Skip to content

Commit

Permalink
Game Save|libcommon: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jul 6, 2012
1 parent 7cdb3dd commit 387907b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 118 deletions.
2 changes: 1 addition & 1 deletion doomsday/plugins/common/include/p_saveio.h
Expand Up @@ -59,7 +59,7 @@ const char* SV_SavePath(void);
const char* SV_ClientSavePath(void);
#endif

boolean SV_Recognise(SaveInfo* info);
boolean SV_RecogniseState(SaveInfo* info);

/*
* File management
Expand Down
79 changes: 7 additions & 72 deletions doomsday/plugins/common/src/p_saveg.c
Expand Up @@ -604,7 +604,7 @@ static void SV_SaveInfo_Read(SaveInfo* info)
Reader_Delete(svReader);
}

static boolean recogniseSaveState(SaveInfo* info)
static boolean recogniseState(SaveInfo* info)
{
#if __JHEXEN__
byte* saveBuffer;
Expand Down Expand Up @@ -648,85 +648,20 @@ static boolean recogniseSaveState(SaveInfo* info)
// present sidedefs (ver3 format's sidedefs contain chunks of junk data).
if(info->header.version == 3) return false;
#endif

return true;
}
return false;
}

#if __JDOOM__
static boolean recogniseSaveState_Dm_v19(SaveInfo* info)
{
if(!info) return false;
if(!SV_ExistingFile(Str_Text(SaveInfo_FilePath(info)))) return false;

if(SV_OpenFile_Dm_v19(Str_Text(SaveInfo_FilePath(info))))
{
Reader* svReader = SV_NewReader_Dm_v19();
boolean result = false;

// Check version.
/*char vcheck[VERSIONSIZE];
memset(vcheck, 0, sizeof(vcheck));
Reader_Read(svReader, vcheck, sizeof(vcheck));
if(strncmp(vcheck, "version ", 8))*/
{
SaveInfo_Read_Dm_v19(info, svReader);
result = (SaveInfo_Header(info)->version <= V19_SAVE_VERSION);
}

Reader_Delete(svReader);
svReader = NULL;
SV_CloseFile_Dm_v19();

return result;
}
return false;
}
#endif

#if __JHERETIC__
static boolean recogniseSaveState_Hr_v13(SaveInfo* info)
{
if(!info) return false;
if(!SV_ExistingFile(Str_Text(SaveInfo_FilePath(info)))) return false;

if(SV_OpenFile_Hr_v13(Str_Text(SaveInfo_FilePath(info))))
{
Reader* svReader = SV_NewReader_Hr_v13();
boolean result = false;

// Check version.
/*char vcheck[VERSIONSIZE];
memset(vcheck, 0, sizeof(vcheck));
Reader_Read(svReader, vcheck, sizeof(vcheck));
if(strncmp(vcheck, "version ", 8))*/
{
SaveInfo_Read_Hr_v13(info, svReader);
result = (SaveInfo_Header(info)->version == V13_SAVE_VERSION);
}

Reader_Delete(svReader);
svReader = NULL;
SV_CloseFile_Hr_v13();

return result;
}
return false;
}
#endif

boolean SV_Recognise(SaveInfo* info)
boolean SV_RecogniseState(SaveInfo* info)
{
if(recogniseSaveState(info)) return true;
if(recogniseState(info)) return true;
// Perhaps an original game save?
#if __JDOOM__
if(recogniseSaveState_Dm_v19(info)) return true;
if(SV_RecogniseState_Dm_v19(info)) return true;
#endif
#if __JHERETIC__
if(recogniseSaveState_Hr_v13(info)) return true;
if(SV_RecogniseState_Hr_v13(info)) return true;
#endif
return false;
}
Expand Down Expand Up @@ -5011,9 +4946,9 @@ static int loadGameWorker(SaveInfo* saveInfo)
{
// It might be an original game save?
#if __JDOOM__
return SV_v19_LoadGame(saveInfo);
return SV_LoadState_Dm_v19(saveInfo);
#elif __JHERETIC__
return SV_v13_LoadGame(saveInfo);
return SV_LoadState_Hr_v13(saveInfo);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/saveinfo.c
Expand Up @@ -165,7 +165,7 @@ void SaveInfo_Update(SaveInfo* info)
}

