diff --git a/src/game.cpp b/src/game.cpp index dbece2bb4850d..af421f35bba35 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2758,6 +2758,9 @@ bool game::try_get_right_click_action( action_id &act, const tripoint_bub_ms &mo bool game::is_game_over() { + if( uquit == QUIT_EXIT ) { + return true; + } if( uquit == QUIT_DIED || uquit == QUIT_WATCH ) { events().send(); } diff --git a/src/game.h b/src/game.h index 517fb0520e85c..2823f7e636f02 100644 --- a/src/game.h +++ b/src/game.h @@ -56,6 +56,7 @@ 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 }; enum safe_mode_type { diff --git a/src/main.cpp b/src/main.cpp index c48f56482e84d..e9c787122b692 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -144,42 +144,42 @@ namespace // Used only if AttachConsole() works FILE *CONOUT; #endif -void exit_handler( int s ) + +#if !defined(_WIN32) +void sigint_handler( int /* s */ ) { 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(); + if( query_yn( _( "Really Quit? All unsaved changes will be lost." ) ) ) { + struct sigaction sigIntHandler; + sigIntHandler.sa_handler = SIG_DFL; + sigemptyset( &sigIntHandler.sa_mask ); + sigIntHandler.sa_flags = 0; + sigaction( SIGINT, &sigIntHandler, nullptr ); + g->uquit = QUIT_EXIT; + } else { + inp_mngr.set_timeout( old_timeout ); + ui_manager::redraw_invalidated(); + catacurses::doupdate(); + } +} +#endif + +void exit_handler( int /* s */ ) +{ + deinitDebug(); - int exit_status = 0; - g.reset(); + g.reset(); - catacurses::endwin(); + catacurses::endwin(); + imclient.reset(); #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 { @@ -838,7 +838,7 @@ int main( int argc, const char *argv[] ) #if !defined(_WIN32) struct sigaction sigIntHandler; - sigIntHandler.sa_handler = exit_handler; + sigIntHandler.sa_handler = sigint_handler; sigemptyset( &sigIntHandler.sa_mask ); sigIntHandler.sa_flags = 0; sigaction( SIGINT, &sigIntHandler, nullptr ); @@ -862,7 +862,8 @@ int main( int argc, const char *argv[] ) get_help().load(); - while( true ) { + bool running = true; + while( running ) { main_menu menu; if( !menu.opening_screen() ) { break; @@ -870,7 +871,12 @@ int main( int argc, const char *argv[] ) shared_ptr_fast ui = g->create_or_get_main_ui_adaptor(); get_event_bus().send( getVersionString() ); - while( !do_turn() ) {} + while( !do_turn() ) { + if( g->uquit == QUIT_EXIT ) { + running = false; + break; + } + } } exit_handler( -999 );