character: Add ability for a streamed frame bitmap to be owned by API user

In such case we won't try to free it.
This commit is contained in:
Sebastian Krzyszkowiak 2020-03-18 06:16:34 +01:00
parent 79bcc96d9b
commit 7cb7c361f0
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 13 additions and 4 deletions

View file

@ -53,7 +53,9 @@ SYMBOL_EXPORT void SelectSpritesheet(struct Game* game, struct Character* charac
character->reversing = tmp->reversed ^ reversed; character->reversing = tmp->reversed ^ reversed;
if (tmp->stream) { if (tmp->stream) {
if (character->spritesheet && character->spritesheet->stream && character->frame) { if (character->spritesheet && character->spritesheet->stream && character->frame) {
al_destroy_bitmap(character->frame->bitmap); if (character->frame->owned) {
al_destroy_bitmap(character->frame->bitmap);
}
al_destroy_bitmap(character->frame->_priv.image); al_destroy_bitmap(character->frame->_priv.image);
free(character->frame); free(character->frame);
} }
@ -175,7 +177,9 @@ SYMBOL_EXPORT void UnloadSpritesheets(struct Game* game, struct Character* chara
if (tmp->frames[i]._priv.filepath) { if (tmp->frames[i]._priv.filepath) {
RemoveBitmap(game, tmp->frames[i]._priv.filepath); RemoveBitmap(game, tmp->frames[i]._priv.filepath);
} else { } else {
al_destroy_bitmap(tmp->frames[i].bitmap); if (tmp->frames[i].owned) {
al_destroy_bitmap(tmp->frames[i].bitmap);
}
} }
al_destroy_bitmap(tmp->frames[i]._priv.image); al_destroy_bitmap(tmp->frames[i]._priv.image);
} }
@ -515,7 +519,9 @@ SYMBOL_EXPORT void DestroyCharacter(struct Game* game, struct Character* charact
if (character->spritesheet && character->spritesheet->stream) { if (character->spritesheet && character->spritesheet->stream) {
if (character->frame) { if (character->frame) {
al_destroy_bitmap(character->frame->bitmap); if (character->frame->owned) {
al_destroy_bitmap(character->frame->bitmap);
}
al_destroy_bitmap(character->frame->_priv.image); al_destroy_bitmap(character->frame->_priv.image);
free(character->frame); free(character->frame);
} }
@ -679,7 +685,9 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
if (!reachedEnd && pos != character->pos) { if (!reachedEnd && pos != character->pos) {
pos = character->pos; pos = character->pos;
double duration = character->frame->duration; double duration = character->frame->duration;
al_destroy_bitmap(character->frame->bitmap); if (character->frame->owned) {
al_destroy_bitmap(character->frame->bitmap);
}
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));

View file

@ -41,6 +41,7 @@ struct SpritesheetFrame {
bool start; bool start;
bool end; bool end;
bool shared; bool shared;
bool owned;
struct { struct {
ALLEGRO_BITMAP* image; ALLEGRO_BITMAP* image;