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(); } }
void STAT_Serialize(FSerializer &arc) { FString startlevel; int i = LevelData.Size(); if (arc.BeginObject("statistics")) { if (arc.isReading()) { arc("startlevel", startlevel); StartEpisode = NULL; for (unsigned int j = 0; j < AllEpisodes.Size(); j++) { if (!AllEpisodes[j].mEpisodeMap.CompareNoCase(startlevel)) { StartEpisode = &AllEpisodes[j]; break; } } LevelData.Resize(i); } else { if (StartEpisode != NULL) startlevel = StartEpisode->mEpisodeMap; arc("startlevel", startlevel); } arc("levels", LevelData); arc.EndObject(); } }
void P_WriteACSDefereds (FSerializer &arc) { bool found = false; // only write this stuff if needed for (auto &wi : wadlevelinfos) { if (wi.deferred.Size() > 0) { found = true; break; } } if (found && arc.BeginObject("deferred")) { for (auto &wi : wadlevelinfos) { if (wi.deferred.Size() > 0) { if (wi.deferred.Size() > 0) { arc(wi.MapName, wi.deferred); } } } arc.EndObject(); } }
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(); } }
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(); } }
static void RecurseWriteFields(const PClass *type, FSerializer &ar, const void *addr) { if (type != nullptr) { RecurseWriteFields(type->ParentClass, ar, addr); // Don't write this part if it has no non-transient variables for (unsigned i = 0; i < type->Fields.Size(); ++i) { if (!(type->Fields[i]->Flags & (VARF_Transient|VARF_Meta))) { // Tag this section with the class it came from in case // a more-derived class has variables that shadow a less- // derived class. Whether or not that is a language feature // that will actually be allowed remains to be seen. FString key; key.Format("class:%s", type->TypeName.GetChars()); if (ar.BeginObject(key.GetChars())) { type->VMType->Symbols.WriteFields(ar, addr); ar.EndObject(); } break; } } } }
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(); } }
static void ReadOnePlayer(FSerializer &arc, bool skipload) { int i; const char *name = NULL; bool didIt = false; if (arc.BeginObject(nullptr)) { arc.StringPtr("playername", name); for (i = 0; i < MAXPLAYERS; ++i) { if (playeringame[i]) { if (!didIt) { didIt = true; player_t playerTemp; playerTemp.Serialize(arc); if (!skipload) { // This temp player has undefined pitch limits, so set them to something // that should leave the pitch stored in the savegame intact when // rendering. The real pitch limits will be set by P_SerializePlayers() // via a net command, but that won't be processed in time for a screen // wipe, so we need something here. playerTemp.MaxPitch = playerTemp.MinPitch = playerTemp.mo->Angles.Pitch; CopyPlayer(&players[i], &playerTemp, name); } else { // we need the player actor, so that G_FinishTravel can destroy it later. players[i].mo = playerTemp.mo; } } else { if (players[i].mo != NULL) { players[i].mo->Destroy(); players[i].mo = NULL; } } } } arc.EndObject(); } }
bool PClass::ReadAllFields(FSerializer &ar, void *addr) const { bool readsomething = false; bool foundsomething = false; const char *key; key = ar.GetKey(); if (strcmp(key, "classtype")) { // this does not represent a DObject Printf(TEXTCOLOR_RED "trying to read user variables but got a non-object (first key is '%s')", key); ar.mErrors++; return false; } while ((key = ar.GetKey())) { if (strncmp(key, "class:", 6)) { // We have read all user variable blocks. break; } foundsomething = true; PClass *type = PClass::FindClass(key + 6); if (type != nullptr) { // Only read it if the type is related to this one. if (IsDescendantOf(type)) { if (ar.BeginObject(nullptr)) { readsomething |= type->VMType->Symbols.ReadFields(ar, addr, type->TypeName.GetChars()); ar.EndObject(); } } else { DPrintf(DMSG_ERROR, "Unknown superclass %s of class %s\n", type->TypeName.GetChars(), TypeName.GetChars()); } } else { DPrintf(DMSG_ERROR, "Unknown superclass %s of class %s\n", key+6, TypeName.GetChars()); } } return readsomething || !foundsomething; }
void P_ReadACSDefereds (FSerializer &arc) { FString MapName; P_RemoveDefereds (); if (arc.BeginObject("deferred")) { const char *key; while ((key = arc.GetKey())) { level_info_t *i = FindLevelInfo(key); if (i == NULL) { I_Error("Unknown map '%s' in savegame", key); } arc(nullptr, i->deferred); } arc.EndObject(); } }
static void ReadMultiplePlayers(FSerializer &arc, int numPlayers, int numPlayersNow, bool skipload) { // For two or more players, read each player into a temporary array. int i, j; const char **nametemp = new const char *[numPlayers]; player_t *playertemp = new player_t[numPlayers]; BYTE *tempPlayerUsed = new BYTE[numPlayers]; BYTE playerUsed[MAXPLAYERS]; for (i = 0; i < numPlayers; ++i) { nametemp[i] = NULL; if (arc.BeginObject(nullptr)) { arc.StringPtr("playername", nametemp[i]); playertemp[i].Serialize(arc); arc.EndObject(); } tempPlayerUsed[i] = 0; } for (i = 0; i < MAXPLAYERS; ++i) { playerUsed[i] = playeringame[i] ? 0 : 2; } if (!skipload) { // Now try to match players from the savegame with players present // based on their names. If two players in the savegame have the // same name, then they are assigned to players in the current game // on a first-come, first-served basis. for (i = 0; i < numPlayers; ++i) { for (j = 0; j < MAXPLAYERS; ++j) { if (playerUsed[j] == 0 && stricmp(players[j].userinfo.GetName(), nametemp[i]) == 0) { // Found a match, so copy our temp player to the real player Printf("Found player %d (%s) at %d\n", i, nametemp[i], j); CopyPlayer(&players[j], &playertemp[i], nametemp[i]); playerUsed[j] = 1; tempPlayerUsed[i] = 1; break; } } } // Any players that didn't have matching names are assigned to existing // players on a first-come, first-served basis. for (i = 0; i < numPlayers; ++i) { if (tempPlayerUsed[i] == 0) { for (j = 0; j < MAXPLAYERS; ++j) { if (playerUsed[j] == 0) { Printf("Assigned player %d (%s) to %d (%s)\n", i, nametemp[i], j, players[j].userinfo.GetName()); CopyPlayer(&players[j], &playertemp[i], nametemp[i]); playerUsed[j] = 1; tempPlayerUsed[i] = 1; break; } } } } // Make sure any extra players don't have actors spawned yet. Happens if the players // present now got the same slots as they had in the save, but there are not as many // as there were in the save. for (j = 0; j < MAXPLAYERS; ++j) { if (playerUsed[j] == 0) { if (players[j].mo != NULL) { players[j].mo->Destroy(); players[j].mo = NULL; } } } // Remove any temp players that were not used. Happens if there are fewer players // than there were in the save, and they got shuffled. for (i = 0; i < numPlayers; ++i) { if (tempPlayerUsed[i] == 0) { playertemp[i].mo->Destroy(); playertemp[i].mo = NULL; } } } else { for (i = 0; i < MAXPLAYERS; ++i) { players[i].mo = playertemp[i].mo; } } delete[] tempPlayerUsed; delete[] playertemp; delete[] nametemp; }
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(); } }