From 550c0f9bf9ee18d7dfa2004f6f14885a94029051 Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 28 Feb 2014 08:23:39 +0000 Subject: [PATCH] libcommon|SaveInfo: Cleanup --- doomsday/plugins/common/include/saveinfo.h | 16 ++--- doomsday/plugins/common/src/saveinfo.cpp | 72 ++++++++++------------ 2 files changed, 39 insertions(+), 49 deletions(-) diff --git a/doomsday/plugins/common/include/saveinfo.h b/doomsday/plugins/common/include/saveinfo.h index 2660b001f6..e26eb2daa4 100644 --- a/doomsday/plugins/common/include/saveinfo.h +++ b/doomsday/plugins/common/include/saveinfo.h @@ -57,7 +57,7 @@ struct SessionMetadata }; /** - * Represents a saved game session state. + * Logical component representing a saved game session. * * @ingroup libcommon */ @@ -151,12 +151,6 @@ class SaveInfo */ de::String fileNameForMap(Uri const *mapUri = 0) const; - /** - * Update the metadata associated with the save using values derived from the current game - * session. Note that this does @em not affect the copy of this save on disk. - */ - void applyCurrentSessionMeta(); - /** * Provides read-only access to a copy of the deserialized game session metadata. */ @@ -168,19 +162,19 @@ class SaveInfo void readMeta(Reader *reader); // Metadata manipulation: - void setGameIdentityKey(de::String newGameIdentityKey); + void setMagic(int newMagic); void setVersion(int newVersion); - void setUserDescription(de::String newUserDescription); void setSessionId(uint newSessionId); + void setGameIdentityKey(de::String newGameIdentityKey); + void setGameRules(GameRuleset const &newRules); + void setUserDescription(de::String newUserDescription); void setMapUri(Uri const *newMapUri); #if !__JHEXEN__ void setMapTime(int newMapTime); void setPlayers(SessionMetadata::Players const &newPlayers); #endif // !__JHEXEN__ - void setGameRules(GameRuleset const &newRules); public: /// @todo refactor away: - void setMagic(int newMagic); static SaveInfo *fromReader(Reader *reader); private: diff --git a/doomsday/plugins/common/src/saveinfo.cpp b/doomsday/plugins/common/src/saveinfo.cpp index a88105c72d..3f39855b4e 100644 --- a/doomsday/plugins/common/src/saveinfo.cpp +++ b/doomsday/plugins/common/src/saveinfo.cpp @@ -263,11 +263,11 @@ using namespace internal; DENG2_PIMPL(SaveInfo) { - SessionStatus status; - bool needUpdateStatus; - String fileName; ///< Name of the game session file. + SessionMetadata meta; + SessionStatus status; + bool needUpdateStatus; Instance(Public *i) : Base(i) @@ -277,10 +277,10 @@ DENG2_PIMPL(SaveInfo) Instance(Public *i, Instance const &other) : Base(i) - , status (other.status) - , needUpdateStatus(other.needUpdateStatus) , fileName (other.fileName) , meta (other.meta) + , status (other.status) + , needUpdateStatus(other.needUpdateStatus) {} void updateStatusIfNeeded() @@ -327,9 +327,26 @@ SaveInfo *SaveInfo::newWithCurrentSessionMeta(String const &fileName, { LOG_AS("SaveInfo"); SaveInfo *info = new SaveInfo(fileName); - info->setUserDescription(userDescription); - info->applyCurrentSessionMeta(); - info->setSessionId(G_GenerateSessionId()); + + info->d->meta.userDescription = userDescription; + info->d->meta.magic = IS_NETWORK_CLIENT? MY_CLIENT_SAVE_MAGIC : MY_SAVE_MAGIC; + info->d->meta.version = MY_SAVE_VERSION; + info->d->meta.gameIdentityKey = G_IdentityKey(); + Uri_Copy(info->d->meta.mapUri, gameMapUri); +#if !__JHEXEN__ + info->d->meta.mapTime = ::mapTime; +#endif + info->d->meta.gameRules = G_Rules(); // Make a copy. + +#if !__JHEXEN__ + for(int i = 0; i < MAXPLAYERS; i++) + { + info->d->meta.players[i] = (::players[i]).plr->inGame; + } +#endif + info->d->meta.sessionId = G_GenerateSessionId(); + + info->d->needUpdateStatus = true; return info; } @@ -377,6 +394,15 @@ void SaveInfo::setGameIdentityKey(String newGameIdentityKey) } } +void SaveInfo::setMagic(int newMagic) +{ + if(d->meta.magic != newMagic) + { + d->meta.magic = newMagic; + d->needUpdateStatus = true; + } +} + void SaveInfo::setVersion(int newVersion) { if(d->meta.version != newVersion) @@ -432,27 +458,6 @@ void SaveInfo::setGameRules(GameRuleset const &newRules) d->needUpdateStatus = true; } -void SaveInfo::applyCurrentSessionMeta() -{ - LOG_AS("SaveInfo"); - d->meta.magic = IS_NETWORK_CLIENT? MY_CLIENT_SAVE_MAGIC : MY_SAVE_MAGIC; - d->meta.version = MY_SAVE_VERSION; - d->meta.gameIdentityKey = G_IdentityKey(); - Uri_Copy(d->meta.mapUri, gameMapUri); -#if !__JHEXEN__ - d->meta.mapTime = ::mapTime; -#endif - d->meta.gameRules = G_Rules(); // Make a copy. - -#if !__JHEXEN__ - for(int i = 0; i < MAXPLAYERS; i++) - { - d->meta.players[i] = (::players[i]).plr->inGame; - } -#endif - d->needUpdateStatus = true; -} - bool SaveInfo::haveGameSession() const { LOG_AS("SaveInfo"); @@ -538,15 +543,6 @@ String SaveInfo::description() const .arg(statusAsText()); } -void SaveInfo::setMagic(int newMagic) -{ - if(d->meta.magic != newMagic) - { - d->meta.magic = newMagic; - d->needUpdateStatus = true; - } -} - SaveInfo *SaveInfo::fromReader(reader_s *reader) // static { SaveInfo *info = new SaveInfo;