attempt to ensure clean exit by external request (window closed, process terminated, etc.)
This commit is contained in:
parent
b11e45add6
commit
fdfc2de543
5 changed files with 25 additions and 1 deletions
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
12
src/global.c
12
src/global.c
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue