From 5f4f5bafaf2125077c37ff2bf19eb513b374487c Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 19 Mar 2020 04:29:33 +0100 Subject: [PATCH] character: Pass current frame number to animation stream callback Without that there's no way to restart an already running animation. --- src/character.c | 6 +++--- src/character.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/character.c b/src/character.c index 5865a64..d6679fb 100644 --- a/src/character.c +++ b/src/character.c @@ -60,7 +60,7 @@ SYMBOL_EXPORT void SelectSpritesheet(struct Game* game, struct Character* charac free(character->frame); } character->frame = calloc(1, sizeof(struct SpritesheetFrame)); - *(character->frame) = tmp->stream(game, 0.0, tmp->stream_data); + *(character->frame) = tmp->stream(game, 0.0, character->pos, tmp->stream_data); character->frame->_priv.image = al_create_sub_bitmap(character->frame->bitmap, character->frame->sx * tmp->scale, character->frame->sy * tmp->scale, (character->frame->sw > 0) ? (character->frame->sw * tmp->scale) : al_get_bitmap_width(character->frame->bitmap), (character->frame->sh > 0) ? (character->frame->sh * tmp->scale) : al_get_bitmap_height(character->frame->bitmap)); tmp->width = al_get_bitmap_width(character->frame->bitmap); @@ -228,7 +228,7 @@ SYMBOL_EXPORT void PreloadStreamedSpritesheet(struct Game* game, struct Characte spritesheet->frames = calloc(size, sizeof(struct SpritesheetFrame)); while (true) { PrintConsole(game, " - frame %d", i); - spritesheet->frames[i] = spritesheet->stream(game, delta, spritesheet->stream_data); + spritesheet->frames[i] = spritesheet->stream(game, delta, i, spritesheet->stream_data); if (!spritesheet->frames[i].owned) { spritesheet->frames[i].bitmap = al_clone_bitmap(spritesheet->frames[i].bitmap); @@ -696,7 +696,7 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact al_destroy_bitmap(character->frame->_priv.image); free(character->frame); character->frame = calloc(1, sizeof(struct SpritesheetFrame)); - *(character->frame) = character->spritesheet->stream(game, duration, character->spritesheet->stream_data); + *(character->frame) = character->spritesheet->stream(game, duration, pos, character->spritesheet->stream_data); character->frame->_priv.image = al_create_sub_bitmap(character->frame->bitmap, character->frame->sx * character->spritesheet->scale, character->frame->sy * character->spritesheet->scale, (character->frame->sw > 0) ? (character->frame->sw * character->spritesheet->scale) : al_get_bitmap_width(character->frame->bitmap), (character->frame->sh > 0) ? (character->frame->sh * character->spritesheet->scale) : al_get_bitmap_height(character->frame->bitmap)); } } else { diff --git a/src/character.h b/src/character.h index 61d8f84..7950546 100644 --- a/src/character.h +++ b/src/character.h @@ -49,8 +49,8 @@ struct SpritesheetFrame { } _priv; }; -typedef struct SpritesheetFrame SpritesheetStream(struct Game*, double, void*); -#define SPRITESHEET_STREAM(x) struct SpritesheetFrame x(struct Game* game, double delta, void* data) +typedef struct SpritesheetFrame SpritesheetStream(struct Game*, double, int, void*); +#define SPRITESHEET_STREAM(x) struct SpritesheetFrame x(struct Game* game, double delta, int frame, void* data) typedef void SpritesheetStreamDestructor(struct Game*, void*); #define SPRITESHEET_STREAM_DESCTRUCTOR(x) void x(struct Game* game, void* data)