Skip to content

Commit

Permalink
SaveInfo|libcommon: Use 0-based logical episode and map numbers natively
Browse files Browse the repository at this point in the history
Also fixed a new regression with deserializing v.13 format info.
  • Loading branch information
danij-deng committed Feb 4, 2014
1 parent 8cae7d4 commit 31f8419
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 37 deletions.
24 changes: 19 additions & 5 deletions doomsday/plugins/common/include/saveinfo.h
Expand Up @@ -54,8 +54,8 @@ class SaveInfo
void configure();

/**
* Returns @a true if the game session is compatibile with the current game session
* and @em should therefore be loadable.
* Determines whether the saved game session is compatibile with the current
* game session (and @em should therefore be loadable).
*/
bool isLoadable();

Expand All @@ -77,11 +77,26 @@ class SaveInfo
uint gameId() const;
void setGameId(uint newGameId);

/**
* Returns the logical episode number for the game session.
*/
uint episode() const;

/**
* Returns the logical map number for the game session.
*/
uint map() const;

#if !__JHEXEN__
/**
* Returns the expired time in tics since the map begun.
*/
int mapTime() const;
#endif

/**
* Returns the game ruleset for the game session.
*/
GameRuleset const &gameRules() const;

/**
Expand All @@ -94,11 +109,10 @@ class SaveInfo
*/
void read(Reader *reader);

#if __JHEXEN__
/**
* @brief libhexen specific version of @ref SaveInfo_Read() for deserializing
* legacy version 9 game session info.
* Hexen-specific version for deserializing legacy v.9 game session info.
*/
#if __JHEXEN__
void read_Hx_v9(Reader *reader);
#endif
};
Expand Down
51 changes: 31 additions & 20 deletions doomsday/plugins/common/src/saveinfo.cpp
Expand Up @@ -161,12 +161,12 @@ void SaveInfo::setGameId(uint newGameId)

uint SaveInfo::episode() const
{
return _episode - 1;
return _episode;
}

uint SaveInfo::map() const
{
return _map - 1;
return _map;
}

#if !__JHEXEN__
Expand All @@ -189,10 +189,10 @@ void SaveInfo::configure()
#if __JHEXEN__
_episode = 1;
#else
_episode = gameEpisode + 1;
_episode = gameEpisode;
_mapTime = ::mapTime;
#endif
_map = gameMap + 1;
_map = gameMap;