// Is this a recognisable save state?
if(!SV_Recognise(info)) return;
if(!SV_RecogniseState(info)) return;

// Ensure we have a valid name.
if(Str_IsEmpty(&info->name))
Expand Down
12 changes: 3 additions & 9 deletions doomsday/plugins/jdoom/include/p_oldsvg.h
Expand Up @@ -28,19 +28,13 @@
# error "Using jDoom headers without __JDOOM__"
#endif

#include "p_saveio.h"
#include "saveinfo.h"

#define V19_SAVE_VERSION 500 ///< Version number associated with a recognised doom.exe game save state.

boolean SV_OpenFile_Dm_v19(const char* filePath);
void SV_CloseFile_Dm_v19(void);
Reader* SV_NewReader_Dm_v19(void);

void SaveInfo_Read_Dm_v19(SaveInfo* info, Reader* reader);
boolean SV_RecogniseState_Dm_v19(SaveInfo* info);

/**
* @return @c 0 on success else error code.
*/
int SV_v19_LoadGame(SaveInfo* saveInfo);
int SV_LoadState_Dm_v19(SaveInfo* saveInfo);

#endif /// LIBDOOM_OLD_SAVESTATE
64 changes: 51 additions & 13 deletions doomsday/plugins/jdoom/src/p_oldsvg.c
Expand Up @@ -34,23 +34,30 @@
#include "p_plat.h"
#include "am_map.h"

#define PADSAVEP() savePtr += (4 - ((savePtr - saveBuffer) & 3)) & 3
#define PADSAVEP() savePtr += (4 - ((savePtr - saveBuffer) & 3)) & 3

// All the versions of DOOM have different savegame IDs, but 500 will be the
// savegame base from now on.
#define V19_SAVESTRINGSIZE (24)
#define VERSIONSIZE (16)
#define V19_SAVE_VERSION 500 ///< Version number associated with a recognised doom.exe game save state.
#define V19_SAVESTRINGSIZE 24
#define VERSIONSIZE 16

#define FF_FULLBRIGHT (0x8000) // Used to be a flag in thing->frame.
#define FF_FRAMEMASK (0x7fff)
#define FF_FULLBRIGHT 0x8000 ///< Used to be a flag in thing->frame.
#define FF_FRAMEMASK 0x7fff

#define SIZEOF_V19_THINKER_T 12
#define V19_THINKER_T_FUNC_OFFSET 8
#define SIZEOF_V19_THINKER_T 12
#define V19_THINKER_T_FUNC_OFFSET 8

static byte* savePtr;
static byte* saveBuffer;
static Reader* svReader;

static boolean SV_OpenFile_Dm_v19(const char* filePath);
static void SV_CloseFile_Dm_v19(void);
static Reader* SV_NewReader_Dm_v19(void);

static void SaveInfo_Read_Dm_v19(SaveInfo* info, Reader* reader);

static char sri8(Reader* r)
{
if(!r) return 0;
Expand Down Expand Up @@ -825,7 +832,7 @@ void P_v19_UnArchiveSpecials(void)
}
}

int SV_v19_LoadGame(SaveInfo* info)
int SV_LoadState_Dm_v19(SaveInfo* info)
{
const saveheader_t* hdr;
if(!info) return 1;
Expand Down Expand Up @@ -863,7 +870,7 @@ int SV_v19_LoadGame(SaveInfo* info)
svReader = NULL;
SV_CloseFile_Dm_v19();

Con_Error("SV_v19_LoadGame: Bad savegame (consistency test failed!)\n");
Con_Error("SV_LoadState_Dm_v19: Bad savegame (consistency test failed!)\n");
exit(1); // Unreachable.
}

