From 2e15e4d8dcf57ebcb92791ceab0b4d95760d1a1d Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Sat, 4 Apr 2020 04:47:10 +0200 Subject: [PATCH] Use al_store_state and al_restore_state when dealing with threads This lets the active Allegro file interface to be used by the new thread. --- src/internal.c | 5 +++-- src/internal.h | 2 +- src/mainloop.c | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/internal.c b/src/internal.c index c2e3af7..8befaad 100644 --- a/src/internal.c +++ b/src/internal.c @@ -283,7 +283,7 @@ SYMBOL_INTERNAL void Console_Unload(struct Game* game) { SYMBOL_INTERNAL void* GamestateLoadingThread(void* arg) { struct GamestateLoadingThreadData* data = arg; data->game->_priv.loading.in_progress = true; - al_set_new_bitmap_flags(data->bitmap_flags); + al_restore_state(&data->state); data->gamestate->data = data->gamestate->api->load(data->game, &GamestateProgress); if (data->game->_priv.loading.progress != data->gamestate->progress_count) { PrintConsole(data->game, "[%s] WARNING: Gamestate_ProgressCount does not match the number of progress invokations (%d)!", data->gamestate->name, data->game->_priv.loading.progress); @@ -295,7 +295,8 @@ SYMBOL_INTERNAL void* GamestateLoadingThread(void* arg) { } #endif } - data->bitmap_flags = al_get_new_bitmap_flags(); + al_store_state(&data->state, ALLEGRO_STATE_NEW_FILE_INTERFACE | ALLEGRO_STATE_NEW_BITMAP_PARAMETERS | ALLEGRO_STATE_BLENDER); + data->game->_priv.loading.in_progress = false; return NULL; } diff --git a/src/internal.h b/src/internal.h index 1107888..df57fe6 100644 --- a/src/internal.h +++ b/src/internal.h @@ -73,7 +73,7 @@ struct List { struct GamestateLoadingThreadData { struct Game* game; struct Gamestate* gamestate; - int bitmap_flags; + ALLEGRO_STATE state; }; struct ScreenshotThreadData { diff --git a/src/mainloop.c b/src/mainloop.c index 8458a73..78a10b8 100644 --- a/src/mainloop.c +++ b/src/mainloop.c @@ -349,7 +349,8 @@ static inline bool MainloopTick(struct Game* game) { game->_priv.loading.current = tmp; game->_priv.current_gamestate = tmp; - struct GamestateLoadingThreadData data = {.game = game, .gamestate = tmp, .bitmap_flags = al_get_new_bitmap_flags()}; + struct GamestateLoadingThreadData data = {.game = game, .gamestate = tmp}; + al_store_state(&data.state, ALLEGRO_STATE_NEW_FILE_INTERFACE | ALLEGRO_STATE_NEW_BITMAP_PARAMETERS | ALLEGRO_STATE_BLENDER); game->_priv.loading.in_progress = true; double time = al_get_time(); game->_priv.loading.time = time; @@ -406,7 +407,7 @@ static inline bool MainloopTick(struct Game* game) { #endif al_convert_memory_bitmaps(); - al_set_new_bitmap_flags(data.bitmap_flags); + al_restore_state(&data.state); ReloadShaders(game, false);