Skip to content

Commit

Permalink
libcommon: Remember the GameRuleset post game init as the "default" set
Browse files Browse the repository at this point in the history
Rather than using the game rules of the current game session as a
"staging area", it is better to record rulesets separately, to be
applied as a unit.
  • Loading branch information
danij-deng committed Apr 11, 2014
1 parent f435d64 commit dfbec42
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 42 deletions.
2 changes: 2 additions & 0 deletions doomsday/plugins/common/include/g_common.h
Expand Up @@ -68,6 +68,8 @@ void G_SetGameAction(gameaction_t action);
#if __cplusplus
} // extern "C"

extern GameRuleset defaultGameRules;

/**
* Schedule a new game session (deferred).
*
Expand Down
29 changes: 17 additions & 12 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -73,6 +73,8 @@ using namespace common;

static GameSession session;

GameRuleset defaultGameRules;

#define BODYQUEUESIZE (32)

#define READONLYCVAR CVF_READ_ONLY|CVF_NO_MAX|CVF_NO_MIN|CVF_NO_ARCHIVE
Expand Down Expand Up @@ -144,6 +146,10 @@ wbstartstruct_t wmInfo; // Params for world map / intermission.
#endif

// Game Action Variables:
static uint gaNewSessionMapEntrance;
static Uri *gaNewSessionMapUri; ///< @todo fixme: Never free'd
static GameRuleset gaNewSessionRules;

static de::String gaSaveSessionSlot;
static bool gaSaveSessionGenerateDescription = true;
static de::String gaSaveSessionUserDescription;
Expand Down Expand Up @@ -355,11 +361,6 @@ ccmdtemplate_t gameCmds[] = {
{ "", "", 0, 0 }
};

// Deferred new game arguments:
static uint dMapEntrance;
static Uri *dMapUri; ///< @todo fixme: Never free'd
static GameRuleset dRules;

static gameaction_t gameAction;
static dd_bool quitInProgress;

Expand Down Expand Up @@ -414,13 +415,13 @@ void G_SetGameAction(gameaction_t newAction)

void G_SetGameActionNewSession(Uri const &mapUri, uint mapEntrance, GameRuleset const &rules)
{
if(!dMapUri)
if(!gaNewSessionMapUri)
{
dMapUri = Uri_New();
gaNewSessionMapUri = Uri_New();
}
Uri_Copy(dMapUri, &mapUri);
dMapEntrance = mapEntrance;
dRules = rules; // make a copy.
Uri_Copy(gaNewSessionMapUri, &mapUri);
gaNewSessionMapEntrance = mapEntrance;
gaNewSessionRules = rules; // make a copy.

G_SetGameAction(GA_NEWSESSION);
}
Expand Down Expand Up @@ -554,6 +555,9 @@ void G_CommonPreInit()
// Clear the game rules for the current session to their default values.
COMMON_GAMESESSION->rules() = GameRuleset();

// Clear the default game rules also.
defaultGameRules = GameRuleset();

if(!gameMapUri)
{
gameMapUri = Uri_New();
Expand Down Expand Up @@ -1487,7 +1491,8 @@ static void runGameAction()
{
case GA_NEWSESSION:
COMMON_GAMESESSION->end();
COMMON_GAMESESSION->begin(*dMapUri, dMapEntrance, dRules);
COMMON_GAMESESSION->begin(*gaNewSessionMapUri, gaNewSessionMapEntrance,
gaNewSessionRules);
break;

case GA_LOADSESSION:
Expand Down Expand Up @@ -3391,7 +3396,7 @@ D_CMD(WarpMap)
}
else
{
G_SetGameActionNewSession(*newMapUri, 0/*default*/, COMMON_GAMESESSION->rules());
G_SetGameActionNewSession(*newMapUri, 0/*default*/, defaultGameRules);
}

// If the command source was "us" the game library then it was probably in
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -6443,7 +6443,7 @@ void Hu_MenuInitNewGame(dd_bool confirmed)
cfg.playerClass[CONSOLEPLAYER] = playerclass_t(mnPlrClass);
#endif

GameRuleset newRules(COMMON_GAMESESSION->rules());
GameRuleset newRules(defaultGameRules);
newRules.skill = mnSkillmode;

#if __JHEXEN__
Expand Down
16 changes: 8 additions & 8 deletions doomsday/plugins/doom/src/d_main.cpp
Expand Up @@ -409,20 +409,20 @@ void D_PostInit()
monsterInfight = GetDefInt("AI|Infight", 0);

// Get skill / episode / map from parms.
COMMON_GAMESESSION->rules().skill = /*startSkill =*/ SM_MEDIUM;
defaultGameRules.skill = /*startSkill =*/ SM_MEDIUM;

if(CommandLine_Check("-altdeath"))
cfg.netDeathmatch = 2;
else if(CommandLine_Check("-deathmatch"))
cfg.netDeathmatch = 1;

