Skip to content

Commit

Permalink
Game Save: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 24, 2012
1 parent c3bd396 commit bc6da41
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 71 deletions.
45 changes: 16 additions & 29 deletions doomsday/plugins/common/include/p_saveg.h
Expand Up @@ -102,9 +102,21 @@ boolean SV_HxHaveMapSaveForSlot(int slot, uint map);
saveinfo_t* SV_SaveInfoForSlot(int slot);

boolean SV_ComposeSavePathForSlot(int slot, ddstring_t* path);

#if __JHEXEN__
boolean SV_ComposeSavePathForMapSlot(uint map, int slot, ddstring_t* path);
#else
#endif

#if !__JHEXEN__
/**
* Compose the (possibly relative) path to the game-save associated
* with @a gameId. If the game-save path is unreachable then @a path
* will be made empty.
*
* @param gameId Unique game identifier.
* @param path String buffer to populate with the game save path.
* @return @c true if @a path was set.
*/
boolean SV_ComposeSavePathForClientGameId(uint gameId, ddstring_t* path);
#endif

Expand All @@ -125,7 +137,9 @@ boolean SV_LoadGame(int slot);
#if __JHEXEN__
void SV_HxInitBaseSlot(void);
void SV_HxMapTeleport(uint map, uint position);
#else
#endif

#if !__JHEXEN__
/**
* Saves a snapshot of the world, a still image.
* No data of movement is included (server sends it).
Expand All @@ -135,23 +149,6 @@ void SV_SaveGameClient(uint gameId);
void SV_LoadGameClient(uint gameId);
#endif

typedef enum gamearchivesegment_e {
ASEG_MAP_HEADER = 102, // Hexen only
ASEG_WORLD,
ASEG_POLYOBJS, // Hexen only
ASEG_MOBJS, // Hexen < ver 4 only
ASEG_THINKERS,
ASEG_SCRIPTS, // Hexen only
ASEG_PLAYERS,
ASEG_SOUNDS, // Hexen only
ASEG_MISC, // Hexen only
ASEG_END,
ASEG_MATERIAL_ARCHIVE,
ASEG_MAP_HEADER2, // Hexen only
ASEG_PLAYER_HEADER,
ASEG_GLOBALSCRIPTDATA // Hexen only
} gamearchivesegment_t;

/**
* Original indices must remain unchanged!
* Added new think classes to the end.
Expand Down Expand Up @@ -201,16 +198,6 @@ mobj_t* SV_GetArchiveThing(int thingid, void* address);
MaterialArchive* SV_MaterialArchive(void);
material_t* SV_GetArchiveMaterial(materialarchive_serialid_t serialId, int group);

/**
* Exit with a fatal error if the value at the current location in the
* game-save file does not match that associated with the segment type.
*
* @param segType Segment type identifier to check alignment of.
*/
void SV_AssertSegment(int segType);

void SV_BeginSegment(int segType);

/**
* Update mobj flag values from those used in legacy game-save formats
* to their current values.
Expand Down
55 changes: 41 additions & 14 deletions doomsday/plugins/common/include/p_saveio.h
Expand Up @@ -27,24 +27,41 @@
#include "lzss.h"
#include "p_savedef.h"

typedef enum gamearchivesegment_e {
ASEG_MAP_HEADER = 102, // Hexen only
ASEG_WORLD,
ASEG_POLYOBJS, // Hexen only
ASEG_MOBJS, // Hexen < ver 4 only
ASEG_THINKERS,
ASEG_SCRIPTS, // Hexen only
ASEG_PLAYERS,
ASEG_SOUNDS, // Hexen only
ASEG_MISC, // Hexen only
ASEG_END,
ASEG_MATERIAL_ARCHIVE,
ASEG_MAP_HEADER2, // Hexen only
ASEG_PLAYER_HEADER,
ASEG_GLOBALSCRIPTDATA // Hexen only
} gamearchivesegment_t;

typedef struct saveheader_s {
int magic;
int version;
gamemode_t gameMode;
char name[SAVESTRINGSIZE];
byte skill;
byte episode;
byte map;
byte deathmatch;
byte noMonsters;
int magic;
int version;
gamemode_t gameMode;
char name[SAVESTRINGSIZE];
byte skill;
byte episode;
byte map;
byte deathmatch;
byte noMonsters;
#if __JHEXEN__
byte randomClasses;
byte randomClasses;
#else
byte respawnMonsters;
int mapTime;
byte players[MAXPLAYERS];
byte respawnMonsters;
int mapTime;
byte players[MAXPLAYERS];
#endif
unsigned int gameId;
unsigned int gameId;
} saveheader_t;

typedef struct saveinfo_s {
Expand Down Expand Up @@ -83,6 +100,16 @@ void SV_CopyFile(const ddstring_t* srcPath, const ddstring_t* destPath);
saveptr_t* SV_HxSavePtr(void);
#endif // __JHEXEN__

/**
* Exit with a fatal error if the value at the current location in the
* game-save file does not match that associated with the segment type.
*
* @param segType Segment type identifier to check alignment of.
*/
void SV_AssertSegment(int segType);

void SV_BeginSegment(int segType);

/**
* Seek forward @a offset bytes in the save file.
*/
Expand Down
28 changes: 0 additions & 28 deletions doomsday/plugins/common/src/p_saveg.c
Expand Up @@ -738,15 +738,6 @@ boolean SV_ComposeSavePathForMapSlot(uint map, int slot, ddstring_t* path)
return !Str_IsEmpty(path);
}
#else
/**
* Compose the (possibly relative) path to the game-save associated
* with @a gameId. If the game-save path is unreachable then @a path
* will be made empty.
*
* @param gameId Unique game identifier.
* @param path String buffer to populate with the game save path.
* @return @c true if @a path was set.
*/
static boolean composeClientGameSavePathForGameId(uint gameId, ddstring_t* path)
{
assert(inited && NULL != path);
Expand Down Expand Up @@ -828,25 +819,6 @@ void SV_HxInitBaseSlot(void)
}
#endif

void SV_AssertSegment(int segType)
{
errorIfNotInited("SV_AssertSegment");
#if __JHEXEN__
if(SV_ReadLong() != segType)
{
Con_Error("Corrupt save game: Segment [%d] failed alignment check", segType);
}
#endif
}

void SV_BeginSegment(int segType)
{
errorIfNotInited("SV_BeginSegment");
#if __JHEXEN__
SV_WriteLong(segType);
#endif
}

/**
* @return Ptr to the thinkerinfo for the given thinker.
*/
Expand Down
19 changes: 19 additions & 0 deletions doomsday/plugins/common/src/p_saveio.c
Expand Up @@ -211,6 +211,25 @@ saveptr_t* SV_HxSavePtr(void)
}
#endif

void SV_AssertSegment(int segType)
{
errorIfNotInited("SV_AssertSegment");
#if __JHEXEN__
if(SV_ReadLong() != segType)
{
Con_Error("Corrupt save game: Segment [%d] failed alignment check", segType);
}
#endif
}

void SV_BeginSegment(int segType)
{
errorIfNotInited("SV_BeginSegment");
#if __JHEXEN__
SV_WriteLong(segType);
#endif
}

void SV_Seek(uint offset)
{
errorIfNotInited("SV_SetPos");
Expand Down

0 comments on commit bc6da41

Please sign in to comment.