Skip to content

Commit

Permalink
Game Save|Refactor: Improved code-level naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 22, 2012
1 parent 8c5a81d commit b54e32f
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 153 deletions.
14 changes: 7 additions & 7 deletions doomsday/plugins/common/include/p_saveg.h
Expand Up @@ -54,9 +54,9 @@ void SV_HxMapTeleport(uint map, uint position);
* Saves a snapshot of the world, a still image.
* No data of movement is included (server sends it).
*/
void SV_SaveClient(uint gameId);
void SV_SaveGameClient(uint gameId);

void SV_LoadClient(uint gameId);
void SV_LoadGameClient(uint gameId);
#endif

typedef enum gamearchivesegment_e {
Expand Down Expand Up @@ -116,14 +116,14 @@ typedef enum thinkclass_e {
} thinkerclass_t;

#if __JHEXEN__
int SV_ThingArchiveNum(mobj_t* mo);
int SV_ThingArchiveNum(mobj_t* mo);
#else
unsigned short SV_ThingArchiveNum(mobj_t* mo);
unsigned short SV_ThingArchiveNum(mobj_t* mo);
#endif
mobj_t* SV_GetArchiveThing(int thingid, void* address);
mobj_t* SV_GetArchiveThing(int thingid, void* address);

MaterialArchive* SV_MaterialArchive(void);
material_t* SV_GetArchiveMaterial(materialarchive_serialid_t serialId, int group);
material_t* SV_GetArchiveMaterial(materialarchive_serialid_t serialId, int group);

/**
* Exit with a fatal error if the value at the current location in the
Expand All @@ -144,6 +144,6 @@ void SV_BeginSegment(int segType);
* @param mo Mobj whoose flags are to be updated.
* @param ver The MOBJ save version to update from.
*/
void SV_UpdateReadMobjFlags(mobj_t* mo, int ver);
void SV_TranslateLegacyMobjFlags(mobj_t* mo, int ver);

#endif /* LIBCOMMON_SAVESTATE_H */
69 changes: 34 additions & 35 deletions doomsday/plugins/common/include/p_saveio.h
@@ -1,25 +1,23 @@
/**\file p_saveio.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2012 Daniel Swanson <danij@dengine.net>
/**
* @file p_saveio.h
* Game save file IO.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* @authors Copyright &copy; 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2005-2012 Daniel Swanson <danij@dengine.net>
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBCOMMON_SAVESTATE_INPUT_OUTPUT_H
Expand Down Expand Up @@ -49,10 +47,10 @@ typedef struct saveheader_s {
unsigned int gameId;
} saveheader_t;

typedef struct gamesaveinfo_s {
typedef struct saveinfo_s {
ddstring_t filePath;
ddstring_t name;
} gamesaveinfo_t;
} saveinfo_t;

typedef struct savegameparam_s {
const ddstring_t* path;
Expand All @@ -67,6 +65,7 @@ enum {

void SV_InitIO(void);
void SV_ShutdownIO(void);

void SV_ConfigureSavePaths(void);
const char* SV_SavePath(void);
#if !__JHEXEN__
Expand All @@ -88,7 +87,7 @@ LZFILE* SV_File(void);
* \note It is not necessary to call this after a game-save is made,
* this module will do so automatically.
*/
void SV_UpdateGameSaveInfo(void);
void SV_UpdateAllSaveInfo(void);

/**
* Lookup a save slot by searching for a match on game-save name.
Expand All @@ -98,25 +97,25 @@ void SV_UpdateGameSaveInfo(void);
* @param name Name of the game-save to look for. Case insensitive.
* @return Logical slot number of the found game-save else @c -1
*/
int SV_FindGameSaveSlotForName(const char* name);
int SV_SlotForSaveName(const char* name);

/**
* Parse the given string and determine whether it references a logical
* game-save slot.
*
* @param str String to be parsed. Parse is divided into three passes.
* Pass 1: Check for a known game-save name which matches this.
* Search is in ascending logical slot order 0..N (where N is the
* number of available save slots in the current game).
* Search is in ascending logical slot order 0..N (where N
* is the number of available save slots).
* Pass 2: Check for keyword identifiers.
* <last> = The last used slot.
* <quick> = The currently nominated "quick save" slot.
* <auto> = The autosave slot.
* <auto> = The "auto save" slot.
* Pass 3: Check for a logical save slot number.
*
* @return Save slot identifier of the slot else @c -1
*/
int SV_ParseGameSaveSlot(const char* str);
int SV_ParseSlotIdentifier(const char* str);

/// @return @c true iff @a slot is a valid logical save slot.
boolean SV_IsValidSlot(int slot);
Expand All @@ -125,38 +124,38 @@ boolean SV_IsValidSlot(int slot);
boolean SV_IsUserWritableSlot(int slot);

/// @return @c true iff a game-save is present for logical save @a slot.
boolean SV_IsGameSaveSlotUsed(int slot);
boolean SV_IsSlotUsed(int slot);

#if __JHEXEN__
/**
* @return @c true iff a game-save is present and serialized @a map state is
* is present for logical save @a slot.
*/
boolean SV_HxGameSaveSlotHasMapState(int slot, uint map);
boolean SV_HxHaveMapSaveForSlot(int slot, uint map);
#endif

/**
* @return Game-save info for logical save @a slot. Always returns valid
* info even if supplied with an invalid or unused slot identifer.
*/
const gamesaveinfo_t* SV_GameSaveInfoForSlot(int slot);
const saveinfo_t* SV_SaveInfoForSlot(int slot);

boolean SV_GameSavePathForSlot(int slot, ddstring_t* path);
boolean SV_ComposeSavePathForSlot(int slot, ddstring_t* path);
#if __JHEXEN__
boolean SV_GameSavePathForMapSlot(uint map, int slot, ddstring_t* path);
boolean SV_ComposeSavePathForMapSlot(uint map, int slot, ddstring_t* path);
#else
boolean SV_ClientGameSavePathForGameId(uint gameId, ddstring_t* path);
boolean SV_ComposeSavePathForClientGameId(uint gameId, ddstring_t* path);
#endif

/**
* Deletes all save game files associated with a slot number.
*/
void SV_ClearSaveSlot(int slot);
void SV_ClearSlot(int slot);

/**
* Copies all the save game files from one slot to another.
*/
void SV_CopySaveSlot(int sourceSlot, int destSlot);
void SV_CopySlot(int sourceSlot, int destSlot);

#if __JHEXEN__
saveptr_t* SV_HxSavePtr(void);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/d_netcl.c
Expand Up @@ -838,7 +838,7 @@ void NetCl_SaveGame(Reader* msg)

/// @todo: Why not Hexen?
#if !__JHEXEN__
SV_SaveClient(Reader_ReadUInt32(msg));
SV_SaveGameClient(Reader_ReadUInt32(msg));
#endif
#if __JDOOM__ || __JDOOM64__
P_SetMessage(&players[CONSOLEPLAYER], TXT_GAMESAVED, false);
Expand All @@ -853,7 +853,7 @@ void NetCl_LoadGame(Reader* msg)
return;

#if !__JHEXEN__
SV_LoadClient(Reader_ReadUInt32(msg));
SV_LoadGameClient(Reader_ReadUInt32(msg));
#endif
#if __JDOOM__ || __JDOOM64__
P_SetMessage(&players[CONSOLEPLAYER], GET_TXT(TXT_CLNETLOAD), false);
Expand Down
30 changes: 15 additions & 15 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -2036,7 +2036,7 @@ void G_StartNewInit(void)
/// @todo Do not clear this save slot. Instead we should set a game state
/// flag to signal when a new game should be started instead of loading
/// the autosave slot.
SV_ClearSaveSlot(AUTO_SLOT);
SV_ClearSlot(AUTO_SLOT);

P_ACSInitNewGame();

Expand Down Expand Up @@ -2352,9 +2352,9 @@ boolean G_LoadGame(int slot)
// no guarantee that the game-save will be accessible come load time.

// First ensure we have up-to-date info.
SV_UpdateGameSaveInfo();
SV_UpdateAllSaveInfo();

if(!SV_IsGameSaveSlotUsed(slot))
if(!SV_IsSlotUsed(slot))
{
Con_Message("Warning:G_LoadGame: Save slot #%i is not in use, aborting load.\n", slot);
return false;
Expand Down Expand Up @@ -2383,8 +2383,8 @@ void G_DoLoadGame(void)
if(IS_NETGAME) return;

// Copy the base slot to the autosave slot.
SV_ClearSaveSlot(AUTO_SLOT);
SV_CopySaveSlot(BASE_SLOT, AUTO_SLOT);
SV_ClearSlot(AUTO_SLOT);
SV_CopySlot(BASE_SLOT, AUTO_SLOT);
#endif
}

Expand Down Expand Up @@ -2491,7 +2491,7 @@ void G_DoSaveGame(void)
else
{
// No name specified.
const gamesaveinfo_t* info = SV_GameSaveInfoForSlot(gaSaveGameSlot);
const saveinfo_t* info = SV_SaveInfoForSlot(gaSaveGameSlot);
if(!gaSaveGameGenerateName && !Str_IsEmpty(&info->name))
{
// Slot already in use; reuse the existing name.
Expand Down Expand Up @@ -3388,13 +3388,13 @@ D_CMD(LoadGame)
}

// Ensure we have up-to-date info.
SV_UpdateGameSaveInfo();
SV_UpdateAllSaveInfo();

slot = SV_ParseGameSaveSlot(argv[1]);
if(SV_IsGameSaveSlotUsed(slot))
slot = SV_ParseSlotIdentifier(argv[1]);
if(SV_IsSlotUsed(slot))
{
// A known used slot identifier.
const gamesaveinfo_t* info;
const saveinfo_t* info;
char buf[80];

if(confirm || !cfg.confirmQuickGameSave)
Expand All @@ -3404,7 +3404,7 @@ D_CMD(LoadGame)
return G_LoadGame(slot);
}

info = SV_GameSaveInfoForSlot(slot);
info = SV_SaveInfoForSlot(slot);
dd_snprintf(buf, 80, QLPROMPT, Str_Text(&info->name));

S_LocalSound(SFX_QUICKLOAD_PROMPT, NULL);
Expand Down Expand Up @@ -3482,13 +3482,13 @@ D_CMD(SaveGame)
}

// Ensure we have up-to-date info.
SV_UpdateGameSaveInfo();
SV_UpdateAllSaveInfo();

slot = SV_ParseGameSaveSlot(argv[1]);
slot = SV_ParseSlotIdentifier(argv[1]);
if(SV_IsUserWritableSlot(slot))
{
// A known slot identifier.
const boolean slotIsUsed = SV_IsGameSaveSlotUsed(slot);
const boolean slotIsUsed = SV_IsSlotUsed(slot);
const char* name = (argc >= 3 && stricmp(argv[2], "confirm"))? argv[2] : NULL;
char buf[80];

Expand All @@ -3500,7 +3500,7 @@ D_CMD(SaveGame)
}

{
const gamesaveinfo_t* info = SV_GameSaveInfoForSlot(slot);
const saveinfo_t* info = SV_SaveInfoForSlot(slot);
dd_snprintf(buf, 80, QSPROMPT, Str_Text(&info->name));

S_LocalSound(SFX_QUICKSAVE_PROMPT, NULL);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/hu_menu.c
Expand Up @@ -3287,15 +3287,15 @@ void Hu_MenuUpdateGameSaveWidgets(void)
// Prompt a refresh of the game-save info. We don't yet actively monitor
// the contents of the game-save paths, so instead we settle for manual
// updates whenever the save/load menu is opened.
SV_UpdateGameSaveInfo();
SV_UpdateAllSaveInfo();

// Update widgets.
page = Hu_MenuFindPageByName("LoadGame");
for(i = 0; i < NUMSAVESLOTS; ++i)
{
mn_object_t* obj = MN_MustFindObjectOnPage(page, 0, saveSlotObjectIds[i]);
mndata_edit_t* edit = (mndata_edit_t*) obj->_typedata;
const gamesaveinfo_t* info = SV_GameSaveInfoForSlot(edit->data2);
const saveinfo_t* info = SV_SaveInfoForSlot(edit->data2);
const char* text = "";

MNObject_SetFlags(obj, FO_SET, MNF_DISABLED);
Expand Down

0 comments on commit b54e32f

Please sign in to comment.