// Make a copy of the current game rules.
G_GetGameRules(&_gameRules);
Expand Down Expand Up @@ -274,28 +274,39 @@ void SaveInfo::read(Reader *reader)
else
{
#if !__JHEXEN__
// In DOOM the high bit of the skill mode byte is also used for the
// "fast" game rule dd_bool. There is more confusion in that SM_NOTHINGS
// will result in 0xff and thus always set the fast bit.
//
// Here we decipher this assuming that if the skill mode is invalid then
// by default this means "spawn no things" and if so then the "fast" game
// rule is meaningless so it is forced off.
byte skillModePlusFastBit = Reader_ReadByte(reader);
_gameRules.skill = (skillmode_t) (skillModePlusFastBit & 0x7f);
if(_gameRules.skill < SM_BABY || _gameRules.skill >= NUM_SKILL_MODES)
if(_version < 13)
{
_gameRules.skill = SM_NOTHINGS;
_gameRules.fast = 0;
// In DOOM the high bit of the skill mode byte is also used for the
// "fast" game rule dd_bool. There is more confusion in that SM_NOTHINGS
// will result in 0xff and thus always set the fast bit.
//
// Here we decipher this assuming that if the skill mode is invalid then
// by default this means "spawn no things" and if so then the "fast" game
// rule is meaningless so it is forced off.
byte skillModePlusFastBit = Reader_ReadByte(reader);
_gameRules.skill = (skillmode_t) (skillModePlusFastBit & 0x7f);
if(_gameRules.skill < SM_BABY || _gameRules.skill >= NUM_SKILL_MODES)
{
_gameRules.skill = SM_NOTHINGS;
_gameRules.fast = 0;
}
else
{
_gameRules.fast = (skillModePlusFastBit & 0x80) != 0;
}
}
else
#endif
{
_gameRules.fast = (skillModePlusFastBit & 0x80) != 0;
_gameRules.skill = skillmode_t( Reader_ReadByte(reader) & 0x7f );

// Interpret skill levels outside the normal range as "spawn no things".
if(_gameRules.skill < SM_BABY || _gameRules.skill >= NUM_SKILL_MODES)
_gameRules.skill = SM_NOTHINGS;
}
#endif

_episode = Reader_ReadByte(reader);
_map = Reader_ReadByte(reader);
_episode = Reader_ReadByte(reader) - 1;
_map = Reader_ReadByte(reader) - 1;

_gameRules.deathmatch = Reader_ReadByte(reader);
#if !__JHEXEN__
Expand Down
12 changes: 6 additions & 6 deletions doomsday/plugins/doom/src/p_oldsvg.cpp
Expand Up @@ -893,16 +893,16 @@ static void SaveInfo_Read_Dm_v19(SaveInfo *info, Reader *reader)
Reader_Read(reader, vcheck, VERSIONSIZE);
//DENG_ASSERT(!strncmp(vcheck, "version ", 8)); // Ensure save state format has been recognised by now.

info->_version = atoi(&vcheck[8]);
info->_version = atoi(&vcheck[8]);

info->_gameRules.skill = (skillmode_t) Reader_ReadByte(reader);

// Interpret skill levels outside the normal range as "spawn no things".
if(info->_gameRules.skill < SM_BABY || info->_gameRules.skill >= NUM_SKILL_MODES)
info->_gameRules.skill = SM_NOTHINGS;

info->_episode = Reader_ReadByte(reader);
info->_map = Reader_ReadByte(reader);
info->_episode = Reader_ReadByte(reader) - 1;
info->_map = Reader_ReadByte(reader) - 1;

for(int i = 0; i < 4; ++i)
{
Expand All @@ -915,12 +915,12 @@ static void SaveInfo_Read_Dm_v19(SaveInfo *info, Reader *reader)
int a = Reader_ReadByte(reader);
int b = Reader_ReadByte(reader);
int c = Reader_ReadByte(reader);
info->_mapTime = (a << 16) + (b << 8) + c;
info->_mapTime = (a << 16) + (b << 8) + c;

info->_magic = 0; // Initialize with *something*.
info->_magic = 0; // Initialize with *something*.

/// @note Older formats do not contain all needed values:
info->_gameMode = gameMode; // Assume the current mode.
info->_gameMode = gameMode; // Assume the current mode.

info->_gameRules.deathmatch = 0;
info->_gameRules.noMonsters = 0;
Expand Down
12 changes: 6 additions & 6 deletions doomsday/plugins/heretic/src/p_oldsvg.cpp
Expand Up @@ -901,16 +901,16 @@ static void SaveInfo_Read_Hr_v13(SaveInfo *info, Reader *reader)
char vcheck[VERSIONSIZE];
Reader_Read(reader, vcheck, VERSIONSIZE);
//DENG_ASSERT(!strncmp(vcheck, "version ", 8)); // Ensure save state format has been recognised by now.
info->_version = atoi(&vcheck[8]);
info->_version = atoi(&vcheck[8]);

info->_gameRules.skill = (skillmode_t) Reader_ReadByte(reader);

// Interpret skill levels outside the normal range as "spawn no things".
if(info->_gameRules.skill < SM_BABY || info->_gameRules.skill >= NUM_SKILL_MODES)
info->_gameRules.skill = SM_NOTHINGS;

info->_episode = Reader_ReadByte(reader);
info->_map = Reader_ReadByte(reader);
info->_episode = Reader_ReadByte(reader) - 1;
info->_map = Reader_ReadByte(reader) - 1;
for(int i = 0; i < 4; ++i)
{
info->_players[i] = Reader_ReadByte(reader);
Expand All @@ -921,12 +921,12 @@ static void SaveInfo_Read_Hr_v13(SaveInfo *info, Reader *reader)
int a = Reader_ReadByte(reader);
int b = Reader_ReadByte(reader);
int c = Reader_ReadByte(reader);
info->_mapTime = (a << 16) + (b << 8) + c;
info->_mapTime = (a << 16) + (b << 8) + c;

info->_magic = 0; // Initialize with *something*.
info->_magic = 0; // Initialize with *something*.

/// @note Older formats do not contain all needed values:
info->_gameMode = gameMode; // Assume the current mode.
info->_gameMode = gameMode; // Assume the current mode.

info->_gameRules.deathmatch = 0;
info->_gameRules.noMonsters = 0;
Expand Down

0 comments on commit 31f8419

Please sign in to comment.