Skip to content

Commit

Permalink
Engine: fix a case when new sprite is matching object graphic property
Browse files Browse the repository at this point in the history
Another problem with dynamic sprite since 3.6.1...
Case:
- an object has a dynamic sprite assigned;
- dynamic sprite gets deleted, object redrawn, its texture updated etc, all good (displays safe placeholder);
- new dynamic sprite created, with same index by coincidence, and assigned to the object;
- object fails to redraw, because sprite's number is the same as saved in property value, and there's no notification on sprite *creation*.

Solution:
- make a "sprite updated" notification on sprite creation too.
  • Loading branch information
ivan-mogilko committed Feb 25, 2025
1 parent 5068a6a commit 030ebf9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Engine/ac/dynamicsprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ void DynamicSprite_Resize(ScriptDynamicSprite *sds, int width, int height) {
RectWH(0, 0, width, height));

add_dynamic_sprite(sds->slot, std::move(new_pic), (game.SpriteInfos[sds->slot].Flags & SPF_ALPHACHANNEL) != 0);
game_sprite_updated(sds->slot);
}

void DynamicSprite_Flip(ScriptDynamicSprite *sds, int direction) {
Expand All @@ -129,7 +128,6 @@ void DynamicSprite_Flip(ScriptDynamicSprite *sds, int direction) {
new_pic->FlipBlt(sprite, 0, 0, static_cast<GraphicFlip>(direction));

add_dynamic_sprite(sds->slot, std::move(new_pic), (game.SpriteInfos[sds->slot].Flags & SPF_ALPHACHANNEL) != 0);
game_sprite_updated(sds->slot);
}

void DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite *sds, int sourceSprite) {
Expand Down Expand Up @@ -160,7 +158,6 @@ void DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite *sds, int sourceSpri
}

BitmapHelper::CopyTransparency(target, source, dst_has_alpha, src_has_alpha);
game_sprite_updated(sds->slot);
}

void DynamicSprite_ChangeCanvasSize(ScriptDynamicSprite *sds, int width, int height, int x, int y)
Expand All @@ -179,7 +176,6 @@ void DynamicSprite_ChangeCanvasSize(ScriptDynamicSprite *sds, int width, int hei
new_pic->Blit(sprite, 0, 0, x, y, sprite->GetWidth(), sprite->GetHeight());

add_dynamic_sprite(sds->slot, std::move(new_pic), (game.SpriteInfos[sds->slot].Flags & SPF_ALPHACHANNEL) != 0);
game_sprite_updated(sds->slot);
}

void DynamicSprite_Crop(ScriptDynamicSprite *sds, int x1, int y1, int width, int height) {
Expand All @@ -200,7 +196,6 @@ void DynamicSprite_Crop(ScriptDynamicSprite *sds, int x1, int y1, int width, int

// replace the bitmap in the sprite set
add_dynamic_sprite(sds->slot, std::move(new_pic), (game.SpriteInfos[sds->slot].Flags & SPF_ALPHACHANNEL) != 0);
game_sprite_updated(sds->slot);
}

void DynamicSprite_Rotate(ScriptDynamicSprite *sds, int angle, int width, int height) {
Expand Down Expand Up @@ -231,7 +226,6 @@ void DynamicSprite_Rotate(ScriptDynamicSprite *sds, int angle, int width, int he

// replace the bitmap in the sprite set
add_dynamic_sprite(sds->slot, std::move(new_pic), (game.SpriteInfos[sds->slot].Flags & SPF_ALPHACHANNEL) != 0);
game_sprite_updated(sds->slot);
}

void DynamicSprite_Tint(ScriptDynamicSprite *sds, int red, int green, int blue, int saturation, int luminance)
Expand All @@ -243,7 +237,6 @@ void DynamicSprite_Tint(ScriptDynamicSprite *sds, int red, int green, int blue,
tint_image(new_pic.get(), source, red, green, blue, saturation, (luminance * 25) / 10);

add_dynamic_sprite(sds->slot, std::move(new_pic), (game.SpriteInfos[sds->slot].Flags & SPF_ALPHACHANNEL) != 0);
game_sprite_updated(sds->slot);
}

int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char* namm)
Expand Down Expand Up @@ -451,6 +444,11 @@ int add_dynamic_sprite(int slot, std::unique_ptr<Bitmap> image, bool has_alpha,
uint32_t flags = SPF_DYNAMICALLOC | (SPF_ALPHACHANNEL * has_alpha) | extra_flags;
if (!spriteset.SetSprite(slot, std::move(image), flags))
return 0; // failed to add the sprite, bad image or realloc failed

// Notify a new (normal) dynamic sprite in case some objects
// have this number assigned to their Graphic property
if ((extra_flags & SPF_OBJECTOWNED) == 0)
game_sprite_updated(slot);
return slot;
}

Expand Down
2 changes: 2 additions & 0 deletions Engine/ac/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ void game_sprite_updated(int sprnum, bool deleted)

// GUI still have a special draw route, so cannot rely on object caches;
// will have to do a per-GUI and per-control check.
// TODO: devise a way to speed this iteration up, perhaps link GUI objects
// to the sprite notification block somehow, etc...?
//
// gui backgrounds
for (auto &gui : guis)
Expand Down

0 comments on commit 030ebf9

Please sign in to comment.