Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libcommon|Cleanup: Handling focus event to (un)pause
Fewer globals == good.
  • Loading branch information
skyjake committed Mar 24, 2013
1 parent 00534a1 commit c5bd86d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
12 changes: 9 additions & 3 deletions doomsday/plugins/common/include/pause.h
Expand Up @@ -28,9 +28,6 @@
/// Non-zero when the game is paused: game time is not advancing.
DENG_EXTERN_C int paused;

DENG_EXTERN_C int gamePauseWhenFocusLost;
DENG_EXTERN_C int gameUnpauseWhenFocusGained;

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -44,6 +41,15 @@ void Pause_Register(void);
*/
void Pause_Ticker(void);

/**
* Process events related to pausing.
*
* @param ev Event.
*
* @return @c true, if the event was processed.
*/
boolean Pause_Responder(event_t *ev);

/**
* Determines if the game is currently paused.
*/
Expand Down
13 changes: 1 addition & 12 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -1369,18 +1369,7 @@ int G_Responder(event_t* ev)

if(G_GameState() == GS_MAP)
{
if(ev->type == EV_FOCUS)
{
if(gamePauseWhenFocusLost && !ev->data1)
{
Pause_Set(true);
}
else if(gameUnpauseWhenFocusGained && ev->data1)
{
Pause_Set(false);
}
return false; // others might be interested
}
Pause_Responder(ev);

// With the menu active, none of these should respond to input events.
if(!Hu_MenuIsActive() && !Hu_IsMessageActive())
Expand Down
27 changes: 23 additions & 4 deletions doomsday/plugins/common/src/pause.c
Expand Up @@ -34,16 +34,17 @@
#define READONLYCVAR (CVF_READ_ONLY|CVF_NO_MAX|CVF_NO_MIN|CVF_NO_ARCHIVE)

int paused = 0;
int gamePauseWhenFocusLost;
int gameUnpauseWhenFocusGained;

static int gamePauseWhenFocusLost; // cvar
static int gameUnpauseWhenFocusGained; // cvar

#ifdef __JDOOM__
/// How long to pause the game after a map has been loaded (cvar).
/// - -1: matches the engine's busy transition tics.
static int gamePauseAfterMapStartTics = -1;
static int gamePauseAfterMapStartTics = -1; // cvar
#else
// Crossfade doesn't require a very long pause.
static int gamePauseAfterMapStartTics = 7;
static int gamePauseAfterMapStartTics = 7; // cvar
#endif

static int forcedPeriodTicsRemaining;
Expand Down Expand Up @@ -160,6 +161,24 @@ void Pause_Ticker(void)
checkForcedPeriod();
}

boolean Pause_Responder(event_t *ev)
{
if(ev->type == EV_FOCUS)
{
if(gamePauseWhenFocusLost && !ev->data1)
{
Pause_Set(true);
return true;
}
else if(gameUnpauseWhenFocusGained && ev->data1)
{
Pause_Set(false);
return true;
}
}
return false;
}

void Pause_MapStarted(void)
{
if(!IS_CLIENT)
Expand Down

0 comments on commit c5bd86d

Please sign in to comment.