From 23cfd29dbb5a837ae04d4522b623ac21836dc396 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 9 Jan 2016 12:28:42 +0100 Subject: [PATCH] - let's save the terrain properties as names so that they survive a change in the definition files. --- src/p_mobj.cpp | 2 +- src/p_saveg.cpp | 4 +++- src/p_terrain.cpp | 24 ++++++++++++++++++++++++ src/p_terrain.h | 2 ++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 8c814738e..3d0d8e072 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -193,7 +193,7 @@ void AActor::Serialize (FArchive &arc) << Damage; if (SaveVersion >= 4530) { - arc << floorterrain; + P_SerializeTerrain(arc, floorterrain); } if (SaveVersion >= 3227) { diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 918eb7a89..db14aeb90 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -52,6 +52,7 @@ #include "farchive.h" #include "p_lnspec.h" #include "p_acs.h" +#include "p_terrain.h" static void CopyPlayer (player_t *dst, player_t *src, const char *name); static void ReadOnePlayer (FArchive &arc, bool skipload); @@ -371,7 +372,8 @@ void P_SerializeWorld (FArchive &arc) << sec->gravity; if (SaveVersion >= 4530) { - arc << sec->terrainnum[0] << sec->terrainnum[1]; + P_SerializeTerrain(arc, sec->terrainnum[0]); + P_SerializeTerrain(arc, sec->terrainnum[1]); } if (SaveVersion >= 4529) { diff --git a/src/p_terrain.cpp b/src/p_terrain.cpp index 006835ea6..af8de5cab 100644 --- a/src/p_terrain.cpp +++ b/src/p_terrain.cpp @@ -46,6 +46,7 @@ #include "s_sound.h" #include "p_local.h" #include "templates.h" +#include "farchive.h" // MACROS ------------------------------------------------------------------ @@ -704,3 +705,26 @@ int P_FindTerrain (FName name) } return -1; } + +void P_SerializeTerrain(FArchive &arc, int &terrainnum) +{ + FName val; + if (arc.IsStoring()) + { + if (terrainnum < 0 || terrainnum >= (int)Terrains.Size()) + { + val = NAME_Null; + } + else + { + val = Terrains[terrainnum].Name; + } + arc << val; + } + else + { + arc << val; + terrainnum = P_FindTerrain(val); + + } +} diff --git a/src/p_terrain.h b/src/p_terrain.h index 85059a945..dab4904b6 100644 --- a/src/p_terrain.h +++ b/src/p_terrain.h @@ -122,6 +122,8 @@ struct FTerrainDef extern TArray Splashes; extern TArray Terrains; +class FArchive; int P_FindTerrain(FName name); +void P_SerializeTerrain(FArchive &arc, int &terrainnum); #endif //__P_TERRAIN_H__