From 616b746b9272481f45ef1432ffb395e504f5d298 Mon Sep 17 00:00:00 2001 From: Zhilkin Serg Date: Fri, 27 Dec 2024 16:32:19 +0300 Subject: [PATCH] Revert 75999 --- src/do_turn.cpp | 3 --- src/flexbuffer_json.cpp | 4 --- src/game.cpp | 19 --------------- src/game.h | 4 --- src/handle_action.cpp | 7 ------ src/init.cpp | 20 --------------- src/input_context.cpp | 5 ---- src/main.cpp | 54 +++++++++++++++++++++++------------------ src/main_menu.cpp | 9 ------- src/sdltiles.cpp | 5 ++-- src/ui.cpp | 3 +-- 11 files changed, 34 insertions(+), 99 deletions(-) diff --git a/src/do_turn.cpp b/src/do_turn.cpp index 4d9571ffdb7bd..1c77e02109790 100644 --- a/src/do_turn.cpp +++ b/src/do_turn.cpp @@ -103,9 +103,6 @@ namespace turn_handler bool cleanup_at_end() { avatar &u = get_avatar(); - if( g->uquit == QUIT_EXIT ) { - return true; - } if( g->uquit == QUIT_DIED || g->uquit == QUIT_SUICIDE ) { // Put (non-hallucinations) into the overmap so they are not lost. for( monster &critter : g->all_monsters() ) { diff --git a/src/flexbuffer_json.cpp b/src/flexbuffer_json.cpp index 11a3cec8f06fa..28c279d04c7f1 100644 --- a/src/flexbuffer_json.cpp +++ b/src/flexbuffer_json.cpp @@ -7,7 +7,6 @@ #include "cata_unreachable.h" #include "filesystem.h" -#include "game.h" #include "json.h" namespace @@ -253,9 +252,6 @@ bool JsonValue::read( std::string &s, bool throw_on_error ) const void JsonObject::report_unvisited() const { #ifndef CATA_IN_TOOL - if( g && g->uquit == quit_status::QUIT_EXIT ) { - return; - } if( !std::uncaught_exceptions() && report_unvisited_members && !visited_fields_bitset_.all() ) { std::vector skipped_members; skipped_members.reserve( visited_fields_bitset_.size() ); diff --git a/src/game.cpp b/src/game.cpp index 76c28527a9f63..e057b612da69f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2866,27 +2866,8 @@ bool game::try_get_right_click_action( action_id &act, const tripoint_bub_ms &mo return true; } -bool game::query_exit_to_OS() -{ - const int old_timeout = inp_mngr.get_timeout(); - inp_mngr.reset_timeout(); - uquit = QUIT_EXIT_PENDING; // change it before query so input_context doesn't get confused - if( query_yn( _( "Really Quit? All unsaved changes will be lost." ) ) ) { - uquit = QUIT_EXIT; - throw exit_exception(); - } - uquit = QUIT_NO; - inp_mngr.set_timeout( old_timeout ); - ui_manager::redraw_invalidated(); - catacurses::doupdate(); - return false; -} - bool game::is_game_over() { - if( uquit == QUIT_EXIT ) { - return query_exit_to_OS(); - } if( uquit == QUIT_DIED || uquit == QUIT_WATCH ) { Creature *player_killer = u.get_killer(); if( player_killer && player_killer->as_character() ) { diff --git a/src/game.h b/src/game.h index 988832e9f68b8..4eeb65a8acc7c 100644 --- a/src/game.h +++ b/src/game.h @@ -57,8 +57,6 @@ enum quit_status { QUIT_NOSAVED, // Quit without saving QUIT_DIED, // Actual death QUIT_WATCH, // Died, and watching aftermath - QUIT_EXIT, // Skip main menu and quit directly to OS - QUIT_EXIT_PENDING, // same as above, used temporarily so input_context doesn't get confused }; enum safe_mode_type { @@ -1010,8 +1008,6 @@ class game void bury_screen() const;// Bury a dead character (record their last words) void death_screen(); // Display our stats, "GAME OVER BOO HOO" public: - bool query_exit_to_OS(); - class exit_exception: public std::exception {}; /** * If there is a robot (that can be disabled), query the player * and try to disable it. diff --git a/src/handle_action.cpp b/src/handle_action.cpp index a1837c2b774a4..e2daf32e8bd7d 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -336,9 +336,6 @@ input_context game::get_player_input( std::string &action ) creature_tracker &creatures = get_creature_tracker(); do { - if( g->uquit == QUIT_EXIT ) { - break; - } if( bWeatherEffect && get_option( "ANIMATION_RAIN" ) ) { /* Location to add rain drop animation bits! Since it refreshes w_terrain it can be added to the animation section easily @@ -3143,10 +3140,6 @@ bool game::handle_action() // of location clicked. std::optional mouse_target; - if( uquit == QUIT_EXIT ) { - return false; - } - if( uquit == QUIT_WATCH && action == "QUIT" ) { uquit = QUIT_DIED; return false; diff --git a/src/init.cpp b/src/init.cpp index ba0ff56238825..928a741788851 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -44,7 +44,6 @@ #include "field_type.h" #include "filesystem.h" #include "flag.h" -#include "game.h" #include "gates.h" #include "harvest.h" #include "help.h" @@ -104,7 +103,6 @@ #include "translations.h" #include "trap.h" #include "type_id.h" -#include "ui_manager.h" #include "veh_type.h" #include "vehicle_group.h" #include "vitamin.h" @@ -126,20 +124,6 @@ DynamicDataLoader &DynamicDataLoader::get_instance() return theDynamicDataLoader; } -namespace -{ - -void check_sigint() -{ - if( g && g->uquit == quit_status::QUIT_EXIT ) { - if( g->query_exit_to_OS() ) { - throw game::exit_exception(); - } - } -} - -} // namespace - void DynamicDataLoader::load_object( const JsonObject &jo, const std::string &src, const cata_path &base_path, const cata_path &full_path ) @@ -189,7 +173,6 @@ void DynamicDataLoader::load_deferred( deferred_json &data ) } ++it; inp_mngr.pump_events(); - check_sigint(); } data.erase( data.begin(), it ); if( data.size() == n ) { @@ -633,7 +616,6 @@ void DynamicDataLoader::load_all_from_json( const JsonValue &jsin, const std::st // find type and dispatch each object until array close for( JsonObject jo : ja ) { load_object( jo, src, base_path, full_path ); - check_sigint(); } } else { // not an object or an array? @@ -865,7 +847,6 @@ void DynamicDataLoader::finalize_loaded_data() for( const named_entry &e : entries ) { loading_ui::show( _( "Finalizing" ), e.first ); e.second(); - check_sigint(); } if( !get_option( "SKIP_VERIFICATION" ) ) { @@ -971,6 +952,5 @@ void DynamicDataLoader::check_consistency() for( const named_entry &e : entries ) { loading_ui::show( _( "Verifying" ), e.first ); e.second(); - check_sigint(); } } diff --git a/src/input_context.cpp b/src/input_context.cpp index bc3bdc9c8d164..93869ae4532ee 100644 --- a/src/input_context.cpp +++ b/src/input_context.cpp @@ -134,7 +134,6 @@ static const std::string ANY_INPUT = "ANY_INPUT"; static const std::string HELP_KEYBINDINGS = "HELP_KEYBINDINGS"; static const std::string COORDINATE = "COORDINATE"; static const std::string TIMEOUT = "TIMEOUT"; -static const std::string QUIT = "QUIT"; const std::string &input_context::input_to_action( const input_event &inp ) const { @@ -446,10 +445,6 @@ const std::string &input_context::handle_input( const int timeout ) break; } - if( g->uquit == QUIT_EXIT ) { - result = &QUIT; - break; - } const std::string &action = input_to_action( next_action ); //Special global key to toggle language to english and back diff --git a/src/main.cpp b/src/main.cpp index f26cbba523f2f..61627d21558f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -143,30 +143,42 @@ namespace // Used only if AttachConsole() works FILE *CONOUT; #endif - -#if !defined(_WIN32) -extern "C" void sigint_handler( int /* s */ ) -{ - if( g->uquit != QUIT_EXIT_PENDING ) { - g->uquit = QUIT_EXIT; - } -} -#endif - -void exit_handler( int /* s */ ) +void exit_handler( int s ) { - deinitDebug(); + const int old_timeout = inp_mngr.get_timeout(); + inp_mngr.reset_timeout(); + if( s != 2 || query_yn( _( "Really Quit? All unsaved changes will be lost." ) ) ) { + deinitDebug(); - g.reset(); + int exit_status = 0; + g.reset(); - catacurses::endwin(); + catacurses::endwin(); #if defined(__ANDROID__) - // Avoid capturing SIGABRT on exit on Android in crash report - // Can be removed once the SIGABRT on exit problem is fixed - signal( SIGABRT, SIG_DFL ); + // Avoid capturing SIGABRT on exit on Android in crash report + // Can be removed once the SIGABRT on exit problem is fixed + signal( SIGABRT, SIG_DFL ); #endif +#if !defined(_WIN32) + if( s == 2 ) { + struct sigaction sigIntHandler; + sigIntHandler.sa_handler = SIG_DFL; + sigemptyset( &sigIntHandler.sa_mask ); + sigIntHandler.sa_flags = 0; + sigaction( SIGINT, &sigIntHandler, nullptr ); + kill( getpid(), s ); + } else +#endif + { + imclient.reset(); + exit( exit_status ); + } + } + inp_mngr.set_timeout( old_timeout ); + ui_manager::redraw_invalidated(); + catacurses::doupdate(); } struct arg_handler { @@ -827,7 +839,7 @@ int main( int argc, const char *argv[] ) #if !defined(_WIN32) struct sigaction sigIntHandler; - sigIntHandler.sa_handler = sigint_handler; + sigIntHandler.sa_handler = exit_handler; sigemptyset( &sigIntHandler.sa_mask ); sigIntHandler.sa_flags = 0; sigaction( SIGINT, &sigIntHandler, nullptr ); @@ -859,11 +871,7 @@ int main( int argc, const char *argv[] ) shared_ptr_fast ui = g->create_or_get_main_ui_adaptor(); get_event_bus().send( getVersionString() ); - try { - while( !do_turn() ) { } - } catch( game::exit_exception const &/* ex */ ) { - break; - } + while( !do_turn() ) {} } exit_handler( -999 ); diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 957481a9e03b8..eddbaab741b9c 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -791,10 +791,6 @@ bool main_menu::opening_screen() #endif while( !start ) { - if( g->uquit == QUIT_EXIT ) { - return false; - } - ui_manager::redraw(); std::string action = ctxt.handle_input(); input_event sInput = ctxt.get_raw_input(); @@ -884,12 +880,9 @@ bool main_menu::opening_screen() // also check special keys if( action == "QUIT" ) { #if !defined(EMSCRIPTEN) - g->uquit = QUIT_EXIT_PENDING; if( query_yn( _( "Really quit?" ) ) ) { - g->uquit = QUIT_EXIT; return false; } - g->uquit = QUIT_NO; #endif } else if( action == "LEFT" || action == "PREV_TAB" || action == "RIGHT" || action == "NEXT_TAB" ) { sel_line = 0; @@ -1203,8 +1196,6 @@ bool main_menu::load_game( std::string const &worldname, save_t const &savegame try { g->setup(); - } catch( game::exit_exception const &/* ex */ ) { - return false; } catch( const std::exception &err ) { debugmsg( "Error: %s", err.what() ); return false; diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index cc9fa46776b41..a635e03afb553 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -3537,9 +3537,8 @@ static void CheckMessages() try_sdl_update(); } if( quit ) { - if( g->uquit != quit_status::QUIT_EXIT_PENDING ) { - g->uquit = quit_status::QUIT_EXIT; - } + catacurses::endwin(); + exit( 0 ); } } diff --git a/src/ui.cpp b/src/ui.cpp index 99ef13f2dbb37..612342c27b50e 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -994,8 +994,7 @@ void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys ) if( entries[ selected ].enabled || allow_disabled ) { ret = entries[selected].retval; } - } else if( ( allow_cancel && ret_act == "UILIST.QUIT" ) || - ( g->uquit == QUIT_EXIT && ret_act == "QUIT" ) ) { + } else if( allow_cancel && ret_act == "UILIST.QUIT" ) { ret = UILIST_CANCEL; } else if( ret_act == "TIMEOUT" ) { ret = UILIST_WAIT_INPUT;