Skip to content

Commit

Permalink
Refactor|libcommon: Updated save state IO to use SaveInfo's C++ API, …
Browse files Browse the repository at this point in the history
…directly
  • Loading branch information
danij-deng committed Feb 3, 2014
1 parent b9b93e8 commit d00a767
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 99 deletions.
53 changes: 30 additions & 23 deletions doomsday/plugins/common/include/saveinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typedef struct saveheader_s {
class SaveInfo
{
public: /// @todo make private:
Str _name;
Str _description;
uint _gameId;
saveheader_t _header;

Expand All @@ -66,41 +66,50 @@ class SaveInfo
void configure();

/**
* Returns @a true if the game state is compatibile with the current game session
* and @em should be loadable.
* Returns @a true if the game session is compatibile with the current game session
* and @em should therefore be loadable.
*/
dd_bool isLoadable();
bool isLoadable();

/**
* Returns the logicl version of the serialized game session state.
*/
int version() const;

/**
* Returns the textual description of the game session (provided by the user).
*/
Str const *description() const;
void setDescription(Str const *newDesc);

/**
* @see SV_GenerateGameId()
*/
uint gameId() const;
void setGameId(uint newGameId);

Str const *name() const;
void setName(Str const *newName);

/**
* Serializes the save info using @a writer.
*
* @param writer Writer instance.
* Serializes the game session info using @a writer.
*/
void write(Writer *writer) const;

/**
* Deserializes the save info using @a reader.
*
* @param reader Reader instance.
* Deserializes the game session info using @a reader.
*/
void read(Reader *reader);

#if __JHEXEN__
/**
* @brief libhexen specific version of @ref SaveInfo_Read() for deserializing
* legacy version 9 save state info.
* legacy version 9 game session info.
*/
void read_Hx_v9(Reader *reader);
#endif

/**
* Provides readonly access to the game session header.
* @todo refactor away.
*/
saveheader_t const *header() const;
};

Expand All @@ -121,20 +130,16 @@ void SaveInfo_Delete(SaveInfo *info);

SaveInfo *SaveInfo_Copy(SaveInfo *info, SaveInfo const *other);

uint SaveInfo_GameId(SaveInfo const *info);
void SaveInfo_Configure(SaveInfo *info);

saveheader_t const *SaveInfo_Header(SaveInfo const *info);
dd_bool SaveInfo_IsLoadable(SaveInfo *info);

Str const *SaveInfo_Name(SaveInfo const *info);
Str const *SaveInfo_Description(SaveInfo const *info);
void SaveInfo_SetDescription(SaveInfo *info, Str const *newName);

uint SaveInfo_GameId(SaveInfo const *info);
void SaveInfo_SetGameId(SaveInfo *info, uint newGameId);

void SaveInfo_SetName(SaveInfo *info, Str const *newName);

void SaveInfo_Configure(SaveInfo *info);

dd_bool SaveInfo_IsLoadable(SaveInfo *info);

void SaveInfo_Write(SaveInfo *info, Writer *writer);

void SaveInfo_Read(SaveInfo *info, Reader *reader);
Expand All @@ -143,6 +148,8 @@ void SaveInfo_Read(SaveInfo *info, Reader *reader);
void SaveInfo_Read_Hx_v9(SaveInfo *info, Reader *reader);
#endif

saveheader_t const *SaveInfo_Header(SaveInfo const *info);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
12 changes: 6 additions & 6 deletions doomsday/plugins/common/src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,7 @@ void G_DoReborn(int plrNum)
{
// Compose the confirmation message.
SaveInfo* info = SV_SaveInfoForSlot(chosenSlot);
AutoStr* msg = Str_Appendf(AutoStr_NewStd(), REBORNLOAD_CONFIRM, Str_Text(SaveInfo_Name(info)));
AutoStr* msg = Str_Appendf(AutoStr_NewStd(), REBORNLOAD_CONFIRM, Str_Text(SaveInfo_Description(info)));
S_LocalSound(SFX_REBORNLOAD_CONFIRM, NULL);
Hu_MsgStart(MSG_YESNO, Str_Text(msg), rebornLoadConfirmResponse, chosenSlot, 0);
}
Expand Down Expand Up @@ -2929,10 +2929,10 @@ void G_DoSaveGame(void)
{
// No name specified.
SaveInfo* info = SV_SaveInfoForSlot(gaSaveGameSlot);
if(!gaSaveGameGenerateName && !Str_IsEmpty(SaveInfo_Name(info)))
if(!gaSaveGameGenerateName && !Str_IsEmpty(SaveInfo_Description(info)))
{
// Slot already in use; reuse the existing name.
name = Str_Text(SaveInfo_Name(info));
name = Str_Text(SaveInfo_Description(info));
}
else
{
Expand Down Expand Up @@ -3663,7 +3663,7 @@ D_CMD(LoadGame)

info = SV_SaveInfoForSlot(slot);
// Compose the confirmation message.
msg = Str_Appendf(AutoStr_NewStd(), QLPROMPT, Str_Text(SaveInfo_Name(info)));
msg = Str_Appendf(AutoStr_NewStd(), QLPROMPT, Str_Text(SaveInfo_Description(info)));

S_LocalSound(SFX_QUICKLOAD_PROMPT, NULL);
Hu_MsgStart(MSG_YESNO, Str_Text(msg), loadGameConfirmResponse, slot, 0);
Expand Down Expand Up @@ -3762,7 +3762,7 @@ D_CMD(SaveGame)
}

// Compose the confirmation message.
msg = Str_Appendf(AutoStr_NewStd(), QSPROMPT, Str_Text(SaveInfo_Name(info)));
msg = Str_Appendf(AutoStr_NewStd(), QSPROMPT, Str_Text(SaveInfo_Description(info)));

// Make a copy of the name.
name = Str_Copy(Str_New(), &localName);
Expand Down Expand Up @@ -3856,7 +3856,7 @@ D_CMD(DeleteGameSave)
{
// Compose the confirmation message.
SaveInfo* info = SV_SaveInfoForSlot(slot);
AutoStr* msg = Str_Appendf(AutoStr_NewStd(), DELETESAVEGAME_CONFIRM, Str_Text(SaveInfo_Name(info)));
AutoStr* msg = Str_Appendf(AutoStr_NewStd(), DELETESAVEGAME_CONFIRM, Str_Text(SaveInfo_Description(info)));
S_LocalSound(SFX_DELETESAVEGAME_CONFIRM, NULL);
Hu_MsgStart(MSG_YESNO, Str_Text(msg), deleteSaveGameConfirmResponse, slot, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/hu_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -5662,7 +5662,7 @@ void Hu_MenuUpdateGameSaveWidgets(void)
if(SV_IsSlotUsed(edit->data2))
{
SaveInfo* info = SV_SaveInfoForSlot(edit->data2);
text = Str_Text(SaveInfo_Name(info));
text = Str_Text(SaveInfo_Description(info));
MNObject_SetFlags(obj, FO_CLEAR, MNF_DISABLED);
}
MNEdit_SetText(obj, MNEDIT_STF_NO_ACTION, text);
Expand Down
Loading

0 comments on commit d00a767

Please sign in to comment.