Space::Space(Game *game, RefCountedPtr<Galaxy> galaxy, const SystemPath &path, Space* oldSpace) : m_starSystemCache(oldSpace ? oldSpace->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 = galaxy->GetStarSystem(path); 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)); CityOnPlanet::SetCityModelPatterns(m_starSystem->GetPath()); // XXX set radius in constructor m_rootFrame.reset(new Frame(0, Lang::SYSTEM)); m_rootFrame->SetRadius(FLT_MAX); GenBody(m_game->GetTime(), m_starSystem->GetRootBody().Get(), m_rootFrame.get()); m_rootFrame->UpdateOrbitRails(m_game->GetTime(), m_game->GetTimeStep()); GenSectorCache(galaxy, &path); //DebugDumpFrames(); }
Space::Space(Game *game, RefCountedPtr<Galaxy> galaxy, Space* oldSpace) : m_starSystemCache(oldSpace ? oldSpace->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_background.reset(new Background::Container(Pi::renderer, Pi::rng)); m_rootFrame.reset(new Frame(0, Lang::SYSTEM)); m_rootFrame->SetRadius(FLT_MAX); GenSectorCache(galaxy, &game->GetHyperspaceDest()); }
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); }