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

View file

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