示例#1
0
void FRandom::StaticReadRNGState(FSerializer &arc)
{
	FRandom *rng;

	arc("rngseed", rngseed);

	// Call StaticClearRandom in order to ensure that SFMT is initialized
	FRandom::StaticClearRandom ();

	if (arc.BeginArray("rngs"))
	{
		int count = arc.ArraySize();

		for (int i = 0; i < count; i++)
		{
			if (arc.BeginObject(nullptr))
			{
				uint32_t crc;
				arc("crc", crc);

				for (rng = FRandom::RNGList; rng != NULL; rng = rng->Next)
				{
					if (rng->NameCRC == crc)
					{
						arc("index", rng->idx)
							.Array("u", rng->sfmt.u, SFMT::N32);
						break;
					}
				}
				arc.EndObject();
			}
		}
		arc.EndArray();
	}
}
示例#2
0
void FRandom::StaticWriteRNGState (FSerializer &arc)
{
	FRandom *rng;

	arc("rngseed", rngseed);

	if (arc.BeginArray("rngs"))
	{
		for (rng = FRandom::RNGList; rng != NULL; rng = rng->Next)
		{
			// Only write those RNGs that have names
			if (rng->NameCRC != 0)
			{
				if (arc.BeginObject(nullptr))
				{
					arc("crc", rng->NameCRC)
						("index", rng->idx)
						.Array("u", rng->sfmt.u, SFMT::N32)
						.EndObject();
				}
			}
		}
		arc.EndArray();
	}
}
示例#3
0
void G_ReadVisited(FSerializer &arc)
{
	if (arc.BeginArray("visited"))
	{
		for (int s = arc.ArraySize(); s > 0; s--)
		{
			FString str;
			arc(nullptr, str);
			auto i = FindLevelInfo(str);
			if (i != nullptr) i->flags |= LEVEL_VISITED;
		}
		arc.EndArray();
	}

	arc.Array("randomclasses", SinglePlayerClass, MAXPLAYERS);

	if (arc.BeginObject("playerclasses"))
	{
		for (int i = 0; i < MAXPLAYERS; ++i)
		{
			FString key;
			key.Format("%d", i);
			arc(key, players[i].cls);
		}
		arc.EndObject();
	}
}
示例#4
0
void G_WriteVisited(FSerializer &arc)
{
	if (arc.BeginArray("visited"))
	{
		// Write out which levels have been visited
		for (auto & wi : wadlevelinfos)
		{
			if (wi.flags & LEVEL_VISITED)
			{
				arc.AddString(nullptr, wi.MapName);
			}
		}
		arc.EndArray();
	}

	// Store player classes to be used when spawning a random class
	if (multiplayer)
	{
		arc.Array("randomclasses", SinglePlayerClass, MAXPLAYERS);
	}

	if (arc.BeginObject("playerclasses"))
	{
		for (int i = 0; i < MAXPLAYERS; ++i)
		{
			if (playeringame[i])
			{
				FString key;
				key.Format("%d", i);
				arc(key, players[i].cls);
			}
		}
		arc.EndObject();
	}
}
示例#5
0
void FRemapTable::StaticSerializeTranslations(FSerializer &arc)
{
	if (arc.BeginArray("translations"))
	{
		// Does this level have custom translations?
		FRemapTable *trans;
		int w;
		if (arc.isWriting())
		{
			for (unsigned int i = 0; i < translationtables[TRANSLATION_LevelScripted].Size(); ++i)
			{
				trans = translationtables[TRANSLATION_LevelScripted][i];
				if (trans != NULL && !trans->IsIdentity())
				{
					if (arc.BeginObject(nullptr))
					{
						arc("index", i);
						trans->Serialize(arc);
						arc.EndObject();
					}
				}
			}
		}
		else
		{
			while (arc.BeginObject(nullptr))
			{
				arc("index", w);
				trans = translationtables[TRANSLATION_LevelScripted].GetVal(w);
				if (trans == NULL)
				{
					trans = new FRemapTable;
					translationtables[TRANSLATION_LevelScripted].SetVal(w, trans);
				}
				trans->Serialize(arc);
				arc.EndObject();
			}
		}
		arc.EndArray();
	}
}
示例#6
0
void P_SerializePlayers(FSerializer &arc, bool skipload)
{
	int numPlayers, numPlayersNow;
	int i;

	// Count the number of players present right now.
	for (numPlayersNow = 0, i = 0; i < MAXPLAYERS; ++i)
	{
		if (playeringame[i])
		{
			++numPlayersNow;
		}
	}

	if (arc.isWriting())
	{
		// Record the number of players in this save.
		arc("numplayers", numPlayersNow);
		if (arc.BeginArray("players"))
		{
			// Record each player's name, followed by their data.
			for (i = 0; i < MAXPLAYERS; ++i)
			{
				if (playeringame[i])
				{
					if (arc.BeginObject(nullptr))
					{
						const char *n = players[i].userinfo.GetName();
						arc.StringPtr("playername", n);
						players[i].Serialize(arc);
						arc.EndObject();
					}
				}
			}
			arc.EndArray();
		}
	}
	else
	{
		arc("numplayers", numPlayers);

		if (arc.BeginArray("players"))
		{
			// If there is only one player in the game, they go to the
			// first player present, no matter what their name.
			if (numPlayers == 1)
			{
				ReadOnePlayer(arc, skipload);
			}
			else
			{
				ReadMultiplePlayers(arc, numPlayers, numPlayersNow, skipload);
			}
			arc.EndArray();
		}
		if (!skipload && numPlayersNow > numPlayers)
		{
			SpawnExtraPlayers();
		}
		// Redo pitch limits, since the spawned player has them at 0.
		players[consoleplayer].SendPitchLimits();
	}
}