Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SaveInfo|libcommon: Began transforming SaveInfo into a C++ class
  • Loading branch information
danij-deng committed Feb 3, 2014
1 parent 7296820 commit b9b93e8
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 103 deletions.
90 changes: 63 additions & 27 deletions doomsday/plugins/common/include/saveinfo.h
Expand Up @@ -45,21 +45,77 @@ typedef struct saveheader_s {
#endif
} saveheader_t;

#ifdef __cplusplus
/**
* SaveInfo instance.
* Saved game session info.
*/
typedef struct saveinfo_s {
Str name;
uint gameId;
saveheader_t header;
} SaveInfo;
class SaveInfo
{
public: /// @todo make private:
Str _name;
uint _gameId;
saveheader_t _header;

public:
SaveInfo();
SaveInfo(SaveInfo const &other);
~SaveInfo();

SaveInfo &operator = (SaveInfo const &other);

void configure();

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

int version() const;

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.
*/
void write(Writer *writer) const;

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

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

saveheader_t const *header() const;
};

#endif // __cplusplus

// C wrapper API, for legacy modules -------------------------------------------

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

SaveInfo *SaveInfo_New(void);
SaveInfo *SaveInfo_NewCopy(SaveInfo const *other);
SaveInfo *SaveInfo_Dup(SaveInfo const *other);

void SaveInfo_Delete(SaveInfo *info);

Expand All @@ -77,33 +133,13 @@ void SaveInfo_SetName(SaveInfo *info, Str const *newName);

void SaveInfo_Configure(SaveInfo *info);

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

/**
* Serializes the save info using @a writer.
*
* @param info SaveInfo instance.
* @param writer Writer instance.
*/
void SaveInfo_Write(SaveInfo *info, Writer *writer);

/**
* Deserializes the save info using @a reader.
*
* @param info SaveInfo instance.
* @param reader Reader instance.
*/
void SaveInfo_Read(SaveInfo *info, Reader *reader);

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

Expand Down
20 changes: 14 additions & 6 deletions doomsday/plugins/common/src/p_saveg.cpp
Expand Up @@ -689,19 +689,27 @@ static bool recogniseNativeState(Str const *path, SaveInfo *info)
#endif

// Magic must match.
if(info->header.magic != MY_SAVE_MAGIC &&
info->header.magic != MY_CLIENT_SAVE_MAGIC) return false;
saveheader_t const *hdr = &info->_header;
if(hdr->magic != MY_SAVE_MAGIC && hdr->magic != MY_CLIENT_SAVE_MAGIC)
{
return false;
}

/*
* Check for unsupported versions.
*/
// A future version?
if(info->header.version > MY_SAVE_VERSION) return false;
if(hdr->version > MY_SAVE_VERSION) // Future version?
{
return false;
}

#if __JHEXEN__
// We are incompatible with v3 saves due to an invalid test used to determine
// present sides (ver3 format's sides contain chunks of junk data).
if(info->header.version == 3) return false;
if(hdr->version == 3)
{
return false;
}
#endif

return true;
Expand Down Expand Up @@ -848,7 +856,7 @@ void SV_CopySlot(int sourceSlot, int destSlot)
SV_CopyFile(src, dst);

// Copy saveinfo too.
replaceSaveInfo(destSlot, SaveInfo_NewCopy(findSaveInfoForSlot(sourceSlot)));
replaceSaveInfo(destSlot, SaveInfo_Dup(findSaveInfoForSlot(sourceSlot)));
}

#if __JHEXEN__
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/p_xgfile.cpp
@@ -1,4 +1,4 @@
/** @file p_xgfile.cpp Extended Generalized Line Types.
/** @file p_xgfile.cpp Extended generalized line types.
*
* DD_XGDATA lump reader.
*
Expand Down

0 comments on commit b9b93e8

Please sign in to comment.