// Apply these rules.
COMMON_GAMESESSION->rules().noMonsters = CommandLine_Check("-nomonsters")? true : false;
COMMON_GAMESESSION->rules().respawnMonsters = CommandLine_Check("-respawn")? true : false;
COMMON_GAMESESSION->rules().fast = CommandLine_Check("-fast")? true : false;
defaultGameRules.noMonsters = CommandLine_Check("-nomonsters")? true : false;
defaultGameRules.respawnMonsters = CommandLine_Check("-respawn")? true : false;
defaultGameRules.fast = CommandLine_Check("-fast")? true : false;

int p = CommandLine_Check("-timer");
if(p && p < myargc - 1 && COMMON_GAMESESSION->rules().deathmatch)
if(p && p < myargc - 1 && defaultGameRules.deathmatch)
{
int time = atoi(CommandLine_At(p + 1));
App_Log(DE2_LOG_NOTE, "Maps will end after %d %s", time, time == 1? "minute" : "minutes");
Expand Down Expand Up @@ -464,7 +464,7 @@ void D_PostInit()
if(p && p < myargc - 1)
{
int skillNumber = atoi(CommandLine_At(p + 1));
COMMON_GAMESESSION->rules().skill = (skillmode_t)(skillNumber > 0? skillNumber - 1 : skillNumber);
defaultGameRules.skill = (skillmode_t)(skillNumber > 0? skillNumber - 1 : skillNumber);
autoStart = true;
}

Expand Down Expand Up @@ -508,14 +508,14 @@ void D_PostInit()
{
App_Log(DE2_LOG_NOTE, "Autostart in Map %s, Skill %d",
F_PrettyPath(Str_Text(Uri_ToString(startMapUri))),
COMMON_GAMESESSION->rules().skill);
defaultGameRules.skill);
}

// Validate episode and map.
AutoStr *path = Uri_Compose(startMapUri);
if((autoStart || IS_NETGAME) && P_MapExists(Str_Text(path)))
{
G_SetGameActionNewSession(*startMapUri, 0/*default*/, COMMON_GAMESESSION->rules());
G_SetGameActionNewSession(*startMapUri, 0/*default*/, defaultGameRules);
}
else
{
Expand Down
16 changes: 8 additions & 8 deletions doomsday/plugins/doom64/src/d_main.cpp
Expand Up @@ -315,7 +315,7 @@ void D_PostInit()
monsterInfight = GetDefInt("AI|Infight", 0);

// Get skill / episode / map from parms.
COMMON_GAMESESSION->rules().skill = /*startSkill =*/ SM_MEDIUM;
defaultGameRules.skill = /*startSkill =*/ SM_MEDIUM;

// Game mode specific settings
// None.
Expand All @@ -326,12 +326,12 @@ void D_PostInit()
cfg.netDeathmatch = 1;

// Apply these rules.
COMMON_GAMESESSION->rules().noMonsters = CommandLine_Check("-nomonsters")? true : false;
COMMON_GAMESESSION->rules().respawnMonsters = CommandLine_Check("-respawn")? true : false;
COMMON_GAMESESSION->rules().fast = CommandLine_Check("-fast")? true : false;
defaultGameRules.noMonsters = CommandLine_Check("-nomonsters")? true : false;
defaultGameRules.respawnMonsters = CommandLine_Check("-respawn")? true : false;
defaultGameRules.fast = CommandLine_Check("-fast")? true : false;

int p = CommandLine_Check("-timer");
if(p && p < myargc - 1 && COMMON_GAMESESSION->rules().deathmatch)
if(p && p < myargc - 1 && defaultGameRules.deathmatch)
{
int time = atoi(CommandLine_At(p + 1));
App_Log(DE2_LOG_NOTE, "Maps will end after %d %s", time, time == 1? "minute" : "minutes");
Expand Down Expand Up @@ -373,7 +373,7 @@ void D_PostInit()
if(p && p < myargc - 1)
{
int skillNumber = atoi(CommandLine_At(p + 1));
COMMON_GAMESESSION->rules().skill = (skillmode_t)(skillNumber > 0? skillNumber - 1 : skillNumber);
defaultGameRules.skill = (skillmode_t)(skillNumber > 0? skillNumber - 1 : skillNumber);
autoStart = true;
}

Expand All @@ -396,14 +396,14 @@ void D_PostInit()
{
App_Log(DE2_LOG_NOTE, "Autostart in Map %s, Skill %d",
F_PrettyPath(Str_Text(Uri_ToString(startMapUri))),
COMMON_GAMESESSION->rules().skill);
defaultGameRules.skill);
}

// Validate episode and map.
AutoStr *path = Uri_Compose(startMapUri);
if((autoStart || IS_NETGAME) && P_MapExists(Str_Text(path)))
{
G_SetGameActionNewSession(*startMapUri, 0/*default*/, COMMON_GAMESESSION->rules());
G_SetGameActionNewSession(*startMapUri, 0/*default*/, defaultGameRules);
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions doomsday/plugins/heretic/src/h_main.cpp
Expand Up @@ -342,7 +342,7 @@ void H_PostInit()
monsterInfight = GetDefInt("AI|Infight", 0);

// Defaults for skill, episode and map.
COMMON_GAMESESSION->rules().skill = /*startSkill =*/ SM_MEDIUM;
defaultGameRules.skill = /*startSkill =*/ SM_MEDIUM;

// Game mode specific settings.
/* None */
Expand All @@ -353,8 +353,8 @@ void H_PostInit()
}

// Apply these game rules.
COMMON_GAMESESSION->rules().noMonsters = CommandLine_Exists("-nomonsters")? true : false;
COMMON_GAMESESSION->rules().respawnMonsters = CommandLine_Check("-respawn")? true : false;
defaultGameRules.noMonsters = CommandLine_Exists("-nomonsters")? true : false;
defaultGameRules.respawnMonsters = CommandLine_Check("-respawn")? true : false;

// turbo option.
int p = CommandLine_Check("-turbo");
Expand Down Expand Up @@ -392,7 +392,7 @@ void H_PostInit()
if(p && p < myargc - 1)
{
int skillNumber = atoi(CommandLine_At(p + 1));
COMMON_GAMESESSION->rules().skill = (skillmode_t)(skillNumber > 0? skillNumber - 1 : skillNumber);
defaultGameRules.skill = (skillmode_t)(skillNumber > 0? skillNumber - 1 : skillNumber);
autoStart = true;
}

Expand Down Expand Up @@ -426,14 +426,14 @@ void H_PostInit()
{
App_Log(DE2_LOG_NOTE, "Autostart in Map %s, Skill %d",
F_PrettyPath(Str_Text(Uri_ToString(startMapUri))),
COMMON_GAMESESSION->rules().skill);
defaultGameRules.skill);
}

