From 916094b371b7384db95b2b5da1dabf640efad213 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 9 Aug 2018 00:42:53 +0200 Subject: [PATCH] debug: decouple livereload from autopause --- src/internal.c | 10 ++++++++-- src/internal.h | 1 + src/libsuperderpy.c | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index e960cca..e920a2b 100644 --- a/src/internal.c +++ b/src/internal.c @@ -553,12 +553,12 @@ SYMBOL_INTERNAL void PauseExecution(struct Game* game) { PrintConsole(game, "DEBUG: game execution paused."); } -SYMBOL_INTERNAL void ResumeExecution(struct Game* game) { +SYMBOL_INTERNAL void ReloadCode(struct Game* game) { ReloadShaders(game, true); PrintConsole(game, "DEBUG: reloading the gamestates..."); struct Gamestate* tmp = game->_priv.gamestates; while (tmp) { - if (game->_priv.debug.livereload && tmp->fromlib) { + if (tmp->fromlib) { char* name = strdup(tmp->name); CloseGamestate(game, tmp); tmp->name = name; @@ -571,7 +571,13 @@ SYMBOL_INTERNAL void ResumeExecution(struct Game* game) { tmp->loaded = false; } } + tmp = tmp->next; + } +} +SYMBOL_INTERNAL void ResumeExecution(struct Game* game) { + struct Gamestate* tmp = game->_priv.gamestates; + while (tmp) { if (!tmp->paused && tmp->loaded && tmp->started && tmp->api->Gamestate_Resume) { tmp->api->Gamestate_Resume(game, tmp->data); } diff --git a/src/internal.h b/src/internal.h index 9268a62..4bb6785 100644 --- a/src/internal.h +++ b/src/internal.h @@ -99,6 +99,7 @@ void CloseGamestate(struct Game* game, struct Gamestate* gamestate); struct Gamestate* AllocateGamestate(struct Game* game, const char* name); char* GetLibraryPath(struct Game* game, char* filename); void PauseExecution(struct Game* game); +void ReloadCode(struct Game* game); void ResumeExecution(struct Game* game); void ReloadShaders(struct Game* game, bool force); void DestroyShaders(struct Game* game); diff --git a/src/libsuperderpy.c b/src/libsuperderpy.c index 747f8d4..f1c1456 100644 --- a/src/libsuperderpy.c +++ b/src/libsuperderpy.c @@ -573,6 +573,9 @@ SYMBOL_INTERNAL void libsuperderpy_mainloop(void* g) { } else if ((game->config.debug) && (game->_priv.debug.autopause) && (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT)) { PauseExecution(game); } else if ((game->config.debug) && (game->_priv.debug.autopause) && (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN)) { + if (game->_priv.debug.livereload) { + ReloadCode(game); + } ResumeExecution(game); } #ifdef ALLEGRO_ANDROID @@ -588,6 +591,7 @@ SYMBOL_INTERNAL void libsuperderpy_mainloop(void* g) { if (!game->_priv.paused) { PauseExecution(game); } else { + ReloadCode(game); ResumeExecution(game); } } else if ((ev.type == ALLEGRO_EVENT_KEY_DOWN) && (game->config.debug) && (ev.keyboard.keycode == ALLEGRO_KEY_F9)) {