From 76a057a5c247d045910dd19dc03969df3306a0fd Mon Sep 17 00:00:00 2001 From: danij Date: Thu, 21 Jun 2012 02:03:14 +0100 Subject: [PATCH] libcommon|Refactor: Reworked save game interfaces --- doomsday/plugins/common/include/p_saveg.h | 10 ------- doomsday/plugins/common/src/g_game.c | 21 +++++++-------- doomsday/plugins/common/src/p_saveg.c | 31 --------------------- doomsday/plugins/common/src/p_saveio.c | 33 +++++++++++++++++------ 4 files changed, 35 insertions(+), 60 deletions(-) diff --git a/doomsday/plugins/common/include/p_saveg.h b/doomsday/plugins/common/include/p_saveg.h index 56a85b8531..1a61d7b3b6 100644 --- a/doomsday/plugins/common/include/p_saveg.h +++ b/doomsday/plugins/common/include/p_saveg.h @@ -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); diff --git a/doomsday/plugins/common/src/g_game.c b/doomsday/plugins/common/src/g_game.c index c919b32842..08160ecb88 100644 --- a/doomsday/plugins/common/src/g_game.c +++ b/doomsday/plugins/common/src/g_game.c @@ -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); @@ -2033,7 +2033,7 @@ void G_DoReborn(int plrNum) void G_StartNewInit(void) { SV_HxInitBaseSlot(); - SV_HxClearRebornSlot(); + SV_ClearSaveSlot(REBORN_SLOT); P_ACSInitNewGame(); @@ -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 @@ -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) diff --git a/doomsday/plugins/common/src/p_saveg.c b/doomsday/plugins/common/src/p_saveg.c index 343600f2f0..e08e4e3eab 100644 --- a/doomsday/plugins/common/src/p_saveg.c +++ b/doomsday/plugins/common/src/p_saveg.c @@ -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__ diff --git a/doomsday/plugins/common/src/p_saveio.c b/doomsday/plugins/common/src/p_saveio.c index 093b93eeb8..c2bdf8c2ac 100644 --- a/doomsday/plugins/common/src/p_saveio.c +++ b/doomsday/plugins/common/src/p_saveio.c @@ -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"); @@ -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;