From dfce7ed40d30a8d76cc2804b8b74343f71390078 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 14 Jan 2023 19:05:37 +0000 Subject: [PATCH] Simplify SDL_QUIT handling Remove the global `Quitting` and instead run the window close loop immediately upon receiving SDL_QUIT. --- common/main/inferno.h | 1 - similar/main/inferno.cpp | 54 +++++++++++++++------------------------- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/common/main/inferno.h b/common/main/inferno.h index 70a5deda6..73adbe142 100644 --- a/common/main/inferno.h +++ b/common/main/inferno.h @@ -85,7 +85,6 @@ namespace dsx { ** Global variables **/ -extern int Quitting; extern int Screen_mode; // editor screen or game screen? #ifdef DXX_BUILD_DESCENT_I extern int MacHog; diff --git a/similar/main/inferno.cpp b/similar/main/inferno.cpp index 43cbd3629..f25ad8c7a 100644 --- a/similar/main/inferno.cpp +++ b/similar/main/inferno.cpp @@ -285,8 +285,6 @@ static void print_commandline_help() } -int Quitting = 0; - } namespace dcx { @@ -296,35 +294,6 @@ window_event_result standard_handler(const d_event &event) { int key; - if (Quitting) - { - window *wind = window_get_front(); - if (!wind) - return window_event_result::ignored; // finished quitting - - if (wind == Game_wind) - { - Quitting = 0; - const auto choice = nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_YES, TXT_NO), menu_subtitle{TXT_ABORT_GAME}); - if (choice != 0) - return window_event_result::handled; // aborted quitting - else - { - CGameArg.SysAutoDemo = false; - Quitting = 1; - } - } - - // Close front window, let the code flow continue until all windows closed or quit cancelled - if (!window_close(wind)) - { - Quitting = 0; - return window_event_result::handled; - } - - return window_event_result::deleted; // tell the event system we deleted some window - } - switch (event.type) { case EVENT_MOUSE_BUTTON_DOWN: @@ -401,11 +370,28 @@ window_event_result standard_handler(const d_event &event) case EVENT_QUIT: #if DXX_USE_EDITOR - if (SafetyCheck()) + if (!SafetyCheck()) + return window_event_result::handled; #endif - Quitting = 1; - return window_event_result::handled; + for (;;) + { + const auto wind = window_get_front(); + if (!wind) + return window_event_result::handled; // finished quitting + if (wind == Game_wind) + { + const auto choice = nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_YES, TXT_NO), menu_subtitle{TXT_ABORT_GAME}); + if (choice != 0) + return window_event_result::handled; // aborted quitting + else + CGameArg.SysAutoDemo = false; + } + + // Close front window, let the code flow continue until all windows closed or quit cancelled + if (!window_close(wind)) + return window_event_result::handled; + } default: break; }