Skip to content

Commit 030ebf9

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 5068a6a commit 030ebf9

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
@@ -111,7 +111,6 @@ void DynamicSprite_Resize(ScriptDynamicSprite *sds, int width, int height) {
111111
RectWH(0, 0, width, height));
112112

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

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

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

135133
void DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite *sds, int sourceSprite) {
@@ -160,7 +158,6 @@ void DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite *sds, int sourceSpri
160158
}
161159

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

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

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

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

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

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

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

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

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

249242
int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char* namm)
@@ -451,6 +444,11 @@ int add_dynamic_sprite(int slot, std::unique_ptr<Bitmap> image, bool has_alpha,
451444
uint32_t flags = SPF_DYNAMICALLOC | (SPF_ALPHACHANNEL * has_alpha) | extra_flags;
452445
if (!spriteset.SetSprite(slot, std::move(image), flags))
453446
return 0; // failed to add the sprite, bad image or realloc failed
447+
448+
// Notify a new (normal) dynamic sprite in case some objects
449+
// have this number assigned to their Graphic property
450+
if ((extra_flags & SPF_OBJECTOWNED) == 0)
451+
game_sprite_updated(slot);
454452
return slot;
455453
}
456454

Engine/ac/game.cpp

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

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

0 commit comments

Comments
 (0)