From 03a0b1feb2ce24191e026598a0faef98db7ef3b5 Mon Sep 17 00:00:00 2001 From: Misa Date: Thu, 1 Apr 2021 15:24:14 -0700 Subject: [PATCH] Call VVV_exit() when SDL_QUIT is received MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a regression introduced by #535 where a quit signal (e.g. Ctrl-C) sent to the window while the game was in unfocus pause wouldn't close the game. One problem was that key.quitProgram would only be checked when control flow switched back to the outer loop in main(), which would only happen when the loop order state machine switched to a delta function. As the unfocused func table didn't have any delta functions, this means key.quitProgram would never be checked. So a naïve solution to this would just be to add a no-op delta func entry to the unfocused func table. However, we then run into a separate issue where a delta function at the end of a func list never reassigns the active funcs, causing the game to be stuck in the unfocus pause forever. Active func reassignment only happens after fixed funcs. So then a naïve solution after that would be to simply add a no-op fixed func entry after that. And indeed, that would fix the whole issue. However, I want to do things the right way. And this does not seem like the right way. Even putting aside the separate last-func-being-delta issue, it mandates that every func list needs a delta function. Which seems quite unnecessary to me. Another solution I considered was copy-pasting the key.quitProgram check to the inner loops, or adding some sort of signal propagation to the inner loops - implemented by copy-pasting checks after each loop - so we didn't need to copy-paste key.quitProgram... but that seems really messy, too. So, I realized that we could throw away key.quitProgram, and simply call VVV_exit() directly when we receive an SDL_QUIT event. This fixes the issue, this removes an unnecessary middleman variable, and it's pretty cleanly and simply the right thing to do. --- desktop_version/src/KeyPoll.cpp | 4 ++-- desktop_version/src/KeyPoll.h | 1 - desktop_version/src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index c6cdb4e5..697ca615 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -5,6 +5,7 @@ #include #include +#include "Exit.h" #include "Game.h" #include "Graphics.h" #include "Music.h" @@ -36,7 +37,6 @@ KeyPoll::KeyPoll(void) // 0..5 sensitivity = 2; - quitProgram = 0; keybuffer=""; leftbutton=0; rightbutton=0; middlebutton=0; mx=0; my=0; @@ -339,7 +339,7 @@ void KeyPoll::Poll(void) /* Quit Event */ case SDL_QUIT: - quitProgram = true; + VVV_exit(0); break; } } diff --git a/desktop_version/src/KeyPoll.h b/desktop_version/src/KeyPoll.h index 9635aa3b..2c5c7532 100644 --- a/desktop_version/src/KeyPoll.h +++ b/desktop_version/src/KeyPoll.h @@ -37,7 +37,6 @@ public: bool resetWindow; - bool quitProgram; void toggleFullscreen(void); int sensitivity; diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 9727c52f..1d99f5c2 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -615,7 +615,7 @@ int main(int argc, char *argv[]) gamestate_funcs = get_gamestate_funcs(game.gamestate, &num_gamestate_funcs); loop_assign_active_funcs(); - while(!key.quitProgram) + while (true) { f_time = SDL_GetTicks();