From 49628de381e52e52d1ae1ca039926ffd1a0f5390 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 5 Jul 2018 19:38:31 +0200 Subject: [PATCH] LoadSpritesheets: call progress function after each spritesheet --- src/character.c | 5 ++++- src/character.h | 2 +- src/internal.c | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/character.c b/src/character.c index deca718..5d2dfe1 100644 --- a/src/character.c +++ b/src/character.c @@ -98,7 +98,7 @@ SYMBOL_EXPORT struct Spritesheet* GetSpritesheet(struct Game* game, struct Chara return NULL; } -SYMBOL_EXPORT void LoadSpritesheets(struct Game* game, struct Character* character) { +SYMBOL_EXPORT void LoadSpritesheets(struct Game* game, struct Character* character, void (*progress)(struct Game*)) { PrintConsole(game, "Loading spritesheets for character %s...", character->name); struct Spritesheet* tmp = character->spritesheets; while (tmp) { @@ -130,6 +130,9 @@ SYMBOL_EXPORT void LoadSpritesheets(struct Game* game, struct Character* charact tmp->frames[i].bitmap = al_create_sub_bitmap(tmp->bitmap, tmp->frames[i].col * tmp->width, tmp->frames[i].row * tmp->height, tmp->width, tmp->height); } } + if (progress) { + progress(game); + } tmp = tmp->next; } diff --git a/src/character.h b/src/character.h index a0e6787..3bab901 100644 --- a/src/character.h +++ b/src/character.h @@ -124,7 +124,7 @@ void DrawScaledCharacter(struct Game* game, struct Character* character, ALLEGRO struct Character* CreateCharacter(struct Game* game, char* name); void DestroyCharacter(struct Game* game, struct Character* character); -void LoadSpritesheets(struct Game* game, struct Character* character); +void LoadSpritesheets(struct Game* game, struct Character* character, void (*progress)(struct Game*)); void UnloadSpritesheets(struct Game* game, struct Character* character); void AnimateCharacter(struct Game* game, struct Character* character, float delta, float speed_modifier); diff --git a/src/internal.c b/src/internal.c index cb414de..0b7901c 100644 --- a/src/internal.c +++ b/src/internal.c @@ -250,6 +250,7 @@ SYMBOL_INTERNAL void GamestateProgress(struct Game* game) { PrintConsole(game, "[%s] Progress: %d%% (%d/%d)", tmp->name, (int)(progress * 100), game->_priv.loading.progress, *(tmp->api->Gamestate_ProgressCount)); } #ifndef LIBSUPERDERPY_SINGLE_THREAD + // TODO: debounce thread synchronization to reduce overhead al_lock_mutex(game->_priv.texture_sync_mutex); game->_priv.texture_sync = true; while (game->_priv.texture_sync) { @@ -257,6 +258,7 @@ SYMBOL_INTERNAL void GamestateProgress(struct Game* game) { } al_unlock_mutex(game->_priv.texture_sync_mutex); #else + al_convert_memory_bitmaps(); DrawGamestates(game); double delta = al_get_time() - game->_priv.loading.time; if (tmp->showLoading) {