From f4ca431238be52a4a42b0b0d541b82fcbb5c8a89 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Wed, 18 Jul 2018 19:50:35 +0200 Subject: [PATCH] gmaestate: automatically load unloaded gamestate when trying to start it --- src/gamestate.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gamestate.c b/src/gamestate.c index 0993361..e7288ba 100644 --- a/src/gamestate.c +++ b/src/gamestate.c @@ -95,6 +95,7 @@ SYMBOL_EXPORT void UnloadGamestate(struct Game* game, const char* name) { PrintConsole(game, "Gamestate \"%s\" marked to be UNLOADED.", name); } else { PrintConsole(game, "Tried to unload nonexisitent gamestate \"%s\"", name); + return; } game->_priv.gamestate_scheduled = true; } @@ -106,10 +107,15 @@ SYMBOL_EXPORT void StartGamestate(struct Game* game, const char* name) { PrintConsole(game, "Gamestate \"%s\" already started.", name); return; } + if (!gs->loaded) { + LoadGamestate(game, name); + } gs->pending_start = true; PrintConsole(game, "Gamestate \"%s\" marked to be STARTED.", name); } else { - PrintConsole(game, "Tried to start nonexisitent gamestate \"%s\"", name); + // trying to start a gamestate that's not registered yet + LoadGamestate(game, name); + return StartGamestate(game, name); } game->_priv.gamestate_scheduled = true; } @@ -130,6 +136,7 @@ SYMBOL_EXPORT void StopGamestate(struct Game* game, const char* name) { PrintConsole(game, "Gamestate \"%s\" marked to be STOPPED.", name); } else { PrintConsole(game, "Tried to stop nonexisitent gamestate \"%s\"", name); + return; } game->_priv.gamestate_scheduled = true; }