Skip to content

Commit

Permalink
libcommon|Refactor: Reworked save game interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 21, 2012
1 parent 20624a3 commit 76a057a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 60 deletions.
10 changes: 0 additions & 10 deletions doomsday/plugins/common/include/p_saveg.h
Expand Up @@ -89,16 +89,6 @@ boolean SV_GetClientGameSavePathForGameId(uint gameId, ddstring_t* path);

#if __JHEXEN__
void SV_HxInitBaseSlot(void);

/**
* Copies the base slot to the reborn slot.
*/
void SV_HxUpdateRebornSlot(void);

void SV_HxClearRebornSlot(void);

int SV_HxGetRebornSlot(void);
boolean SV_HxRebornSlotAvailable(void);
#endif

boolean SV_SaveGame(int slot, const char* name);
Expand Down
21 changes: 10 additions & 11 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -2008,7 +2008,7 @@ void G_DoReborn(int plrNum)
briefDisabled = true;

#if __JHEXEN__
if(SV_HxRebornSlotAvailable())
if(SV_IsGameSaveSlotUsed(REBORN_SLOT))
{
// Use the reborn logic if the slot is available and in use.
G_SetGameAction(GA_SINGLEREBORN);
Expand All @@ -2033,7 +2033,7 @@ void G_DoReborn(int plrNum)
void G_StartNewInit(void)
{
SV_HxInitBaseSlot();
SV_HxClearRebornSlot();
SV_ClearSaveSlot(REBORN_SLOT);

P_ACSInitNewGame();

Expand Down Expand Up @@ -2342,7 +2342,7 @@ void G_DoWorldDone(void)
void G_DoSingleReborn(void)
{
G_SetGameAction(GA_NONE);
SV_LoadGame(SV_HxGetRebornSlot());
SV_LoadGame(REBORN_SLOT);
}
#endif

Expand Down Expand Up @@ -2379,16 +2379,15 @@ boolean G_LoadGame(int slot)
void G_DoLoadGame(void)
{
G_SetGameAction(GA_NONE);
if(SV_LoadGame(gaLoadGameSlot))
{
if(!SV_LoadGame(gaLoadGameSlot)) return;

#if __JHEXEN__
if(!IS_NETGAME)
{
// Copy the base slot to the reborn slot.
SV_HxUpdateRebornSlot();
}
if(IS_NETGAME) return;

// Copy the base slot to the reborn slot.
SV_ClearSaveSlot(REBORN_SLOT);
SV_CopySaveSlot(BASE_SLOT, REBORN_SLOT);
#endif
}
}

boolean G_IsSaveGamePossible(void)
Expand Down
31 changes: 0 additions & 31 deletions doomsday/plugins/common/src/p_saveg.c
Expand Up @@ -402,37 +402,6 @@ void SV_HxInitBaseSlot(void)
{
SV_ClearSaveSlot(BASE_SLOT);
}

void SV_HxUpdateRebornSlot(void)
{
SV_ClearSaveSlot(REBORN_SLOT);
SV_CopySaveSlot(BASE_SLOT, REBORN_SLOT);
}

void SV_HxClearRebornSlot(void)
{
SV_ClearSaveSlot(REBORN_SLOT);
}

int SV_HxGetRebornSlot(void)
{
errorIfNotInited("SV_HxGetRebornSlot");
return (REBORN_SLOT);
}

boolean SV_HxRebornSlotAvailable(void)
{
ddstring_t path;
boolean result = false;
errorIfNotInited("SV_HxRebornSlotAvailable");
Str_InitStd(&path);
if(SV_GetGameSavePathForSlot(REBORN_SLOT, &path))
{
result = SV_ExistingFile(Str_Text(&path));
}
Str_Free(&path);
return result;
}
#endif

#if __JHEXEN__
Expand Down
33 changes: 25 additions & 8 deletions doomsday/plugins/common/src/p_saveio.c
Expand Up @@ -435,14 +435,6 @@ static gamesaveinfo_t* findGameSaveInfoForSlot(int slot)
return &invalidInfo;
}

boolean SV_IsGameSaveSlotUsed(int slot)
{
const gamesaveinfo_t* info;
errorIfNotInited("SV_IsGameSaveSlotUsed");
info = findGameSaveInfoForSlot(slot);
return !Str_IsEmpty(&info->filePath);
}

const gamesaveinfo_t* SV_GetGameSaveInfoForSlot(int slot)
{
errorIfNotInited("SV_GetGameSaveInfoForSlot");
Expand Down Expand Up @@ -532,6 +524,31 @@ boolean SV_GetGameSavePathForMapSlot(uint map, int slot, ddstring_t* path)
}
#endif

boolean SV_IsGameSaveSlotUsed(int slot)
{
errorIfNotInited("SV_IsGameSaveSlotUsed");

#if __JHEXEN__
if(slot == REBORN_SLOT)
{
ddstring_t path;
boolean result = false;
Str_InitStd(&path);
if(SV_GetGameSavePathForSlot(REBORN_SLOT, &path))
{
result = SV_ExistingFile(Str_Text(&path));
}
Str_Free(&path);
return result;
}
else
#endif
{
const gamesaveinfo_t* info = SV_GetGameSaveInfoForSlot(slot);
return !Str_IsEmpty(&info->filePath);
}
}

void SV_CopySaveSlot(int sourceSlot, int destSlot)
{
AutoStr* src, *dst;
Expand Down

0 comments on commit 76a057a

Please sign in to comment.