Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 26, 2012
1 parent 3354de6 commit 765a1a9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 49 deletions.
71 changes: 35 additions & 36 deletions doomsday/plugins/common/src/p_saveg.c
Expand Up @@ -4836,7 +4836,24 @@ void SV_Shutdown(void)
inited = false;
}

static boolean SV_LoadGame2(SaveInfo* saveInfo)
static boolean openGameSaveFile(const char* fileName, boolean write)
{
#if __JHEXEN__
if(!write)
{
boolean result = M_ReadFile(fileName, (char**)&saveBuffer) > 0;
// Set the save pointer.
SV_HxSavePtr()->b = saveBuffer;
return result;
}
else
#endif
SV_OpenFile(fileName, write? "wp" : "rp");
if(!SV_File()) return false;
return true;
}

static int loadGameWorker(SaveInfo* saveInfo)
{
int i;
char buf[80];
Expand All @@ -4845,6 +4862,18 @@ static boolean SV_LoadGame2(SaveInfo* saveInfo)
int k;
#endif

playerHeaderOK = false; // Uninitialized.

if(!openGameSaveFile(Str_Text(SaveInfo_FilePath(saveInfo)), false))
{
// It might be an original game save?
#if __JDOOM__
return SV_v19_LoadGame(saveInfo);
#elif __JHERETIC__
return SV_v13_LoadGame(saveInfo);
#endif
}

// Read the header again.
/// @todo Seek past the header straight to the game state.
{
Expand Down Expand Up @@ -5021,24 +5050,7 @@ static boolean SV_LoadGame2(SaveInfo* saveInfo)
R_UpdateConsoleView(i);
}

return true; // Success!
}

static boolean openGameSaveFile(const char* fileName, boolean write)
{
#if __JHEXEN__
if(!write)
{
boolean result = M_ReadFile(fileName, (char**)&saveBuffer) > 0;
// Set the save pointer.
SV_HxSavePtr()->b = saveBuffer;
return result;
}
else
#endif
SV_OpenFile(fileName, write? "wp" : "rp");
if(!SV_File()) return false;
return true;
return 0; // Success!
}

boolean SV_LoadGame(int slot)
Expand All @@ -5048,8 +5060,8 @@ boolean SV_LoadGame(int slot)
#else
const int logicalSlot = slot;
#endif
boolean loadError = true;
SaveInfo* saveInfo;
int loadError;

errorIfNotInited("SV_LoadGame");

Expand All @@ -5058,7 +5070,8 @@ boolean SV_LoadGame(int slot)
VERBOSE( Con_Message("Attempting load of game-save slot #%i...\n", slot) )

#if __JHEXEN__
// Copy all needed save files to the base slot
// Copy all needed save files to the base slot.
/// @todo Why do this BEFORE loading??
if(slot != BASE_SLOT)
{
SV_ClearSlot(BASE_SLOT);
Expand All @@ -5067,21 +5080,7 @@ boolean SV_LoadGame(int slot)
#endif

saveInfo = SV_SaveInfoForSlot(logicalSlot);

playerHeaderOK = false; // Uninitialized.
if(openGameSaveFile(Str_Text(SaveInfo_FilePath(saveInfo)), false))
{
loadError = !SV_LoadGame2(saveInfo);
}
else
{
// It might be an original game save?
#if __JDOOM__
loadError = !SV_v19_LoadGame(saveInfo);
#elif __JHERETIC__
loadError = !SV_v13_LoadGame(saveInfo);
#endif
}
loadError = loadGameWorker(saveInfo);

if(!loadError)
{
Expand Down
6 changes: 5 additions & 1 deletion doomsday/plugins/jdoom/include/p_oldsvg.h
Expand Up @@ -31,6 +31,10 @@
#include "p_saveio.h"

boolean SV_v19_Recognise(SaveInfo* saveInfo);
boolean SV_v19_LoadGame(SaveInfo* saveInfo);

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

#endif /// LIBDOOM_OLD_SAVESTATE
13 changes: 6 additions & 7 deletions doomsday/plugins/jdoom/src/p_oldsvg.c
Expand Up @@ -822,18 +822,18 @@ void P_v19_UnArchiveSpecials(void)
}
}

boolean SV_v19_LoadGame(SaveInfo* info)
int SV_v19_LoadGame(SaveInfo* info)
{
const char* savename;
int i, a, b, c;
size_t length;
char vcheck[VERSIONSIZE];

if(!info) return false;
if(!info) return 1;

savename = Str_Text(SaveInfo_FilePath(info));
if(!(length = M_ReadFile(savename, (char**)&saveBuffer)))
return false;
return 1;

// Skip the description field.
savePtr = saveBuffer + V19_SAVESTRINGSIZE;
Expand All @@ -853,7 +853,7 @@ boolean SV_v19_LoadGame(SaveInfo* info)
Z_Free(saveBuffer);
saveBuffer = NULL;
savePtr = NULL;
return false;
return 1;
}

// Just give a warning.
Expand Down Expand Up @@ -883,16 +883,15 @@ boolean SV_v19_LoadGame(SaveInfo* info)
P_v19_UnArchiveSpecials();

if(*savePtr != 0x1d)
Con_Error
("SV_v19_LoadGame: Bad savegame (consistency test failed!)\n");
Con_Error("SV_v19_LoadGame: Bad savegame (consistency test failed!)\n");

Z_Free(saveBuffer);
saveBuffer = NULL;

// Spawn particle generators.
R_SetupMap(DDSMM_AFTER_LOADING, 0);

return true;
return 0; // Success!
}

boolean SV_v19_Recognise(SaveInfo* info)
Expand Down
6 changes: 5 additions & 1 deletion doomsday/plugins/jheretic/include/p_oldsvg.h
Expand Up @@ -31,6 +31,10 @@
#include "p_saveio.h"

boolean SV_v13_Recognise(SaveInfo* saveInfo);
boolean SV_v13_LoadGame(SaveInfo* saveInfo);

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

#endif /// LIBHERETIC_OLD_SAVESTATE
10 changes: 6 additions & 4 deletions doomsday/plugins/jheretic/src/p_oldsvg.c
Expand Up @@ -831,18 +831,18 @@ enum {
}
}

boolean SV_v13_LoadGame(SaveInfo* info)
int SV_v13_LoadGame(SaveInfo* info)
{
const char* savename;
size_t length;
int i, a, b, c;
char vcheck[VERSIONSIZE];

if(!info) return false;
if(!info) return 1;

savename = Str_Text(SaveInfo_FilePath(info));
if(!(length = M_ReadFile(savename, (char**)&savebuffer)))
return false;
return 1;

save_p = savebuffer + V13_SAVESTRINGSIZE;

Expand All @@ -853,8 +853,10 @@ boolean SV_v13_LoadGame(SaveInfo* info)
{
// Bad version!
Con_Message("Savegame ID '%s': incompatible?\n", save_p);
return 1;
}
save_p += VERSIONSIZE;

gameSkill = *save_p++;
gameEpisode = (*save_p++) - 1;
gameMap = (*save_p++) - 1;
Expand Down Expand Up @@ -887,7 +889,7 @@ boolean SV_v13_LoadGame(SaveInfo* info)
// Spawn particle generators.
R_SetupMap(DDSMM_AFTER_LOADING, 0);

return true;
return 0; // Success!
}

boolean SV_v13_Recognise(SaveInfo* info)
Expand Down

0 comments on commit 765a1a9

Please sign in to comment.