diff --git a/src/main.c b/src/main.c index 43e6e06..e6ebed4 100644 --- a/src/main.c +++ b/src/main.c @@ -148,6 +148,15 @@ int main(int argc, char** argv) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) quit = 1; // Handle quit. + // Pause the game if it is unfocused. + if(event.type == SDL_ACTIVEEVENT) { + if(event.active.state != SDL_APPMOUSEFOCUS) { + // We don't need the mouse focus. + if((event.active.gain == 0) && !paused) pause(); + else if((event.active.gain == 1) && paused) unpause(); + } + } + input_handle(&event); // handles all the events the player keybinds. } @@ -192,6 +201,8 @@ static void fps_control(void) { // dt in ms/1000. dt = (double)(SDL_GetTicks() - gtime) / 1000.; gtime = SDL_GetTicks(); + + if(paused) SDL_Delay(10); // Drop paused FPS to be nice to the CPU. // If the fps is limited.. if((max_fps != 0) && (dt < 1./max_fps)) {