From 67ecea1a427c2720598bdc1144d48aafef93e4c8 Mon Sep 17 00:00:00 2001 From: ephphatha Date: Fri, 10 Sep 2021 18:30:47 +1000 Subject: [PATCH] Always set the monster animation when ChangeAnimationData is called Required updating AnimationInfo to handle being passed 0 for the total framecount, previously it would call clamp with min > max which was invalid. --- Source/engine/animationinfo.cpp | 6 +++++- Source/monster.h | 8 ++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index a99fdcef1..bae4f5fc6 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -166,7 +166,11 @@ void AnimationInfo::ChangeAnimationData(const CelSprite *celSprite, int numberOf { if (numberOfFrames != NumberOfFrames || ticksPerFrame != TicksPerFrame) { // Ensure that the CurrentFrame is still valid and that we disable ADL cause the calculcated values (for example TickModifier) could be wrong - CurrentFrame = clamp(CurrentFrame, 1, numberOfFrames); + if (numberOfFrames >= 1) + CurrentFrame = clamp(CurrentFrame, 1, numberOfFrames); + else + CurrentFrame = 0; + NumberOfFrames = numberOfFrames; TicksPerFrame = ticksPerFrame; TicksSinceSequenceStarted = 0; diff --git a/Source/monster.h b/Source/monster.h index fb6859b4b..779e1e393 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -229,12 +229,8 @@ struct Monster { // note: missing field _mAFNum auto &animationData = this->MType->GetAnimData(graphic); auto &celSprite = animationData.GetCelSpritesForDirection(direction); - if (celSprite) { - // Passing the Frames and Rate properties here is only relevant when initialising a monster, but doesn't cause any harm when switching animations. - this->AnimInfo.ChangeAnimationData(&*celSprite, animationData.Frames, animationData.Rate); - } - // This function is called during level load for some monsters without animations, in those cases AnimInfo is default initialised - // with zero/nullptr values for all the properties ChangeAnimationData would otherwise set. + // Passing the Frames and Rate properties here is only relevant when initialising a monster, but doesn't cause any harm when switching animations. + this->AnimInfo.ChangeAnimationData(celSprite ? &*celSprite : nullptr, animationData.Frames, animationData.Rate); } /**