character: Pass current frame number to animation stream callback

Without that there's no way to restart an already running animation.
This commit is contained in:
Sebastian Krzyszkowiak 2020-03-19 04:29:33 +01:00
parent 5476be3631
commit 5f4f5bafaf
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 5 additions and 5 deletions

View file

@ -60,7 +60,7 @@ SYMBOL_EXPORT void SelectSpritesheet(struct Game* game, struct Character* charac
free(character->frame); free(character->frame);
} }
character->frame = calloc(1, sizeof(struct SpritesheetFrame)); 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)); 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); 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)); spritesheet->frames = calloc(size, sizeof(struct SpritesheetFrame));
while (true) { while (true) {
PrintConsole(game, " - frame %d", i); 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) { if (!spritesheet->frames[i].owned) {
spritesheet->frames[i].bitmap = al_clone_bitmap(spritesheet->frames[i].bitmap); 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); al_destroy_bitmap(character->frame->_priv.image);
free(character->frame); free(character->frame);
character->frame = calloc(1, sizeof(struct SpritesheetFrame)); 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)); 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 { } else {

View file

@ -49,8 +49,8 @@ struct SpritesheetFrame {
} _priv; } _priv;
}; };
typedef struct SpritesheetFrame SpritesheetStream(struct Game*, double, void*); typedef struct SpritesheetFrame SpritesheetStream(struct Game*, double, int, void*);
#define SPRITESHEET_STREAM(x) struct SpritesheetFrame x(struct Game* game, double delta, void* data) #define SPRITESHEET_STREAM(x) struct SpritesheetFrame x(struct Game* game, double delta, int frame, void* data)
typedef void SpritesheetStreamDestructor(struct Game*, void*); typedef void SpritesheetStreamDestructor(struct Game*, void*);
#define SPRITESHEET_STREAM_DESCTRUCTOR(x) void x(struct Game* game, void* data) #define SPRITESHEET_STREAM_DESCTRUCTOR(x) void x(struct Game* game, void* data)