Skip to content

Commit f31c6dc

Browse files
committed
Pause controlled through option 'pauseInactive'.
When the option is set an inactive window (lost focus, minimized or hidden) will keep the game paused (no logic or graphics updates). When the option is unset (the default), the game will continue to run as normal even when it has no focus. It will merely slow down when it becomes minimized.
1 parent 8552e9e commit f31c6dc

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎src/Engine/Game.cpp‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Game::~Game()
162162
*/
163163
void Game::run()
164164
{
165-
enum ApplicationState { RUNNING = 0, PAUSED } runningState = RUNNING;
165+
enum ApplicationState { RUNNING = 0, SLOWED = 1, PAUSED = 2 } runningState = RUNNING;
166166
while (!_quit)
167167
{
168168
// Clean up states
@@ -202,9 +202,14 @@ void Game::run()
202202
switch (reinterpret_cast<SDL_ActiveEvent*>(&_event)->state)
203203
{
204204
case SDL_APPACTIVE:
205+
runningState =
206+
Options::getBool("pauseInactive") ? PAUSED : SLOWED;
207+
runningState = reinterpret_cast<SDL_ActiveEvent*>(&_event)->gain ? RUNNING : runningState;
208+
break;
205209
case SDL_APPMOUSEFOCUS:
206210
case SDL_APPINPUTFOCUS:
207-
runningState = reinterpret_cast<SDL_ActiveEvent*>(&_event)->gain ? RUNNING : PAUSED;
211+
runningState = Options::getBool("pauseInactive") ? PAUSED : RUNNING;
212+
runningState = reinterpret_cast<SDL_ActiveEvent*>(&_event)->gain ? RUNNING : runningState;
208213
break;
209214
}
210215
break;
@@ -255,7 +260,8 @@ void Game::run()
255260
switch (runningState)
256261
{
257262
case RUNNING: SDL_Delay(1); break; //Save CPU from going 100%
258-
case PAUSED: SDL_Delay(100); break; //More slowing down.
263+
case SLOWED: case PAUSED:
264+
SDL_Delay(100); break; //More slowing down.
259265
}
260266
}
261267
}

‎src/Engine/Options.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void createDefault()
8181
setBool("globeSeasons", false);
8282
setInt("audioSampleRate", 22050);
8383
setInt("audioBitDepth", 16);
84+
setBool("pauseInactive", false);
8485

8586
_rulesets.push_back("Xcom1Ruleset");
8687
}

0 commit comments

Comments
 (0)