Skip to content

Commit 0fbf3a1

Browse files
committed
Engine: fix a case when new sprite is matching object graphic property
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.
1 parent 5a94bc0 commit 0fbf3a1

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Engine/ac/dynamicsprite.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ void DynamicSprite_Resize(ScriptDynamicSprite *sds, int width, int height) {
113113
RectWH(0, 0, width, height));
114114

115115
add_dynamic_sprite(sds->slot, std::move(new_pic));
116-
game_sprite_updated(sds->slot);
117116
}
118117

119118
void DynamicSprite_Flip(ScriptDynamicSprite *sds, int direction) {
@@ -130,7 +129,6 @@ void DynamicSprite_Flip(ScriptDynamicSprite *sds, int direction) {
130129
new_pic->FlipBlt(sprite, 0, 0, flip);
131130

132131
add_dynamic_sprite(sds->slot, std::move(new_pic));
133-
game_sprite_updated(sds->slot);
134132
}
135133

136134
void DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite *sds, int sourceSprite) {
@@ -153,7 +151,6 @@ void DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite *sds, int sourceSpri
153151

154152
// set the target's alpha channel depending on the source
155153
BitmapHelper::CopyTransparency(target, source, target->GetColorDepth() == 32, source->GetColorDepth() == 32);
156-
game_sprite_updated(sds->slot);
157154
}
158155

159156
void DynamicSprite_ChangeCanvasSize(ScriptDynamicSprite *sds, int width, int height, int x, int y)
@@ -169,7 +166,6 @@ void DynamicSprite_ChangeCanvasSize(ScriptDynamicSprite *sds, int width, int hei
169166
new_pic->Blit(sprite, 0, 0, x, y, sprite->GetWidth(), sprite->GetHeight());
170167

171168
add_dynamic_sprite(sds->slot, std::move(new_pic));
172-
game_sprite_updated(sds->slot);
173169
}
174170

175171
void DynamicSprite_Crop(ScriptDynamicSprite *sds, int x1, int y1, int width, int height) {
@@ -187,7 +183,6 @@ void DynamicSprite_Crop(ScriptDynamicSprite *sds, int x1, int y1, int width, int
187183

188184
// replace the bitmap in the sprite set
189185
add_dynamic_sprite(sds->slot, std::move(new_pic));
190-
game_sprite_updated(sds->slot);
191186
}
192187

193188
void DynamicSprite_Rotate(ScriptDynamicSprite *sds, int angle, int width, int height) {
@@ -215,7 +210,6 @@ void DynamicSprite_Rotate(ScriptDynamicSprite *sds, int angle, int width, int he
215210

216211
// replace the bitmap in the sprite set
217212
add_dynamic_sprite(sds->slot, std::move(new_pic));
218-
game_sprite_updated(sds->slot);
219213
}
220214

221215
void DynamicSprite_Tint(ScriptDynamicSprite *sds, int red, int green, int blue, int saturation, int luminance)
@@ -227,7 +221,6 @@ void DynamicSprite_Tint(ScriptDynamicSprite *sds, int red, int green, int blue,
227221
tint_image(new_pic.get(), source, red, green, blue, saturation, GfxDef::Value100ToValue250(luminance));
228222

229223
add_dynamic_sprite(sds->slot, std::move(new_pic));
230-
game_sprite_updated(sds->slot);
231224
}
232225

233226
int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char* namm)
@@ -457,6 +450,11 @@ int add_dynamic_sprite(int slot, std::unique_ptr<Bitmap> image, uint32_t extra_f
457450
uint32_t flags = SPF_DYNAMICALLOC | extra_flags;
458451
if (!spriteset.SetSprite(slot, std::move(image), flags))
459452
return 0; // failed to add the sprite, bad image or realloc failed
453+
454+
// Notify a new (normal) dynamic sprite in case some objects
455+
// have this number assigned to their Graphic property
456+
if ((extra_flags & SPF_OBJECTOWNED) == 0)
457+
game_sprite_updated(slot);
460458
return slot;
461459
}
462460

Engine/ac/game.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,8 @@ void game_sprite_updated(int sprnum, bool deleted)
15951595

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

0 commit comments

Comments
 (0)