Skip to content

Commit

Permalink
libcommon|SaveInfo: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Feb 28, 2014
1 parent a011e4e commit 550c0f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 49 deletions.
16 changes: 5 additions & 11 deletions doomsday/plugins/common/include/saveinfo.h
Expand Up @@ -57,7 +57,7 @@ struct SessionMetadata
};

/**
* Represents a saved game session state.
* Logical component representing a saved game session.
*
* @ingroup libcommon
*/
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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:
Expand Down
72 changes: 34 additions & 38 deletions doomsday/plugins/common/src/saveinfo.cpp
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 550c0f9

Please sign in to comment.