From 0d62e6befeb31842388478ca12f5d90a16df5c64 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 15 Mar 2023 22:52:14 +1100 Subject: [PATCH] - Exhumed: Optimise `UnlinkIgnitedAnim()` from fb97e3c6cae49d9ff34f43668593b9c089b7a02d a bit. * Bad cherry pick caused a stat iteration over the wrong stat number. * Cleaned up commentary to reflect that we have actors and not so much sprites or an anim array anymore. --- source/games/exhumed/src/anims.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/source/games/exhumed/src/anims.cpp b/source/games/exhumed/src/anims.cpp index c7ad69a39..7b20f1a3c 100644 --- a/source/games/exhumed/src/anims.cpp +++ b/source/games/exhumed/src/anims.cpp @@ -55,31 +55,25 @@ void InitAnims() } /* - Use when deleting an ignited sprite to check if any anims reference it. - Will remove the Anim's loop flag and set the source (the ignited sprite's) sprite reference to -1. - FuncAnim() will then delete the anim on next call for this anim. + Use when deleting an ignited actor to check if any actors reference it. + Will remove the actor's anim loop flag and set the source (the ignited actor's) actor target to null. + FuncAnim() will then delete the actor on next call for this actor. - Without this, the anim will hold reference to a sprite which will eventually be reused, but the anim code - will continue to manipulate its hitag value. This can break runlist records for things like LavaDude - limbs that store these in the sprite hitag. + Without this, the actor will hold reference to an actor which will prevent the GC from deleting it properly. Specifically needed for IgniteSprite() anims which can become orphaned from the source sprite (e.g a bullet) when the bullet sprite is deleted. */ void UnlinkIgnitedAnim(DExhumedActor* pActor) { - // scan the active anims (that aren't in the 'free' section of AnimsFree[]) - ExhumedStatIterator it(500); + ExhumedStatIterator it(kStatIgnited); while (auto itActor = it.Next()) { - if (itActor->spr.statnum == kStatIgnited) + // .pTarget holds the actor pointer of the source 'actor that's on fire' actor + if (pActor == itActor->pTarget) { - // .hitag holds the sprite number of the source 'sprite that's on fire' sprite - if (pActor == itActor->pTarget) - { - itActor->nAction &= ~kAnimLoop; // clear the animation loop flag - itActor->pTarget = nullptr; // set the sprite reference to -1 - } + itActor->nAction &= ~kAnimLoop; // clear the animation loop flag + itActor->pTarget = nullptr; // set the actor target to null } } }