Skip to content

Commit

Permalink
Game Save|Cleanup: Swap SaveInfo upon a successful save
Browse files Browse the repository at this point in the history
It is now unnecessary to call SV_UpdateAllSaveInfo() upon saving as
we can simply swap in the new SaveInfo instance.
  • Loading branch information
danij-deng committed Jun 26, 2012
1 parent be4a886 commit 2adb125
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
31 changes: 18 additions & 13 deletions doomsday/plugins/common/src/p_saveg.c
Original file line number Diff line number Diff line change
Expand Up @@ -5352,7 +5352,7 @@ boolean SV_SaveGame(int slot, const char* name)
#else
const int logicalSlot = slot;
#endif
SaveInfo* saveInfo;
SaveInfo* info;
AutoStr* path;
ddstring_t nameStr;
int saveError;
Expand All @@ -5377,16 +5377,14 @@ boolean SV_SaveGame(int slot, const char* name)
Con_Message("Warning: Path \"%s\" is unreachable, game not saved.\n", SV_SavePath());
return false;
}
saveInfo = SaveInfo_NewWithFilePath(path);
SaveInfo_SetName(saveInfo, Str_InitStatic(&nameStr, name));
SaveInfo_SetGameId(saveInfo, SV_GenerateGameId());
SaveInfo_Configure(saveInfo);
info = SaveInfo_NewWithFilePath(path);
SaveInfo_SetName(info, Str_InitStatic(&nameStr, name));
SaveInfo_SetGameId(info, SV_GenerateGameId());
SaveInfo_Configure(info);

/// @todo Use progress bar mode and update progress during the setup.
saveError = Con_Busy(BUSYF_ACTIVITY | /*BUSYF_PROGRESS_BAR |*/ (verbose? BUSYF_CONSOLE_OUTPUT : 0),
"Saving game...", saveGameWorker, saveInfo);

SaveInfo_Delete(saveInfo);
"Saving game...", saveGameWorker, info);

if(!saveError)
{
Expand All @@ -5397,16 +5395,23 @@ boolean SV_SaveGame(int slot, const char* name)
// Copy base slot to destination slot.
SV_CopySlot(BASE_SLOT, slot);
#endif
// Swap the save info.
if(saveInfo[slot]) SaveInfo_Delete(saveInfo[slot]);
saveInfo[slot] = info;

// The "last" save slot is now this.
Con_SetInteger2("game-save-last-slot", slot, SVF_WRITE_OVERRIDE);
}
else if(saveError == SV_INVALIDFILENAME)
else
{
Con_Message("Warning: Failed opening \"%s\" for writing.\n", Str_Text(path));
}
// We no longer need the info.
SaveInfo_Delete(info);

// Update our game save info.
SV_UpdateAllSaveInfo();
if(saveError == SV_INVALIDFILENAME)
{
Con_Message("Warning: Failed opening \"%s\" for writing.\n", Str_Text(path));
}
}

return !saveError;
}
Expand Down
7 changes: 3 additions & 4 deletions doomsday/plugins/common/src/saveinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,13 @@ void SaveInfo_Read_Hx_v9(SaveInfo* saveInfo, Reader* reader)
# define HXS_VERSION_TEXT_LENGTH 16
# define HXS_NAME_LENGTH 24

char verText[HXS_VERSION_TEXT_LENGTH], name[HXS_NAME_LENGTH];
ddstring_t nameStr;
char verText[HXS_VERSION_TEXT_LENGTH], nameBuffer[HXS_NAME_LENGTH];
saveheader_t* info;
assert(saveInfo);

info = &saveInfo->header;
Reader_Read(reader, name, HXS_NAME_LENGTH);
SaveInfo_SetName(saveInfo, Str_InitStatic(&nameStr, name));
Reader_Read(reader, nameBuffer, HXS_NAME_LENGTH);
Str_Set(&saveInfo->name, nameBuffer);
Reader_Read(reader, &verText, HXS_VERSION_TEXT_LENGTH);
info->version = atoi(&verText[8]);

Expand Down

0 comments on commit 2adb125

Please sign in to comment.