Skip to content

Commit

Permalink
Merge pull request #77651 from andrei8l/are-ya-quitting-son
Browse files Browse the repository at this point in the history
input: fix no-op input loop when quitting
  • Loading branch information
Maleclypse authored Nov 10, 2024
2 parents 5fd7937 + 77df2be commit f3850e2
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/do_turn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
7 changes: 6 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 );
}
2 changes: 2 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>( "ANIMATION_RAIN" ) ) {
Expand Down Expand Up @@ -3118,7 +3118,7 @@ bool game::handle_action()
// of location clicked.
std::optional<tripoint_bub_ms> mouse_target;

if( uquit == QUIT_EXIT ) {
if( are_we_quitting() ) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/input_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ bool main_menu::opening_screen()
#endif

while( !start ) {
if( g->uquit == QUIT_EXIT ) {
if( are_we_quitting() ) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f3850e2

Please sign in to comment.