From 016c482154b7f96653232b9b9a86d68e80e06f29 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Sat, 23 Jun 2018 04:44:36 +0200 Subject: [PATCH] convert bitmaps to video textures on every progress() when loading gamestate in threaded mode --- src/internal.c | 8 ++++++++ src/libsuperderpy.c | 13 ++++++++++++- src/libsuperderpy.h | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/internal.c b/src/internal.c index cd16b29..6041a30 100644 --- a/src/internal.c +++ b/src/internal.c @@ -249,6 +249,14 @@ SYMBOL_INTERNAL void GamestateProgress(struct Game* game) { if (game->config.debug) { PrintConsole(game, "[%s] Progress: %d%% (%d/%d)", tmp->name, (int)(progress * 100), game->_priv.loading.progress, *(tmp->api->Gamestate_ProgressCount)); } +#ifndef LIBSUPERDERPY_SINGLE_THREAD + al_lock_mutex(game->_priv.texture_sync_mutex); + game->_priv.texture_sync = true; + while (game->_priv.texture_sync) { + al_wait_cond(game->_priv.texture_sync_cond, game->_priv.texture_sync_mutex); + } + al_unlock_mutex(game->_priv.texture_sync_mutex); +#endif #ifdef LIBSUPERDERPY_SINGLE_THREAD DrawGamestates(game); double delta = al_get_time() - game->_priv.loading.time; diff --git a/src/libsuperderpy.c b/src/libsuperderpy.c index 74d14b3..c8ac7bb 100644 --- a/src/libsuperderpy.c +++ b/src/libsuperderpy.c @@ -85,6 +85,10 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char* game->handlers.predraw = NULL; game->handlers.postdraw = NULL; + game->_priv.texture_sync = false; + game->_priv.texture_sync_cond = al_create_cond(); + game->_priv.texture_sync_mutex = al_create_mutex(); + game->config.fullscreen = strtol(GetConfigOptionDefault(game, "SuperDerpy", "fullscreen", "1"), NULL, 10); game->config.music = strtol(GetConfigOptionDefault(game, "SuperDerpy", "music", "10"), NULL, 10); game->config.voice = strtol(GetConfigOptionDefault(game, "SuperDerpy", "voice", "10"), NULL, 10); @@ -412,15 +416,20 @@ SYMBOL_INTERNAL void libsuperderpy_mainloop(void* g) { (*game->_priv.loading.gamestate->api->Gamestate_Draw)(game, game->_priv.loading.gamestate->data); } game->_priv.loading.time += delta; + if (game->_priv.texture_sync) { + al_convert_memory_bitmaps(); + game->_priv.texture_sync = false; + al_signal_cond(game->_priv.texture_sync_cond); + } DrawConsole(game); al_flip_display(); } #else GamestateLoadingThread(&data); + al_convert_memory_bitmaps(); #endif al_set_new_bitmap_flags(data.bitmap_flags); - al_convert_memory_bitmaps(); ReloadShaders(game, false); game->_priv.loading.loaded++; @@ -666,6 +675,8 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) { al_destroy_mixer(game->audio.music); al_destroy_mixer(game->audio.mixer); al_destroy_voice(game->audio.v); + al_destroy_cond(game->_priv.texture_sync_cond); + al_destroy_mutex(game->_priv.texture_sync_mutex); al_uninstall_audio(); DeinitConfig(game); #ifndef __EMSCRIPTEN__ diff --git a/src/libsuperderpy.h b/src/libsuperderpy.h index 7a5708f..fc1f091 100644 --- a/src/libsuperderpy.h +++ b/src/libsuperderpy.h @@ -137,6 +137,10 @@ struct Game { bool paused; + volatile bool texture_sync; + ALLEGRO_MUTEX* texture_sync_mutex; + ALLEGRO_COND* texture_sync_cond; + #ifdef ALLEGRO_MACOSX char cwd[MAXPATHLEN]; #endif