Skip to content

Commit

Permalink
libcommon|Added: Cvar "game-pause-focuslost" (default:1)
Browse files Browse the repository at this point in the history
Automatically pause the game when game window loses focus.
  • Loading branch information
skyjake committed Apr 1, 2012
1 parent 7c7a2be commit 73b2591
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
7 changes: 7 additions & 0 deletions doomsday/engine/data/cphelp.txt
Expand Up @@ -1181,3 +1181,10 @@ desc = 1=Default to fullscreen.

[vid-bpp]
desc = Default color depth (bits per pixel), 16 or 32.

#
# CONSOLE VARIABLES: libcommon
#

[game-pause-focuslost]
desc = Pause the game when game window loses focus.
32 changes: 26 additions & 6 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -262,6 +262,8 @@ int gsvAmmo[NUM_AMMO_TYPES];

char *gsvMapName = NOTAMAPNAME;

int gamePauseWhenFocusLost;

#if __JHERETIC__ || __JHEXEN__ || __JDOOM64__
int gsvInvItems[NUM_INVENTORYITEM_TYPES];
#endif
Expand All @@ -278,6 +280,8 @@ cvartemplate_t gamestatusCVars[] = {
{"game-paused", READONLYCVAR, CVT_INT, &paused, 0, 0},
{"game-skill", READONLYCVAR, CVT_INT, &gameSkill, 0, 0},

{"game-pause-focuslost", 0, CVT_INT, &gamePauseWhenFocusLost, 0, 1},

{"map-id", READONLYCVAR, CVT_INT, &gameMap, 0, 0},
{"map-name", READONLYCVAR, CVT_CHARPTR, &gsvMapName, 0, 0},
{"map-episode", READONLYCVAR, CVT_INT, &gameEpisode, 0, 0},
Expand Down Expand Up @@ -445,6 +449,9 @@ void G_Register(void)
{
int i;

// Default values (overridden by values from .cfg files).
gamePauseWhenFocusLost = true;

for(i = 0; gamestatusCVars[i].path; ++i)
Con_AddVariable(gamestatusCVars + i);

Expand Down Expand Up @@ -1310,14 +1317,27 @@ int G_Responder(event_t* ev)
// Eat all events once shutdown has begun.
if(G_QuitInProgress()) return true;

// With the menu active, none of these should respond to input events.
if(G_GameState() == GS_MAP && !Hu_MenuIsActive() && !Hu_IsMessageActive())
if(G_GameState() == GS_MAP)
{
if(ST_Responder(ev))
return true;
if(ev->type == EV_FOCUS)
{
if(gamePauseWhenFocusLost)
{
// Pause when focus lost.
G_SetPause(!ev->data1);
}
return false; // others might be interested
}

if(G_EventSequenceResponder(ev))
return true;
// With the menu active, none of these should respond to input events.
if(!Hu_MenuIsActive() && !Hu_IsMessageActive())
{
if(ST_Responder(ev))
return true;

if(G_EventSequenceResponder(ev))
return true;
}
}

return Hu_MenuResponder(ev);
Expand Down

0 comments on commit 73b2591

Please sign in to comment.