// Validate episode and map.
AutoStr *path = Uri_Compose(startMapUri);
if((autoStart || IS_NETGAME) && P_MapExists(Str_Text(path)))
{
G_SetGameActionNewSession(*startMapUri, 0/*default*/, COMMON_GAMESESSION->rules());
G_SetGameActionNewSession(*startMapUri, 0/*default*/, defaultGameRules);
}
else
{
Expand Down
13 changes: 6 additions & 7 deletions doomsday/plugins/hexen/src/h2_main.cpp
Expand Up @@ -312,16 +312,15 @@ void X_PostInit()
/* None */

// Defaults for skill, episode and map.
COMMON_GAMESESSION->rules().skill = /*startSkill =*/ SM_MEDIUM;
defaultGameRules.skill = /*startSkill =*/ SM_MEDIUM;

// Game mode specific settings.
/* None */

cfg.netDeathmatch = CommandLine_Exists("-deathmatch");

// Apply these rules.
COMMON_GAMESESSION->rules().noMonsters = CommandLine_Check("-nomonsters")? true : false;
COMMON_GAMESESSION->rules().randomClasses = CommandLine_Exists("-randclass")? true : false;
defaultGameRules.noMonsters = CommandLine_Check("-nomonsters")? true : false;
defaultGameRules.randomClasses = CommandLine_Exists("-randclass")? true : false;

// Turbo movement option.
int p = CommandLine_Check("-turbo");
Expand Down Expand Up @@ -371,7 +370,7 @@ void X_PostInit()
if((p = CommandLine_CheckWith("-skill", 1)) != 0)
{
int skillNumber = atoi(CommandLine_At(p + 1));
COMMON_GAMESESSION->rules().skill = (skillmode_t)(skillNumber > 0? skillNumber - 1 : skillNumber);
defaultGameRules.skill = (skillmode_t)(skillNumber > 0? skillNumber - 1 : skillNumber);
autoStart = true;
}

Expand Down Expand Up @@ -419,14 +418,14 @@ void X_PostInit()
{
App_Log(DE2_LOG_NOTE, "Autostart in Map %s, Skill %d",
F_PrettyPath(Str_Text(Uri_ToString(startMapUri))),
COMMON_GAMESESSION->rules().skill);
defaultGameRules.skill);
}

// Validate episode and map.
AutoStr *path = Uri_Compose(startMapUri);
if((autoStart || IS_NETGAME) && P_MapExists(Str_Text(path)))
{
G_SetGameActionNewSession(*startMapUri, 0/*default*/, COMMON_GAMESESSION->rules());
G_SetGameActionNewSession(*startMapUri, 0/*default*/, defaultGameRules);
}
else
{
Expand Down

0 comments on commit dfbec42

Please sign in to comment.