From 7ed635efd69082ffdc5bdd8b86dcdb5fc2c0ac8c Mon Sep 17 00:00:00 2001 From: John Collins Date: Thu, 20 Aug 2020 00:03:46 -0500 Subject: [PATCH 1/2] Added pause on focus lost (SDL1 and SDL2 only) --- src/game/level_update.c | 7 +++++-- src/pc/gfx/gfx_sdl1.c | 8 +++++++- src/pc/gfx/gfx_sdl2.c | 8 +++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/game/level_update.c b/src/game/level_update.c index 72a6a6073..10fa61b0e 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -30,6 +30,7 @@ #include "course_table.h" #include "thread6.h" #include "../../include/libc/stdlib.h" +#include "print.h" #include "pc/pc_main.h" #include "pc/cliopts.h" @@ -154,7 +155,7 @@ struct CreditsEntry sCreditsSequence[] = { { LEVEL_CASTLE_GROUNDS, 1, 1, -128, { 0, 906, -1200 }, NULL }, { LEVEL_NONE, 0, 1, 0, { 0, 0, 0 }, NULL }, }; - +extern bool focus_Lost; struct MarioState gMarioStates[1]; struct HudDisplay gHudDisplay; s16 sCurrPlayMode; @@ -961,6 +962,7 @@ void basic_update(UNUSED s16 *arg) { int gPressedStart = 0; s32 play_mode_normal(void) { + if (gCurrDemoInput != NULL) { print_intro_text(); if (gPlayer1Controller->buttonPressed & END_DEMO) { @@ -997,11 +999,12 @@ s32 play_mode_normal(void) { set_play_mode(PLAY_MODE_CHANGE_LEVEL); } else if (sTransitionTimer != 0) { set_play_mode(PLAY_MODE_CHANGE_AREA); - } else if (pressed_pause()) { + } else if (pressed_pause() || focus_Lost) { lower_background_noise(1); cancel_rumble(); gCameraMovementFlags |= CAM_MOVE_PAUSE_SCREEN; set_play_mode(PLAY_MODE_PAUSED); + focus_Lost = FALSE; } } diff --git a/src/pc/gfx/gfx_sdl1.c b/src/pc/gfx/gfx_sdl1.c index e8c6fa4e9..0089979de 100644 --- a/src/pc/gfx/gfx_sdl1.c +++ b/src/pc/gfx/gfx_sdl1.c @@ -26,7 +26,7 @@ #else # define FRAMERATE 30 #endif - +bool focus_Lost = FALSE; static int inverted_scancode_table[512]; static kb_callback_t kb_key_down = NULL; @@ -202,6 +202,11 @@ static void gfx_sdl_onkeyup(int scancode) { static void gfx_sdl_handle_events(void) { SDL_Event event; while (SDL_PollEvent(&event)) { + if (event.type.event = SDL_WINDOWEVENT_FOCUS_LOST) + { + focus_Lost = TRUE; + } + switch (event.type) { #ifndef TARGET_WEB // Scancodes are broken in Emscripten SDL2: https://bugzilla.libsdl.org/show_bug.cgi?id=3259 @@ -222,6 +227,7 @@ static void gfx_sdl_handle_events(void) { case SDL_QUIT: game_exit(); break; + } } } diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 4d907893a..84fc96e85 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -41,7 +41,7 @@ #else # define FRAMERATE 30 #endif - +bool focus_Lost = FALSE; static SDL_Window *wnd; static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; @@ -282,11 +282,13 @@ static void gfx_sdl_handle_events(void) { // Scancodes are broken in Emscripten SDL2: https://bugzilla.libsdl.org/show_bug.cgi?id=3259 case SDL_KEYDOWN: gfx_sdl_onkeydown(event.key.keysym.scancode); + break; case SDL_KEYUP: gfx_sdl_onkeyup(event.key.keysym.scancode); break; #endif + case SDL_WINDOWEVENT: // TODO: Check if this makes sense to be included in the Web build if (!IS_FULLSCREEN()) { switch (event.window.event) { @@ -300,12 +302,16 @@ static void gfx_sdl_handle_events(void) { configWindow.w = event.window.data1; configWindow.h = event.window.data2; break; + case SDL_WINDOWEVENT_FOCUS_LOST: + focus_Lost = TRUE; + break; } } break; case SDL_QUIT: game_exit(); break; + } } From 4be43a8d8eb3b3d5ff6164635c85691ec02f237f Mon Sep 17 00:00:00 2001 From: John Collins Date: Thu, 20 Aug 2020 00:11:51 -0500 Subject: [PATCH 2/2] Removed print.h include --- src/game/level_update.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/game/level_update.c b/src/game/level_update.c index 10fa61b0e..f0bcbe152 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -30,7 +30,6 @@ #include "course_table.h" #include "thread6.h" #include "../../include/libc/stdlib.h" -#include "print.h" #include "pc/pc_main.h" #include "pc/cliopts.h"