Exemple #1
0
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();
}
Exemple #2
0
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());
}