attempt to ensure clean exit by external request (window closed, process terminated, etc.)

This commit is contained in:
Andrei Alexeyev 2018-05-19 05:01:16 +03:00
parent b11e45add6
commit fdfc2de543
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
5 changed files with 25 additions and 1 deletions

View file

@ -293,7 +293,8 @@ static void events_unregister_default_handlers(void) {
}
static bool events_handler_quit(SDL_Event *event, void *arg) {
exit(0);
taisei_quit();
return true;
}
static bool events_handler_keyrepeat_workaround(SDL_Event *event, void *arg) {

View file

@ -158,6 +158,10 @@ begin_frame:
fpscounter_update(&global.fps.logic);
}
if(taisei_quit_requested()) {
break;
}
if((!uncapped_rendering && frame_num % get_effective_frameskip()) || global.is_replay_verification) {
rframe_action = RFRAME_DROP;
} else {

View file

@ -44,3 +44,15 @@ void init_global(CLIAction *cli) {
bool gamekeypressed(KeyIndex key) {
return SDL_GetKeyboardState(NULL)[config_get_int(KEYIDX_TO_CFGIDX(key))] || gamepad_game_key_pressed(key);
}
static SDL_atomic_t quitting;
void taisei_quit(void) {
if(SDL_AtomicCAS(&quitting, 0, 1)) {
log_info("Exit requested");
}
}
bool taisei_quit_requested(void) {
return SDL_AtomicGet(&quitting);
}

View file

@ -134,5 +134,8 @@ extern Global global;
void init_global(CLIAction *cli);
void taisei_quit(void);
bool taisei_quit_requested(void);
// XXX: Move this somewhere?
bool gamekeypressed(KeyIndex key);

View file

@ -703,4 +703,8 @@ void stage_loop(StageInfo *stage) {
ent_shutdown();
stage_objpools_free();
stop_sounds();
if(taisei_quit_requested()) {
global.game_over = GAMEOVER_ABORT;
}
}