debug: decouple livereload from autopause

This commit is contained in:
Sebastian Krzyszkowiak 2018-08-09 00:42:53 +02:00
parent 7d4575308d
commit 916094b371
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
3 changed files with 13 additions and 2 deletions

View file

@ -553,12 +553,12 @@ SYMBOL_INTERNAL void PauseExecution(struct Game* game) {
PrintConsole(game, "DEBUG: game execution paused."); PrintConsole(game, "DEBUG: game execution paused.");
} }
SYMBOL_INTERNAL void ResumeExecution(struct Game* game) { SYMBOL_INTERNAL void ReloadCode(struct Game* game) {
ReloadShaders(game, true); ReloadShaders(game, true);
PrintConsole(game, "DEBUG: reloading the gamestates..."); PrintConsole(game, "DEBUG: reloading the gamestates...");
struct Gamestate* tmp = game->_priv.gamestates; struct Gamestate* tmp = game->_priv.gamestates;
while (tmp) { while (tmp) {
if (game->_priv.debug.livereload && tmp->fromlib) { if (tmp->fromlib) {
char* name = strdup(tmp->name); char* name = strdup(tmp->name);
CloseGamestate(game, tmp); CloseGamestate(game, tmp);
tmp->name = name; tmp->name = name;
@ -571,7 +571,13 @@ SYMBOL_INTERNAL void ResumeExecution(struct Game* game) {
tmp->loaded = false; 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) { if (!tmp->paused && tmp->loaded && tmp->started && tmp->api->Gamestate_Resume) {
tmp->api->Gamestate_Resume(game, tmp->data); tmp->api->Gamestate_Resume(game, tmp->data);
} }

View file

@ -99,6 +99,7 @@ void CloseGamestate(struct Game* game, struct Gamestate* gamestate);
struct Gamestate* AllocateGamestate(struct Game* game, const char* name); struct Gamestate* AllocateGamestate(struct Game* game, const char* name);
char* GetLibraryPath(struct Game* game, char* filename); char* GetLibraryPath(struct Game* game, char* filename);
void PauseExecution(struct Game* game); void PauseExecution(struct Game* game);
void ReloadCode(struct Game* game);
void ResumeExecution(struct Game* game); void ResumeExecution(struct Game* game);
void ReloadShaders(struct Game* game, bool force); void ReloadShaders(struct Game* game, bool force);
void DestroyShaders(struct Game* game); void DestroyShaders(struct Game* game);

View file

@ -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)) { } else if ((game->config.debug) && (game->_priv.debug.autopause) && (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT)) {
PauseExecution(game); PauseExecution(game);
} else if ((game->config.debug) && (game->_priv.debug.autopause) && (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN)) { } 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); ResumeExecution(game);
} }
#ifdef ALLEGRO_ANDROID #ifdef ALLEGRO_ANDROID
@ -588,6 +591,7 @@ SYMBOL_INTERNAL void libsuperderpy_mainloop(void* g) {
if (!game->_priv.paused) { if (!game->_priv.paused) {
PauseExecution(game); PauseExecution(game);
} else { } else {
ReloadCode(game);
ResumeExecution(game); ResumeExecution(game);
} }
} else if ((ev.type == ALLEGRO_EVENT_KEY_DOWN) && (game->config.debug) && (ev.keyboard.keycode == ALLEGRO_KEY_F9)) { } else if ((ev.type == ALLEGRO_EVENT_KEY_DOWN) && (game->config.debug) && (ev.keyboard.keycode == ALLEGRO_KEY_F9)) {