Simplify SDL_QUIT handling
Remove the global `Quitting` and instead run the window close loop immediately upon receiving SDL_QUIT.
This commit is contained in:
parent
7a087702d0
commit
dfce7ed40d
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue