Space::Space(Game *game, Serializer::Reader &rd) : m_game(game) , m_frameIndexValid(false) , m_bodyIndexValid(false) , m_sbodyIndexValid(false) , m_background(Pi::renderer) , m_bodyNearFinder(this) #ifndef NDEBUG , m_processingFinalizationQueue(false) #endif { m_starSystem = StarSystem::Unserialize(rd); m_background.Refresh(m_starSystem->GetSeed()); RebuildSystemBodyIndex(); Serializer::Reader section = rd.RdSection("Frames"); m_rootFrame.Reset(Frame::Unserialize(section, this, 0)); RebuildFrameIndex(); Uint32 nbodies = rd.Int32(); for (Uint32 i = 0; i < nbodies; i++) m_bodies.push_back(Body::Unserialize(rd, this)); RebuildBodyIndex(); Frame::PostUnserializeFixup(m_rootFrame.Get(), this); for (BodyIterator i = m_bodies.begin(); i != m_bodies.end(); ++i) (*i)->PostLoadFixup(this); }
Space::Space(Game *game, Serializer::Reader &rd, double at_time) : m_game(game) , m_frameIndexValid(false) , m_bodyIndexValid(false) , m_sbodyIndexValid(false) , m_bodyNearFinder(this) #ifndef NDEBUG , m_processingFinalizationQueue(false) #endif { m_starSystem = StarSystem::Unserialize(rd); const SystemPath &path = m_starSystem->GetPath(); RebuildSystemBodyIndex(); Serializer::Reader section = rd.RdSection("Frames"); m_rootFrame.reset(Frame::Unserialize(section, this, 0, at_time)); RebuildFrameIndex(); Uint32 nbodies = rd.Int32(); for (Uint32 i = 0; i < nbodies; i++) m_bodies.push_back(Body::Unserialize(rd, this)); RebuildBodyIndex(); Frame::PostUnserializeFixup(m_rootFrame.get(), this); for (Body* b : m_bodies) b->PostLoadFixup(this); GenSectorCache(&path); }
void Space::Serialize(Serializer::Writer &wr) { RebuildFrameIndex(); RebuildBodyIndex(); RebuildSystemBodyIndex(); StarSystem::Serialize(wr, m_starSystem.Get()); Serializer::Writer section; Frame::Serialize(section, m_rootFrame.Get(), this); wr.WrSection("Frames", section.GetData()); wr.Int32(m_bodies.size()); for (BodyIterator i = m_bodies.begin(); i != m_bodies.end(); ++i) (*i)->Serialize(wr, this); }
void Space::Serialize(Serializer::Writer &wr) { RebuildFrameIndex(); RebuildBodyIndex(); RebuildSystemBodyIndex(); StarSystem::Serialize(wr, m_starSystem.Get()); Serializer::Writer section; Frame::Serialize(section, m_rootFrame.get(), this); wr.WrSection("Frames", section.GetData()); wr.Int32(m_bodies.size()); for (Body* b : m_bodies) b->Serialize(wr, this); }
Space::Space(Game *game, Serializer::Reader &rd) : m_game(game), m_frameIndexValid(false), m_bodyIndexValid(false), m_sbodyIndexValid(false) { m_starSystem = StarSystem::Unserialize(rd); m_background.Refresh(m_starSystem->m_seed); RebuildSBodyIndex(); Serializer::Reader section = rd.RdSection("Frames"); m_rootFrame.Reset(Frame::Unserialize(section, this, 0)); RebuildFrameIndex(); Uint32 nbodies = rd.Int32(); for (Uint32 i = 0; i < nbodies; i++) m_bodies.push_back(Body::Unserialize(rd, this)); RebuildBodyIndex(); for (BodyIterator i = m_bodies.begin(); i != m_bodies.end(); ++i) (*i)->PostLoadFixup(this); Frame::PostUnserializeFixup(m_rootFrame.Get(), this); }
Space::Space(Game *game, RefCountedPtr<Galaxy> galaxy, const Json::Value &jsonObj, double at_time) : m_starSystemCache(galaxy->NewStarSystemSlaveCache()) , m_game(game) , m_frameIndexValid(false) , m_bodyIndexValid(false) , m_sbodyIndexValid(false) , m_bodyNearFinder(this) #ifndef NDEBUG , m_processingFinalizationQueue(false) #endif { if (!jsonObj.isMember("space")) throw SavedGameCorruptException(); Json::Value spaceObj = jsonObj["space"]; m_starSystem = StarSystem::FromJson(galaxy, spaceObj); const SystemPath &path = m_starSystem->GetPath(); Uint32 _init[5] = { path.systemIndex, Uint32(path.sectorX), Uint32(path.sectorY), Uint32(path.sectorZ), UNIVERSE_SEED }; Random rand(_init, 5); m_background.reset(new Background::Container(Pi::renderer, rand)); RebuildSystemBodyIndex(); CityOnPlanet::SetCityModelPatterns(m_starSystem->GetPath()); m_rootFrame.reset(Frame::FromJson(spaceObj, this, 0, at_time)); RebuildFrameIndex(); if (!spaceObj.isMember("bodies")) throw SavedGameCorruptException(); Json::Value bodyArray = spaceObj["bodies"]; if (!bodyArray.isArray()) throw SavedGameCorruptException(); for (Uint32 i = 0; i < bodyArray.size(); i++) m_bodies.push_back(Body::FromJson(bodyArray[i], this)); RebuildBodyIndex(); Frame::PostUnserializeFixup(m_rootFrame.get(), this); for (Body* b : m_bodies) b->PostLoadFixup(this); GenSectorCache(galaxy, &path); }
Space::Space(Game *game, RefCountedPtr<Galaxy> galaxy, Serializer::Reader &rd, double at_time) : m_starSystemCache(galaxy->NewStarSystemSlaveCache()) , m_game(game) , m_frameIndexValid(false) , m_bodyIndexValid(false) , m_sbodyIndexValid(false) , m_bodyNearFinder(this) #ifndef NDEBUG , m_processingFinalizationQueue(false) #endif { m_starSystem = StarSystem::Unserialize(galaxy, rd); const SystemPath &path = m_starSystem->GetPath(); Uint32 _init[5] = { path.systemIndex, Uint32(path.sectorX), Uint32(path.sectorY), Uint32(path.sectorZ), UNIVERSE_SEED }; Random rand(_init, 5); m_background.reset(new Background::Container(Pi::renderer, rand)); RebuildSystemBodyIndex(); CityOnPlanet::SetCityModelPatterns(m_starSystem->GetPath()); Serializer::Reader section = rd.RdSection("Frames"); m_rootFrame.reset(Frame::Unserialize(section, this, 0, at_time)); RebuildFrameIndex(); Uint32 nbodies = rd.Int32(); for (Uint32 i = 0; i < nbodies; i++) m_bodies.push_back(Body::Unserialize(rd, this)); RebuildBodyIndex(); Frame::PostUnserializeFixup(m_rootFrame.get(), this); for (Body* b : m_bodies) b->PostLoadFixup(this); GenSectorCache(galaxy, &path); }
void Space::ToJson(Json::Value &jsonObj) { PROFILE_SCOPED() RebuildFrameIndex(); RebuildBodyIndex(); RebuildSystemBodyIndex(); Json::Value spaceObj(Json::objectValue); // Create JSON object to contain space data (all the bodies and things). StarSystem::ToJson(spaceObj, m_starSystem.Get()); Frame::ToJson(spaceObj, m_rootFrame.get(), this); Json::Value bodyArray(Json::arrayValue); // Create JSON array to contain body data. for (Body* b : m_bodies) { Json::Value bodyArrayEl(Json::objectValue); // Create JSON object to contain body. b->ToJson(bodyArrayEl, this); bodyArray.append(bodyArrayEl); // Append body object to array. } spaceObj["bodies"] = bodyArray; // Add body array to space object. jsonObj["space"] = spaceObj; // Add space object to supplied object. }