From cf1e6d527552030f07cc3832910dca5881095105 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 20 Sep 2016 11:35:25 +0200 Subject: [PATCH] - converted FBehavior::StaticSerializeModuleStates. - removed some code which is no longer needed. --- src/dobject.h | 6 -- src/doomtype.h | 1 - src/p_acs.cpp | 130 ++++++++++++++------------------ src/p_acs.h | 6 +- src/p_pspr.h | 1 - src/p_saveg.cpp | 2 +- src/p_terrain.h | 2 - src/r_data/renderstyle.cpp | 6 -- src/r_data/renderstyle.h | 4 - src/textures/texturemanager.cpp | 19 ----- 10 files changed, 61 insertions(+), 116 deletions(-) diff --git a/src/dobject.h b/src/dobject.h index 0419e8c59..0f81ae873 100644 --- a/src/dobject.h +++ b/src/dobject.h @@ -414,18 +414,12 @@ public: return GC::ReadBarrier(p) == u; } - template friend inline FArchive &operator<<(FArchive &arc, TObjPtr &o); template friend inline void GC::Mark(TObjPtr &obj); template friend FSerializer &Serialize(FSerializer &arc, const char *key, TObjPtr &value, TObjPtr *); friend class DObject; }; -template inline FArchive &operator<<(FArchive &arc, TObjPtr &o) -{ - return arc << o.p; -} - // Use barrier_cast instead of static_cast when you need to cast // the contents of a TObjPtr to a related type. template inline T barrier_cast(TObjPtr &o) diff --git a/src/doomtype.h b/src/doomtype.h index 34f750313..ccf8ccc3d 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -212,7 +212,6 @@ class PClassInventory; class FTextureID { friend class FTextureManager; - friend FArchive &operator<< (FArchive &arc, FTextureID &tex); friend FTextureID GetHUDIcon(PClassInventory *cls); friend void R_InitSpriteDefs(); diff --git a/src/p_acs.cpp b/src/p_acs.cpp index b49f820f4..c366e4f42 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -1628,64 +1628,72 @@ void FBehavior::UnlockMapVarStrings() const } } -void FBehavior::StaticSerializeModuleStates (FArchive &arc) +void FBehavior::StaticSerializeModuleStates (FSerializer &arc) { - DWORD modnum; + auto modnum = StaticModules.Size(); - modnum = StaticModules.Size(); - arc << modnum; - - if (modnum != StaticModules.Size()) + if (arc.BeginObject("acsmodules")) { - I_Error("Level was saved with a different number of ACS modules. (Have %d, save has %d)", StaticModules.Size(), modnum); - } + arc("count", modnum); - for (modnum = 0; modnum < StaticModules.Size(); ++modnum) - { - FBehavior *module = StaticModules[modnum]; - int ModSize = module->GetDataSize(); + if (modnum != StaticModules.Size()) + { + I_Error("Level was saved with a different number of ACS modules. (Have %d, save has %d)", StaticModules.Size(), modnum); + } - if (arc.IsStoring()) + for (modnum = 0; modnum < StaticModules.Size(); ++modnum) { - arc.WriteString (module->ModuleName); - arc << ModSize; - } - else - { - char *modname = NULL; - arc << modname; - arc << ModSize; - if (stricmp (modname, module->ModuleName) != 0) + if (arc.BeginArray("modules")) { - delete[] modname; - I_Error("Level was saved with a different set or order of ACS modules. (Have %s, save has %s)", module->ModuleName, modname); + FBehavior *module = StaticModules[modnum]; + const char *modname; + int ModSize = module->GetDataSize(); + + if (arc.BeginObject(nullptr)) + { + arc.StringPtr("modname", modname) + ("modsize", ModSize); + + if (arc.isReading()) + { + if (stricmp(modname, module->ModuleName) != 0) + { + I_Error("Level was saved with a different set or order of ACS modules. (Have %s, save has %s)", module->ModuleName, modname); + } + else if (ModSize != module->GetDataSize()) + { + I_Error("ACS module %s has changed from what was saved. (Have %d bytes, save has %d bytes)", module->ModuleName, module->GetDataSize(), ModSize); + } + } + module->SerializeVars(arc); + arc.EndObject(); + } + arc.EndArray(); } - else if (ModSize != module->GetDataSize()) - { - delete[] modname; - I_Error("ACS module %s has changed from what was saved. (Have %d bytes, save has %d bytes)", module->ModuleName, module->GetDataSize(), ModSize); - } - delete[] modname; } - module->SerializeVars (arc); + arc.EndObject(); } } -void FBehavior::SerializeVars (FArchive &arc) +void FBehavior::SerializeVars (FSerializer &arc) { - SerializeVarSet (arc, MapVarStore, NUM_MAPVARS); - for (int i = 0; i < NumArrays; ++i) + if (arc.BeginArray("variables")) { - SerializeVarSet (arc, ArrayStore[i].Elements, ArrayStore[i].ArraySize); + SerializeVarSet(arc, MapVarStore, NUM_MAPVARS); + for (int i = 0; i < NumArrays; ++i) + { + SerializeVarSet(arc, ArrayStore[i].Elements, ArrayStore[i].ArraySize); + } + arc.EndArray(); } } -void FBehavior::SerializeVarSet (FArchive &arc, SDWORD *vars, int max) +void FBehavior::SerializeVarSet (FSerializer &arc, SDWORD *vars, int max) { - SDWORD arcval; + SDWORD count; SDWORD first, last; - if (arc.IsStoring ()) + if (arc.isWriting ()) { // Find first non-zero variable for (first = 0; first < max; ++first) @@ -1707,52 +1715,28 @@ void FBehavior::SerializeVarSet (FArchive &arc, SDWORD *vars, int max) if (last < first) { // no non-zero variables - arcval = 0; - arc << arcval; + count = 0; + arc("count", count); return; } - arcval = last - first + 1; - arc << arcval; - arcval = first; - arc << arcval; - - while (first <= last) - { - arc << vars[first]; - ++first; - } + count = last - first + 1; + arc("count", count); + arc("first", first); + arc.Array("values", &vars[first], count); } else { - SDWORD truelast; - memset (vars, 0, max*sizeof(*vars)); + arc("count", count); - arc << last; - if (last == 0) + if (count == 0) { return; } - arc << first; - last += first; - truelast = last; - - if (last > max) - { - last = max; - } - - while (first < last) - { - arc << vars[first]; - ++first; - } - while (first < truelast) - { - arc << arcval; - ++first; - } + arc("first", first); + if (first + count > max) count = max - first; + arc.Array("values", &vars[first], count); } } diff --git a/src/p_acs.h b/src/p_acs.h index b31996788..512780f8c 100644 --- a/src/p_acs.h +++ b/src/p_acs.h @@ -324,7 +324,7 @@ public: static void StaticUnloadModules (); static bool StaticCheckAllGood (); static FBehavior *StaticGetModule (int lib); - static void StaticSerializeModuleStates (FArchive &arc); + static void StaticSerializeModuleStates (FSerializer &arc); static void StaticMarkLevelVarStrings(); static void StaticLockLevelVarStrings(); static void StaticUnlockLevelVarStrings(); @@ -368,8 +368,8 @@ private: void UnescapeStringTable(BYTE *chunkstart, BYTE *datastart, bool haspadding); int FindStringInChunk (DWORD *chunk, const char *varname) const; - void SerializeVars (FArchive &arc); - void SerializeVarSet (FArchive &arc, SDWORD *vars, int max); + void SerializeVars (FSerializer &arc); + void SerializeVarSet (FSerializer &arc, SDWORD *vars, int max); void MarkMapVarStrings() const; void LockMapVarStrings() const; diff --git a/src/p_pspr.h b/src/p_pspr.h index 7ef5e86ec..7e5109657 100644 --- a/src/p_pspr.h +++ b/src/p_pspr.h @@ -35,7 +35,6 @@ #define WEAPONTOP (32+6./16) class AInventory; -class FArchive; // // Overlay psprites are scaled shapes diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index c0f39be40..2e927e9fa 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -857,7 +857,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload) // fixme: This needs to ensure it reads from the correct place. Should be one once there's enough of this code converted to JSON AM_SerializeMarkers(arc); - //FBehavior::StaticSerializeModuleStates(arc); + FBehavior::StaticSerializeModuleStates(arc); arc.Array("linedefs", lines, &loadlines[0], numlines); arc.Array("sidedefs", sides, &loadsides[0], numsides); arc.Array("sectors", sectors, &loadsectors[0], numsectors); diff --git a/src/p_terrain.h b/src/p_terrain.h index 77d57da6c..694aa9f14 100644 --- a/src/p_terrain.h +++ b/src/p_terrain.h @@ -122,9 +122,7 @@ struct FTerrainDef extern TArray Splashes; extern TArray Terrains; -class FArchive; int P_FindTerrain(FName name); -void P_SerializeTerrain(FArchive &arc, int &terrainnum); FName P_GetTerrainName(int terrainnum); #endif //__P_TERRAIN_H__ diff --git a/src/r_data/renderstyle.cpp b/src/r_data/renderstyle.cpp index fdd20aa17..f84c941d9 100644 --- a/src/r_data/renderstyle.cpp +++ b/src/r_data/renderstyle.cpp @@ -99,12 +99,6 @@ static struct LegacyInit #endif -FArchive &operator<< (FArchive &arc, FRenderStyle &style) -{ - arc << style.BlendOp << style.SrcAlpha << style.DestAlpha << style.Flags; - return arc; -} - double GetAlpha(int type, double alpha) { switch (type) diff --git a/src/r_data/renderstyle.h b/src/r_data/renderstyle.h index c103610ef..78687cec0 100644 --- a/src/r_data/renderstyle.h +++ b/src/r_data/renderstyle.h @@ -162,8 +162,4 @@ inline FRenderStyle &FRenderStyle::operator= (ERenderStyle legacy) return *this; } -class FArchive; - -FArchive &operator<< (FArchive &arc, FRenderStyle &style); - #endif diff --git a/src/textures/texturemanager.cpp b/src/textures/texturemanager.cpp index 95c976f8c..ba4db5e1d 100644 --- a/src/textures/texturemanager.cpp +++ b/src/textures/texturemanager.cpp @@ -1227,25 +1227,6 @@ int FTextureManager::CountLumpTextures (int lumpnum) } -//========================================================================== -// -// operator<< -// -//========================================================================== - -FArchive &operator<< (FArchive &arc, FTextureID &tex) -{ - if (arc.IsStoring()) - { - TexMan.WriteTexture(arc, tex.texnum); - } - else - { - tex.texnum = TexMan.ReadTexture(arc); - } - return arc; -} - //========================================================================== // // FTextureID::operator+