don't live-reload gamestates that don't come from dynamic libraries

This commit is contained in:
Sebastian Krzyszkowiak 2018-07-18 19:58:34 +02:00
parent f4ca431238
commit 31f6b8454d
3 changed files with 14 additions and 9 deletions

View file

@ -58,6 +58,7 @@ SYMBOL_EXPORT void RegisterGamestate(struct Game* game, const char* name, struct
return;
}
gs->api = api;
gs->fromlib = false;
PrintConsole(game, "Gamestate \"%s\" registered.", name);
}

View file

@ -49,6 +49,7 @@ struct Gamestate {
bool frozen;
bool showLoading;
bool paused;
bool fromlib;
struct Gamestate* next;
struct Gamestate_API* api;
ALLEGRO_BITMAP* fb;

View file

@ -340,6 +340,7 @@ SYMBOL_INTERNAL struct Gamestate* AllocateGamestate(struct Game* game, const cha
tmp->pending_unload = false;
tmp->next = NULL;
tmp->api = NULL;
tmp->fromlib = true;
tmp->progressCount = 0;
return tmp;
}
@ -543,17 +544,19 @@ SYMBOL_INTERNAL void ResumeExecution(struct Game* game) {
PrintConsole(game, "DEBUG: reloading the gamestates...");
struct Gamestate* tmp = game->_priv.gamestates;
while (tmp) {
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) {
tmp->api->Gamestate_Reload(game, tmp->data);
}
if (!tmp->paused && tmp->api->Gamestate_Resume) {
tmp->api->Gamestate_Resume(game, tmp->data);
if (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) {
tmp->api->Gamestate_Reload(game, tmp->data);
}
}
}
if (!tmp->paused && tmp->loaded && tmp->api->Gamestate_Resume) {
tmp->api->Gamestate_Resume(game, tmp->data);
}
tmp = tmp->next;
}
game->_priv.paused = false;