Skip to content

Commit

Permalink
libcommon|SaveSlots: Added a C wrapper API for SaveSlots and made use…
Browse files Browse the repository at this point in the history
… of it
  • Loading branch information
danij-deng committed Feb 10, 2014
1 parent d7502c9 commit 594db1a
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 192 deletions.
20 changes: 4 additions & 16 deletions doomsday/plugins/common/include/p_saveg.h
Expand Up @@ -22,13 +22,13 @@
#define LIBCOMMON_SAVESTATE_H

#include "common.h"
#ifdef __cplusplus
# include "dmu_archiveindex.h"
#endif
#include "p_saveio.h"
#include "saveinfo.h"
#include "saveslots.h"
//#include "p_saveio.h"

DENG_EXTERN_C int thingArchiveVersion;
DENG_EXTERN_C uint thingArchiveSize;
DENG_EXTERN_C SaveSlots saveSlots;

#ifdef __cplusplus
extern "C" {
Expand All @@ -45,13 +45,6 @@ void SV_Shutdown(void);

dd_bool SV_RecogniseGameState(Str const *path, SaveInfo *info);

void SV_UpdateAllSaveInfo(void);
int SV_SlotForSaveName(char const *name);
int SV_ParseSlotIdentifier(char const *str);
dd_bool SV_IsValidSlot(int slot);
dd_bool SV_IsUserWritableSlot(int slot);
dd_bool SV_IsSlotUsed(int slot);

#if __JHEXEN__
/**
* Returns @c true iff a game-save is present and serialized @a map state is
Expand All @@ -60,11 +53,6 @@ dd_bool SV_IsSlotUsed(int slot);
dd_bool SV_HxHaveMapStateForSlot(int slot, uint map);
#endif

SaveInfo *SV_SaveInfoForSlot(int slot);
AutoStr *SV_ComposeSlotIdentifier(int slot);
void SV_ClearSlot(int slot);
void SV_CopySlot(int sourceSlot, int destSlot);

/**
* Save the current game state to the specified @a slot number.
*
Expand Down
70 changes: 54 additions & 16 deletions doomsday/plugins/common/include/saveslots.h
Expand Up @@ -25,6 +25,8 @@
#include "saveinfo.h"
#include "p_savedef.h" /// @todo remove me

#ifdef __cplusplus

/**
* Maps saved games into a finite set of "save slots".
*
Expand Down Expand Up @@ -53,6 +55,11 @@ class SaveSlots
*/
void updateAllSaveInfo();

/**
* Returns @c true iff @a slot is a valid logical slot number (in range).
*/
bool isValidSlot(int slot);

/**
* Composes the textual identifier/name for save @a slot.
*/
Expand All @@ -76,44 +83,39 @@ class SaveSlots
int parseSlotIdentifier(char const *str);

/**
* 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).
* Lookup a save slot by searching for a match on game-save description. The search is in
* ascending logical slot order 0...N (where N is the number of available save slots).
*
* @param name Name of the game-save to look for. Case insensitive.
* @param description Description of the game-save to look for. Case insensitive.
*
* @return Logical slot number of the found game-save else @c -1
*/
int slotForSaveName(char const *description);
int findSlotWithSaveDescription(char const *description);

/**
* Returns @c true iff a game-save is present for logical save @a slot.
*/
bool slotInUse(int slot);

/**
* Returns @c true iff @a slot is a valid logical save slot.
*/
bool isValidSlot(int slot);

/**
* Returns @c true iff @a slot is user-writable save slot (i.e., its not one of the special
* slots such as @em auto).
*/
bool isUserWritableSlot(int slot);
bool slotIsUserWritable(int slot);

/**
* Returns the save info for save @a slot. Always returns SaveInfo even if supplied with an
* invalid or unused slot identifer (a null object).
*/
SaveInfo *findSaveInfoForSlot(int slot);

void replaceSaveInfo(int slot, SaveInfo *newInfo);
SaveInfo *saveInfo(int slot);

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

void replaceSaveInfo(int slot, SaveInfo *newInfo);

/**
* Copies all the save game files from one slot to another.
*/
Expand All @@ -127,10 +129,46 @@ class SaveSlots
*
* @return The composed path if reachable (else a zero-length string).
*/
AutoStr *composeGameSavePathForSlot(int slot, int map = -1);
AutoStr *composeSavePathForSlot(int slot, int map = -1);

/// Register the console commands and variables of this module.
static void consoleRegister();

private:
DENG2_PRIVATE(d)
};

#endif // LIBCOMMON_MAPSTATEREADER_H
#endif // __cplusplus

// C wrapper API ---------------------------------------------------------------

#ifdef __cplusplus
extern "C" {
#else
typedef void *SaveSlots;
#endif

SaveSlots *SaveSlots_New(void);
void SaveSlots_Delete(SaveSlots *sslots);

void SaveSlots_ClearSaveInfo(SaveSlots *sslots);
void SaveSlots_BuildSaveInfo(SaveSlots *sslots);
void SaveSlots_UpdateAllSaveInfo(SaveSlots *sslots);
dd_bool SaveSlots_IsValidSlot(SaveSlots *sslots, int slot);
AutoStr *SaveSlots_ComposeSlotIdentifier(SaveSlots *sslots, int slot);
int SaveSlots_ParseSlotIdentifier(SaveSlots *sslots, char const *str);
int SaveSlots_SlotForSaveName(SaveSlots *sslots, char const *description);
dd_bool SaveSlots_SlotInUse(SaveSlots *sslots, int slot);
dd_bool SaveSlots_SlotIsUserWritable(SaveSlots *sslots, int slot);
SaveInfo *SaveSlots_FindSaveInfoForSlot(SaveSlots *sslots, int slot);
void SaveSlots_ReplaceSaveInfo(SaveSlots *sslots, int slot, SaveInfo *newInfo);
void SaveSlots_ClearSlot(SaveSlots *sslots, int slot);
void SaveSlots_CopySlot(SaveSlots *sslots, int sourceSlot, int destSlot);
AutoStr *SaveSlots_ComposeSavePathForSlot(SaveSlots *sslots, int slot, int map);

void SaveSlots_ConsoleRegister();

#ifdef __cplusplus
} // extern "C"
#endif

#endif // LIBCOMMON_SAVESLOTS_H

0 comments on commit 594db1a

Please sign in to comment.