Skip to content

Commit

Permalink
Fixed|libcommon: Applied undefined game rules loading legacy savegame
Browse files Browse the repository at this point in the history
If the game plugin is not unloaded when the game mode changes then
the rules will be left in an undefined state prior to the new game
beginning. Although the game rules are always set when a new session
is begun. However, rather than beginning a new session, if a converted
legacy savegame is loaded which lacks a complete game ruleset then
the undefined game rules from the previous game session were applied
erroneously.

The game rules are explicitly cleared in G_CommonPreInit()
  • Loading branch information
danij-deng committed Apr 10, 2014
1 parent 260b746 commit 048322c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doomsday/plugins/common/include/gamesession.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class GameSession : public de::game::Session
/// Returns the singleton instance.
static GameSession &gameSession();

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

bool hasBegun();
bool savingPossible();
bool loadingPossible();
Expand Down
6 changes: 5 additions & 1 deletion doomsday/plugins/common/src/g_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ static gamestate_t gameState = GS_STARTUP;
cvartemplate_t gamestatusCVars[] =
{
{"game-music", READONLYCVAR, CVT_INT, &gsvCurrentMusic, 0, 0, 0},
//{"game-skill", READONLYCVAR, CVT_INT, &gameRules.skill, 0, 0, 0},
{"game-state", READONLYCVAR, CVT_INT, &gameState, 0, 0, 0},
{"game-state-map", READONLYCVAR, CVT_INT, &gsvInMap, 0, 0, 0},
#if !__JHEXEN__
Expand Down Expand Up @@ -366,6 +365,8 @@ static dd_bool quitInProgress;

void G_Register()
{
common::GameSession::consoleRegister();

for(int i = 0; gamestatusCVars[i].path[0]; ++i)
{
Con_AddVariable(gamestatusCVars + i);
Expand Down Expand Up @@ -550,6 +551,9 @@ static void initSaveSlots()
*/
void G_CommonPreInit()
{
// Clear the game rules for the current session to their default values.
COMMON_GAMESESSION->rules() = GameRuleset();

if(!gameMapUri)
{
gameMapUri = Uri_New();
Expand Down
9 changes: 9 additions & 0 deletions doomsday/plugins/common/src/gamesession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,4 +1102,13 @@ String GameSession::savedUserDescription(String const &saveName)
return ""; // Not found.
}

namespace {
int gsvRuleSkill;
}

void GameSession::consoleRegister() //static
{
C_VAR_INT("game-skill", &gsvRuleSkill, CVF_READ_ONLY|CVF_NO_MAX|CVF_NO_MIN|CVF_NO_ARCHIVE, 0, 0);
}

} // namespace common

0 comments on commit 048322c

Please sign in to comment.