Skip to content

Commit

Permalink
Merge pull request #78791 from ZhilkinSerg/sigint-and-whatnot-revert
Browse files Browse the repository at this point in the history
Sigint and whatnot revert
  • Loading branch information
GuardianDll authored Jan 9, 2025
2 parents 8e8de5f + 049198c commit b940e14
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 147 deletions.
22 changes: 1 addition & 21 deletions object_creator/creator_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
#include <QtWidgets/qsplashscreen.h>
#include <QtGui/qpainter.h>

//Required by the sigaction function in the exit_handler
#if defined(_WIN32)
#include "platform_win.h"
#else
#include <csignal>
#endif

#ifdef _WIN32
#include <QtCore/QtPlugin>
Q_IMPORT_PLUGIN( QWindowsIntegrationPlugin );
Expand All @@ -52,20 +45,7 @@ void exit_handler( int s )

catacurses::endwin();

// As suggested by https://github.com/CleverRaven/Cataclysm-DDA/pull/67893
#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
{
exit( exit_status );
}
exit( exit_status );
}
inp_mngr.set_timeout( old_timeout );
}
Expand Down
11 changes: 1 addition & 10 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "color.h"
#include "cursesdef.h"
#include "filesystem.h"
#include "game.h"
#include "get_version.h"
#include "input.h"
#include "loading_ui.h"
Expand Down Expand Up @@ -383,15 +382,7 @@ static void debug_error_prompt(
#endif
for( bool stop = false; !stop; ) {
ui_manager::redraw();
inp_mngr.set_timeout( 50 );
input_event ievent = inp_mngr.get_input_event();
if( ievent.type == input_event_t::timeout ) {
if( are_we_quitting() ) {
g->query_exit_to_OS();
}
continue;
}
switch( ievent.get_first_input() ) {
switch( inp_mngr.get_input_event().get_first_input() ) {
#if defined(TILES)
case 'c':
case 'C':
Expand Down
3 changes: 0 additions & 3 deletions src/do_turn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ namespace turn_handler
bool cleanup_at_end()
{
avatar &u = get_avatar();
if( are_we_quitting() ) {
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() ) {
Expand Down
4 changes: 0 additions & 4 deletions src/flexbuffer_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "cata_unreachable.h"
#include "filesystem.h"
#include "game.h"
#include "json.h"

namespace
Expand Down Expand Up @@ -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<size_t> skipped_members;
skipped_members.reserve( visited_fields_bitset_.size() );
Expand Down
24 changes: 0 additions & 24 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2868,27 +2868,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( are_we_quitting() ) {
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() ) {
Expand Down Expand Up @@ -14155,8 +14136,3 @@ global_variables &get_globals()
{
return g->global_variables_instance;
}

bool are_we_quitting()
{
return g && ( g->uquit == QUIT_EXIT || g->uquit == QUIT_EXIT_PENDING );
}
6 changes: 0 additions & 6 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1322,6 +1318,4 @@ namespace cata_event_dispatch
void avatar_moves( const tripoint_abs_ms &old_abs_pos, const avatar &u, const map &m );
} // namespace cata_event_dispatch

bool are_we_quitting();

#endif // CATA_SRC_GAME_H
15 changes: 5 additions & 10 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,6 @@ input_context game::get_player_input( std::string &action )

creature_tracker &creatures = get_creature_tracker();
do {
if( are_we_quitting() ) {
break;
}
if( bWeatherEffect && get_option<bool>( "ANIMATION_RAIN" ) ) {
/*
Location to add rain drop animation bits! Since it refreshes w_terrain it can be added to the animation section easily
Expand Down Expand Up @@ -2846,9 +2843,11 @@ bool game::do_regular_action( action_id &act, avatar &player_character,
break;

case ACTION_SAVE:
if( save() ) {
player_character.set_moves( 0 );
uquit = QUIT_SAVED;
if( query_yn( _( "Save and quit?" ) ) ) {
if( save() ) {
player_character.set_moves( 0 );
uquit = QUIT_SAVED;
}
}
break;

Expand Down Expand Up @@ -3153,10 +3152,6 @@ bool game::handle_action()
// of location clicked.
std::optional<tripoint_bub_ms> mouse_target;

if( are_we_quitting() ) {
return false;
}

if( uquit == QUIT_WATCH && action == "QUIT" ) {
uquit = QUIT_DIED;
return false;
Expand Down
18 changes: 0 additions & 18 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -126,18 +124,6 @@ DynamicDataLoader &DynamicDataLoader::get_instance()
return theDynamicDataLoader;
}

namespace
{

void check_sigint()
{
if( g && g->uquit == quit_status::QUIT_EXIT ) {
g->query_exit_to_OS();
}
}

} // namespace

void DynamicDataLoader::load_object( const JsonObject &jo, const std::string &src,
const cata_path &base_path,
const cata_path &full_path )
Expand Down Expand Up @@ -187,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 ) {
Expand Down Expand Up @@ -631,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?
Expand Down Expand Up @@ -863,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<bool>( "SKIP_VERIFICATION" ) ) {
Expand Down Expand Up @@ -969,6 +952,5 @@ void DynamicDataLoader::check_consistency()
for( const named_entry &e : entries ) {
loading_ui::show( _( "Verifying" ), e.first );
e.second();
check_sigint();
}
}
6 changes: 0 additions & 6 deletions src/input_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -446,11 +445,6 @@ const std::string &input_context::handle_input( const int timeout )
break;
}

if( g->uquit == QUIT_EXIT ) {
g->uquit = QUIT_EXIT_PENDING;
result = &QUIT;
break;
}
const std::string &action = input_to_action( next_action );

//Special global key to toggle language to english and back
Expand Down
53 changes: 23 additions & 30 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
#include "type_id.h"
#include "ui_manager.h"
#include "cata_imgui.h"
#if defined(MACOSX) || defined(__CYGWIN__)
# include <unistd.h> // getpid()
#endif

#if defined(EMSCRIPTEN)
#include <emscripten.h>
Expand Down Expand Up @@ -143,30 +140,30 @@ 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

imclient.reset();
exit( exit_status );
}
inp_mngr.set_timeout( old_timeout );
ui_manager::redraw_invalidated();
catacurses::doupdate();
}

struct arg_handler {
Expand Down Expand Up @@ -827,7 +824,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 );
Expand All @@ -853,17 +850,13 @@ int main( int argc, const char *argv[] )

while( true ) {
main_menu menu;
try {
if( !menu.opening_screen() ) {
break;
}

shared_ptr_fast<ui_adaptor> ui = g->create_or_get_main_ui_adaptor();
get_event_bus().send<event_type::game_begin>( getVersionString() );
while( !do_turn() ) { }
} catch( game::exit_exception const &/* ex */ ) {
if( !menu.opening_screen() ) {
break;
}

shared_ptr_fast<ui_adaptor> ui = g->create_or_get_main_ui_adaptor();
get_event_bus().send<event_type::game_begin>( getVersionString() );
while( !do_turn() ) {}
}

exit_handler( -999 );
Expand Down
Loading

0 comments on commit b940e14

Please sign in to comment.