Skip to content

Commit

Permalink
Game Save|Refactor: A "save slot" is not an IO level concept
Browse files Browse the repository at this point in the history
All code concerned with save slots has been relocated to p_saveg.c
  • Loading branch information
danij-deng committed Jun 24, 2012
1 parent 3c968b6 commit c3bd396
Show file tree
Hide file tree
Showing 4 changed files with 601 additions and 616 deletions.
78 changes: 78 additions & 0 deletions doomsday/plugins/common/include/p_saveg.h
Expand Up @@ -40,6 +40,84 @@ void SV_Init(void);
/// Shutdown this module.
void SV_Shutdown(void);

/**
* Force an update of the cached game-save info. To be called (sparingly)
* at strategic points when an update is necessary (e.g., the game-save
* paths have changed).
*
* \note It is not necessary to call this after a game-save is made,
* this module will do so automatically.
*/
void SV_UpdateAllSaveInfo(void);

/**
* Lookup a save slot by searching for a match on game-save name.
* Search is in ascending logical slot order 0...N (where N is the number
* of available save slots in the current game).
*
* @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_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).
* Pass 2: Check for keyword identifiers.
* <last> = The last used slot.
* <quick> = The currently nominated "quick save" 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_ParseSlotIdentifier(const char* str);

/// @return @c true iff @a slot is a valid logical save slot.
boolean SV_IsValidSlot(int slot);

/// @return @c true iff @a slot is user-writable save slot (not "auto" or similar).
boolean SV_IsUserWritableSlot(int slot);

/// @return @c true iff a game-save is present for logical save @a 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_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.
*/
saveinfo_t* SV_SaveInfoForSlot(int slot);

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

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

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

boolean SV_SaveGame(int slot, const char* name);

boolean SV_LoadGame(int slot);
Expand Down
89 changes: 5 additions & 84 deletions doomsday/plugins/common/include/p_saveio.h
Expand Up @@ -53,12 +53,6 @@ typedef struct saveinfo_s {
saveheader_t header;
} saveinfo_t;

typedef struct savegameparam_s {
const ddstring_t* path;
const char* name;
int slot;
} savegameparam_t;

enum {
SV_OK = 0,
SV_INVALIDFILENAME
Expand All @@ -73,90 +67,17 @@ const char* SV_SavePath(void);
const char* SV_ClientSavePath(void);
#endif

boolean SV_Recognise(saveinfo_t* info);

/*
* File management
*/
LZFILE* SV_OpenFile(const char* fileName, const char* mode);
void SV_CloseFile(void);
LZFILE* SV_File(void);

/**
* Force an update of the cached game-save info. To be called (sparingly)
* at strategic points when an update is necessary (e.g., the game-save
* paths have changed).
*
* \note It is not necessary to call this after a game-save is made,
* this module will do so automatically.
*/
void SV_UpdateAllSaveInfo(void);

/**
* Lookup a save slot by searching for a match on game-save name.
* Search is in ascending logical slot order 0...N (where N is the number
* of available save slots in the current game).
*
* @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_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).
* Pass 2: Check for keyword identifiers.
* <last> = The last used slot.
* <quick> = The currently nominated "quick save" 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_ParseSlotIdentifier(const char* str);

/// @return @c true iff @a slot is a valid logical save slot.
boolean SV_IsValidSlot(int slot);

/// @return @c true iff @a slot is user-writable save slot (not "auto" or similar).
boolean SV_IsUserWritableSlot(int slot);

/// @return @c true iff a game-save is present for logical save @a 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_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.
*/
saveinfo_t* SV_SaveInfoForSlot(int slot);

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

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

/**
* Copies all the save game files from one slot to another.
*/
void SV_CopySlot(int sourceSlot, int destSlot);
boolean SV_ExistingFile(char* name);
int SV_RemoveFile(const ddstring_t* path);
void SV_CopyFile(const ddstring_t* srcPath, const ddstring_t* destPath);

#if __JHEXEN__
saveptr_t* SV_HxSavePtr(void);
Expand Down

0 comments on commit c3bd396

Please sign in to comment.