From 77df2bedf6f0ded06447e2725e992afa412cbb44 Mon Sep 17 00:00:00 2001 From: andrei Date: Thu, 7 Nov 2024 15:59:05 +0200 Subject: [PATCH] input: fix no-op input loop when quitting --- src/debug.cpp | 2 +- src/do_turn.cpp | 2 +- src/game.cpp | 7 ++++++- src/game.h | 2 ++ src/handle_action.cpp | 4 ++-- src/input_context.cpp | 1 + src/main_menu.cpp | 2 +- src/ui.cpp | 2 +- 8 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index b463b5e1ec837..9ce27abf1e393 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -386,7 +386,7 @@ static void debug_error_prompt( inp_mngr.set_timeout( 50 ); input_event ievent = inp_mngr.get_input_event(); if( ievent.type == input_event_t::timeout ) { - if( g && g->uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { g->query_exit_to_OS(); } continue; diff --git a/src/do_turn.cpp b/src/do_turn.cpp index e6022764b54a7..a017882f17f2c 100644 --- a/src/do_turn.cpp +++ b/src/do_turn.cpp @@ -103,7 +103,7 @@ namespace turn_handler bool cleanup_at_end() { avatar &u = get_avatar(); - if( g->uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { return true; } if( g->uquit == QUIT_DIED || g->uquit == QUIT_SUICIDE ) { diff --git a/src/game.cpp b/src/game.cpp index cc9316af9c103..fa5cf18088bec 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2818,7 +2818,7 @@ bool game::query_exit_to_OS() bool game::is_game_over() { - if( uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { return query_exit_to_OS(); } if( uquit == QUIT_DIED || uquit == QUIT_WATCH ) { @@ -14009,3 +14009,8 @@ global_variables &get_globals() { return g->global_variables_instance; } + +bool are_we_quitting() +{ + return g && ( g->uquit == QUIT_EXIT || g->uquit == QUIT_EXIT_PENDING ); +} diff --git a/src/game.h b/src/game.h index 54af2ea866a01..ddd7078c9a681 100644 --- a/src/game.h +++ b/src/game.h @@ -1347,4 +1347,6 @@ namespace cata_event_dispatch void avatar_moves( const tripoint &old_abs_pos, const avatar &u, const map &m ); } // namespace cata_event_dispatch +bool are_we_quitting(); + #endif // CATA_SRC_GAME_H diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 5876255e5dcca..9eaa834539ce1 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -334,7 +334,7 @@ input_context game::get_player_input( std::string &action ) creature_tracker &creatures = get_creature_tracker(); do { - if( g->uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { break; } if( bWeatherEffect && get_option( "ANIMATION_RAIN" ) ) { @@ -3117,7 +3117,7 @@ bool game::handle_action() // of location clicked. std::optional mouse_target; - if( uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { return false; } diff --git a/src/input_context.cpp b/src/input_context.cpp index 3bf40e2704bae..ca46cf9f47f71 100644 --- a/src/input_context.cpp +++ b/src/input_context.cpp @@ -447,6 +447,7 @@ const std::string &input_context::handle_input( const int timeout ) } if( g->uquit == QUIT_EXIT ) { + g->uquit = QUIT_EXIT_PENDING; result = &QUIT; break; } diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 638108901af2a..67aa0b41cefbe 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -707,7 +707,7 @@ bool main_menu::opening_screen() #endif while( !start ) { - if( g->uquit == QUIT_EXIT ) { + if( are_we_quitting() ) { return false; } diff --git a/src/ui.cpp b/src/ui.cpp index e2bab96796d51..81daf214fa376 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1044,7 +1044,7 @@ void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys ) ret = entries[selected].retval; } } else if( ( allow_cancel && ret_act == "UILIST.QUIT" ) || - ( g->uquit == QUIT_EXIT && ret_act == "QUIT" ) ) { + ( are_we_quitting() && ret_act == "QUIT" ) ) { ret = UILIST_CANCEL; } else if( ret_act == "TIMEOUT" ) { ret = UILIST_WAIT_INPUT;