LoadSpritesheets: call progress function after each spritesheet

This commit is contained in:
Sebastian Krzyszkowiak 2018-07-05 19:38:31 +02:00
parent ab8dc0f143
commit 49628de381
3 changed files with 7 additions and 2 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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) {