Expand All @@ -877,7 +884,7 @@ int SV_v19_LoadGame(SaveInfo* info)
return 0; // Success!
}

void SaveInfo_Read_Dm_v19(SaveInfo* info, Reader* reader)
static void SaveInfo_Read_Dm_v19(SaveInfo* info, Reader* reader)
{
saveheader_t* hdr = &info->header;
char nameBuffer[V19_SAVESTRINGSIZE];
Expand All @@ -890,6 +897,7 @@ void SaveInfo_Read_Dm_v19(SaveInfo* info, Reader* reader)
Str_Set(&info->name, nameBuffer);

Reader_Read(reader, vcheck, VERSIONSIZE);
//assert(!strncmp(vcheck, "version ", 8)); // Ensure save state format has been recognised by now.
hdr->version = atoi(&vcheck[8]);

hdr->skill = Reader_ReadByte(reader);
Expand Down Expand Up @@ -919,7 +927,7 @@ void SaveInfo_Read_Dm_v19(SaveInfo* info, Reader* reader)
info->gameId = 0; // None.
}

boolean SV_OpenFile_Dm_v19(const char* filePath)
static boolean SV_OpenFile_Dm_v19(const char* filePath)
{
boolean fileOpened;
#if _DEBUG
Expand All @@ -932,15 +940,45 @@ boolean SV_OpenFile_Dm_v19(const char* filePath)
return true;
}

void SV_CloseFile_Dm_v19(void)
static void SV_CloseFile_Dm_v19(void)
{
if(!saveBuffer) return;
Z_Free(saveBuffer);
saveBuffer = savePtr = NULL;
}

Reader* SV_NewReader_Dm_v19(void)
static Reader* SV_NewReader_Dm_v19(void)
{
if(!saveBuffer) return NULL;
return Reader_NewWithCallbacks(sri8, sri16, sri32, NULL, srd);
}

boolean SV_RecogniseState_Dm_v19(SaveInfo* info)
{
if(!info) return false;
if(!SV_ExistingFile(Str_Text(SaveInfo_FilePath(info)))) return false;

if(SV_OpenFile_Dm_v19(Str_Text(SaveInfo_FilePath(info))))
{
Reader* svReader = SV_NewReader_Dm_v19();
boolean result = false;

/// @todo Use the 'version' string as the "magic" identifier.
/*char vcheck[VERSIONSIZE];
memset(vcheck, 0, sizeof(vcheck));
Reader_Read(svReader, vcheck, sizeof(vcheck));
if(strncmp(vcheck, "version ", 8))*/
{
SaveInfo_Read_Dm_v19(info, svReader);
result = (SaveInfo_Header(info)->version <= V19_SAVE_VERSION);
}

Reader_Delete(svReader);
svReader = NULL;
SV_CloseFile_Dm_v19();

return result;
}
return false;
}
12 changes: 3 additions & 9 deletions doomsday/plugins/jheretic/include/p_oldsvg.h
Expand Up @@ -28,19 +28,13 @@
# error "Using jHeretic headers without __JHERETIC__"
#endif

#include "p_saveio.h"
#include "saveinfo.h"

#define V13_SAVE_VERSION 130 ///< Version number associated with a recognised heretic.exe game save state.

boolean SV_OpenFile_Hr_v13(const char* filePath);
void SV_CloseFile_Hr_v13(void);
Reader* SV_NewReader_Hr_v13(void);

void SaveInfo_Read_Hr_v13(SaveInfo* info, Reader* reader);
boolean SV_RecogniseState_Hr_v13(SaveInfo* info);

/**
* @return @c 0 on success else error code.
*/
int SV_v13_LoadGame(SaveInfo* saveInfo);
int SV_LoadState_Hr_v13(SaveInfo* saveInfo);

#endif /// LIBHERETIC_OLD_SAVESTATE

0 comments on commit 387907b

Please sign in to comment.