// XXX mostly a copy of CreateViews void Game::LoadViews(Serializer::Reader &rd) { Pi::SetView(0); // XXX views expect Pi::game and Pi::player to exist Pi::game = this; Pi::player = m_player.Get(); Serializer::Reader section = rd.RdSection("ShipCpanel"); Pi::cpan = new ShipCpanel(section, Pi::renderer); section = rd.RdSection("SectorView"); Pi::sectorView = new SectorView(section); section = rd.RdSection("WorldView"); Pi::worldView = new WorldView(section); Pi::galacticView = new GalacticView(); Pi::systemView = new SystemView(); Pi::systemInfoView = new SystemInfoView(); Pi::spaceStationView = new SpaceStationView(); Pi::infoView = new InfoView(); #if WITH_OBJECTVIEWER Pi::objectViewerView = new ObjectViewerView(); Pi::objectViewerView->SetRenderer(Pi::renderer); #endif Pi::galacticView->SetRenderer(Pi::renderer); Pi::infoView->SetRenderer(Pi::renderer); Pi::sectorView->SetRenderer(Pi::renderer); Pi::systemInfoView->SetRenderer(Pi::renderer); Pi::systemView->SetRenderer(Pi::renderer); Pi::worldView->SetRenderer(Pi::renderer); }
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 Pi::Unserialize(Serializer::Reader &rd) { Serializer::Reader section; SetTimeAccel(0); requestedTimeAccelIdx = 0; Space::Clear(); if (Pi::player) { Pi::player->MarkDead(); Space::bodies.remove(Pi::player); delete Pi::player; Pi::player = 0; } section = rd.RdSection("PiMisc"); gameTime = section.Double(); selectedSystem = StarSystem::Unserialize(section); currentSystem = StarSystem::Unserialize(section); section = rd.RdSection("Space"); Space::Unserialize(section); section = rd.RdSection("Polit"); Polit::Unserialize(section); section = rd.RdSection("SectorView"); sectorView->Load(section); section = rd.RdSection("WorldView"); worldView->Load(section); section = rd.RdSection("LuaModules"); PiLuaModules::Unserialize(section); }
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, 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); }
Game::Game(Serializer::Reader &rd) : m_timeAccel(TIMEACCEL_PAUSED), m_requestedTimeAccel(TIMEACCEL_PAUSED), m_forceTimeAccel(false) { // signature check for (Uint32 i = 0; i < strlen(s_saveStart)+1; i++) if (rd.Byte() != s_saveStart[i]) throw SavedGameCorruptException(); // version check rd.SetStreamVersion(rd.Int32()); Output("savefile version: %d\n", rd.StreamVersion()); if (rd.StreamVersion() != s_saveVersion) { Output("can't load savefile, expected version: %d\n", s_saveVersion); throw SavedGameWrongVersionException(); } // XXX This must be done after loading sectors once we can change them in game Pi::FlushCaches(); Serializer::Reader section; // game state section = rd.RdSection("Game"); m_time = section.Double(); m_state = State(section.Int32()); m_wantHyperspace = section.Bool(); m_hyperspaceProgress = section.Double(); m_hyperspaceDuration = section.Double(); m_hyperspaceEndTime = section.Double(); // space, all the bodies and things section = rd.RdSection("Space"); m_space.reset(new Space(this, section, m_time)); m_player.reset(static_cast<Player*>(m_space->GetBodyByIndex(section.Int32()))); // space transition state section = rd.RdSection("HyperspaceClouds"); // hyperspace clouds being brought over from the previous system Uint32 nclouds = section.Int32(); for (Uint32 i = 0; i < nclouds; i++) m_hyperspaceClouds.push_back(static_cast<HyperspaceCloud*>(Body::Unserialize(section, 0))); // system political stuff section = rd.RdSection("Polit"); Polit::Unserialize(section); // views LoadViews(rd); // lua section = rd.RdSection("LuaModules"); Pi::luaSerializer->Unserialize(section); // signature check for (Uint32 i = 0; i < strlen(s_saveEnd)+1; i++) if (rd.Byte() != s_saveEnd[i]) throw SavedGameCorruptException(); }
Game::Game(Serializer::Reader &rd) : m_timeAccel(TIMEACCEL_PAUSED), m_requestedTimeAccel(TIMEACCEL_PAUSED), m_forceTimeAccel(false) { // signature check for (Uint32 i = 0; i < strlen(s_saveStart)+1; i++) if (rd.Byte() != s_saveStart[i]) throw SavedGameCorruptException(); // version check rd.SetStreamVersion(rd.Int32()); Output("savefile version: %d\n", rd.StreamVersion()); if (rd.StreamVersion() != s_saveVersion) { Output("can't load savefile, expected version: %d\n", s_saveVersion); throw SavedGameWrongVersionException(); } // XXX This must be done after loading sectors once we can change them in game Pi::FlushCaches(); Serializer::Reader section; // Preparing the Lua stuff LuaRef::InitLoad(); Pi::luaSerializer->InitTableRefs(); // galaxy generator section = rd.RdSection("GalaxyGen"); std::string genName = section.String(); GalaxyGenerator::Version genVersion = section.Int32(); if (genName != Pi::GetGalaxy()->GetGeneratorName() || genVersion != Pi::GetGalaxy()->GetGeneratorVersion()) { if (!Pi::CreateGalaxy(genName, genVersion)) { Output("can't load savefile, unsupported galaxy generator %s, version %d\n", genName.c_str(), genVersion); throw SavedGameWrongVersionException(); } } // game state section = rd.RdSection("Game"); m_time = section.Double(); m_state = State(section.Int32()); m_wantHyperspace = section.Bool(); m_hyperspaceProgress = section.Double(); m_hyperspaceDuration = section.Double(); m_hyperspaceEndTime = section.Double(); // space, all the bodies and things section = rd.RdSection("Space"); m_space.reset(new Space(this, section, m_time)); m_player.reset(static_cast<Player*>(m_space->GetBodyByIndex(section.Int32()))); assert(!m_player->IsDead()); // Pioneer does not support necromancy // space transition state section = rd.RdSection("HyperspaceClouds"); // hyperspace clouds being brought over from the previous system Uint32 nclouds = section.Int32(); for (Uint32 i = 0; i < nclouds; i++) m_hyperspaceClouds.push_back(static_cast<HyperspaceCloud*>(Body::Unserialize(section, 0))); // system political stuff section = rd.RdSection("Polit"); Polit::Unserialize(section); // views LoadViews(rd); // lua section = rd.RdSection("LuaModules"); Pi::luaSerializer->Unserialize(section); Pi::luaSerializer->UninitTableRefs(); LuaRef::UninitLoad(); // signature check for (Uint32 i = 0; i < strlen(s_saveEnd)+1; i++) if (rd.Byte() != s_saveEnd[i]) throw SavedGameCorruptException(); EmitPauseState(IsPaused()); }