don't abort when there's no loading screen available

This commit is contained in:
Sebastian Krzyszkowiak 2019-03-30 03:34:55 +01:00
parent 44bee57f55
commit 9706f61116
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
4 changed files with 21 additions and 17 deletions

View file

@ -334,13 +334,15 @@ SYMBOL_INTERNAL void GamestateProgress(struct Game* game) {
#endif
}
SYMBOL_INTERNAL bool OpenGamestate(struct Game* game, struct Gamestate* gamestate) {
SYMBOL_INTERNAL bool OpenGamestate(struct Game* game, struct Gamestate* gamestate, bool required) {
PrintConsole(game, "Opening gamestate \"%s\"...", gamestate->name);
char libname[1024];
snprintf(libname, 1024, "lib%s-%s" LIBRARY_EXTENSION, game->_priv.name, gamestate->name);
gamestate->handle = dlopen(AddGarbage(game, GetLibraryPath(game, libname)), RTLD_NOW);
if (!gamestate->handle) {
FatalError(game, false, "Error while opening gamestate \"%s\": %s", gamestate->name, dlerror()); // TODO: move out
if (required) {
FatalError(game, false, "Error while opening gamestate \"%s\": %s", gamestate->name, dlerror());
}
return false;
}
if (game->_priv.params.handlers.compositor) {
@ -618,7 +620,7 @@ SYMBOL_INTERNAL void ReloadCode(struct Game* game) {
char* name = strdup(tmp->name);
CloseGamestate(game, tmp);
tmp->name = name;
if (OpenGamestate(game, tmp) && LinkGamestate(game, tmp) && tmp->loaded) {
if (OpenGamestate(game, tmp, true) && LinkGamestate(game, tmp) && tmp->loaded) {
if (tmp->api->reload) {
PrintConsole(game, "[%s] Reloading...", tmp->name);
tmp->api->reload(game, tmp->data);

View file

@ -135,7 +135,7 @@ void* RemoveFromList(struct List** list, void* data, bool (*identity)(struct Lis
void AddTimeline(struct Game* game, struct Timeline* timeline);
void RemoveTimeline(struct Game* game, struct Timeline* timeline);
void DrawTimelines(struct Game* game);
bool OpenGamestate(struct Game* game, struct Gamestate* gamestate);
bool OpenGamestate(struct Game* game, struct Gamestate* gamestate, bool required);
bool LinkGamestate(struct Game* game, struct Gamestate* gamestate);
void CloseGamestate(struct Game* game, struct Gamestate* gamestate);
struct Gamestate* AllocateGamestate(struct Game* game, const char* name);

View file

@ -391,17 +391,17 @@ SYMBOL_EXPORT int libsuperderpy_start(struct Game* game) {
}
game->_priv.loading.gamestate = AllocateGamestate(game, "loading");
if (!OpenGamestate(game, game->_priv.loading.gamestate) || !LinkGamestate(game, game->_priv.loading.gamestate)) {
// TODO: support loading-less scenario
return 2;
if (OpenGamestate(game, game->_priv.loading.gamestate, false) && LinkGamestate(game, game->_priv.loading.gamestate)) {
game->_priv.loading.gamestate->data = (*game->_priv.loading.gamestate->api->load)(game, NULL);
game->_priv.loading.gamestate->loaded = true;
PrintConsole(game, "Loading screen registered.");
} else {
PrintConsole(game, "No loading screen available.");
}
game->_priv.loading.gamestate->data = (*game->_priv.loading.gamestate->api->load)(game, NULL);
game->_priv.loading.gamestate->loaded = true;
PrintConsole(game, "Loading screen registered.");
ReloadShaders(game, false);
if (game->_priv.loading.gamestate->api->post_load) {
if (game->_priv.loading.gamestate->open && game->_priv.loading.gamestate->api->post_load) {
(*game->_priv.loading.gamestate->api->post_load)(game, game->_priv.loading.gamestate->data);
}
@ -483,8 +483,10 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
tmp = pom;
}
(*game->_priv.loading.gamestate->api->unload)(game, game->_priv.loading.gamestate->data);
CloseGamestate(game, game->_priv.loading.gamestate);
if (game->_priv.loading.gamestate->open) {
(*game->_priv.loading.gamestate->api->unload)(game, game->_priv.loading.gamestate->data);
CloseGamestate(game, game->_priv.loading.gamestate);
}
free(game->_priv.loading.gamestate);
if (game->_priv.params.handlers.destroy) {

View file

@ -295,12 +295,12 @@ static inline bool MainloopTick(struct Game* game) {
#ifdef __EMSCRIPTEN__
al_detach_voice(game->audio.v);
#endif
if (tmp->show_loading) {
if (tmp->show_loading && game->_priv.loading.gamestate->open) {
(*game->_priv.loading.gamestate->api->start)(game, game->_priv.loading.gamestate->data);
}
if (!tmp->api) {
if (!OpenGamestate(game, tmp) || !LinkGamestate(game, tmp)) {
if (!OpenGamestate(game, tmp, true) || !LinkGamestate(game, tmp)) {
tmp->pending_load = false;
tmp->pending_start = false;
continue;
@ -334,7 +334,7 @@ static inline bool MainloopTick(struct Game* game) {
double delta = al_get_time() - game->_priv.loading.time;
game->time += delta; // TODO: ability to disable passing time during loading
game->_priv.loading.time += delta;
if (game->loading.shown) {
if (game->loading.shown && game->_priv.loading.gamestate->open) {
(*game->_priv.loading.gamestate->api->logic)(game, game->_priv.loading.gamestate->data, delta);
}
DrawGamestates(game);
@ -394,7 +394,7 @@ static inline bool MainloopTick(struct Game* game) {
tmp->loaded = true;
tmp->pending_load = false;
}
if (tmp->show_loading) {
if (tmp->show_loading && game->_priv.loading.gamestate->open) {
(*game->_priv.loading.gamestate->api->stop)(game, game->_priv.loading.gamestate->data);
}
tmp->show_loading = true;