mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-12 20:18:00 +01:00
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:
parent
79bcc96d9b
commit
7cb7c361f0
2 changed files with 13 additions and 4 deletions
|
@ -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));
|
||||
|
|
|
@ -41,6 +41,7 @@ struct SpritesheetFrame {
|
|||
bool start;
|
||||
bool end;
|
||||
bool shared;
|
||||
bool owned;
|
||||
|
||||
struct {
|
||||
ALLEGRO_BITMAP* image;
|
||||
|
|
Loading…
Reference in a new issue