From 532727b15c27c1875fa59577dc0f272342355157 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Mon, 10 Sep 2018 04:36:18 +0200 Subject: [PATCH] Add some missing guards and debug messages for gamestate handling --- src/gamestate.c | 2 +- src/gamestate.h | 1 + src/internal.c | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gamestate.c b/src/gamestate.c index cf41910..87e10c0 100644 --- a/src/gamestate.c +++ b/src/gamestate.c @@ -106,7 +106,7 @@ SYMBOL_EXPORT void StartGamestate(struct Game* game, const char* name) { PrintConsole(game, "Gamestate \"%s\" already started.", name); return; } - if (!gs->loaded) { + if (!gs->loaded && !gs->pending_load) { LoadGamestate(game, name); } gs->pending_start = true; diff --git a/src/gamestate.h b/src/gamestate.h index ec7537d..065e824 100644 --- a/src/gamestate.h +++ b/src/gamestate.h @@ -51,6 +51,7 @@ struct Gamestate { bool showLoading; bool paused; bool fromlib; + bool open; struct Gamestate* next; struct Gamestate_API* api; ALLEGRO_BITMAP* fb; diff --git a/src/internal.c b/src/internal.c index 3912603..61d1229 100644 --- a/src/internal.c +++ b/src/internal.c @@ -304,6 +304,7 @@ SYMBOL_INTERNAL bool OpenGamestate(struct Game* game, struct Gamestate* gamestat } else { gamestate->fb = al_create_sub_bitmap(al_get_backbuffer(game->display), game->_priv.clip_rect.x, game->_priv.clip_rect.y, game->_priv.clip_rect.w, game->_priv.clip_rect.h); } + gamestate->open = true; return true; } @@ -356,10 +357,14 @@ SYMBOL_INTERNAL struct Gamestate* AllocateGamestate(struct Game* game, const cha tmp->api = NULL; tmp->fromlib = true; tmp->progressCount = 0; + tmp->open = false; return tmp; } SYMBOL_INTERNAL void CloseGamestate(struct Game* game, struct Gamestate* gamestate) { + if (!gamestate->open) { + return; + } if (gamestate->handle && !RUNNING_ON_VALGRIND) { #ifndef LEAK_SANITIZER PrintConsole(game, "Closing gamestate \"%s\"...", gamestate->name); @@ -542,6 +547,9 @@ SYMBOL_INTERNAL char* GetLibraryPath(struct Game* game, char* filename) { } SYMBOL_INTERNAL void PauseExecution(struct Game* game) { + if (game->_priv.paused) { + return; + } game->_priv.paused = true; al_stop_timer(game->_priv.timer); al_detach_voice(game->audio.v); @@ -551,15 +559,16 @@ SYMBOL_INTERNAL void PauseExecution(struct Game* game) { SYMBOL_INTERNAL void ReloadCode(struct Game* game) { ReloadShaders(game, true); - PrintConsole(game, "DEBUG: reloading the gamestates..."); + PrintConsole(game, "DEBUG: Reloading the gamestates..."); struct Gamestate* tmp = game->_priv.gamestates; while (tmp) { - if (tmp->fromlib) { + if (tmp->open && tmp->fromlib) { char* name = strdup(tmp->name); CloseGamestate(game, tmp); tmp->name = name; if (OpenGamestate(game, tmp) && LinkGamestate(game, tmp) && tmp->loaded) { if (tmp->api->Gamestate_Reload) { + PrintConsole(game, "[%s] Reloading...", tmp->name); tmp->api->Gamestate_Reload(game, tmp->data); } } else { @@ -569,9 +578,13 @@ SYMBOL_INTERNAL void ReloadCode(struct Game* game) { } tmp = tmp->next; } + PrintConsole(game, "DEBUG: Reloading done."); } SYMBOL_INTERNAL void ResumeExecution(struct Game* game) { + if (!game->_priv.paused) { + return; + } UnfreezeGamestates(game); al_attach_mixer_to_voice(game->audio.mixer, game->audio.v); al_resume_timer(game->_priv.timer);