Browse Source

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.
pull/2845/head
ephphatha 5 years ago committed by Anders Jenbo
parent
commit
67ecea1a42
  1. 6
      Source/engine/animationinfo.cpp
  2. 8
      Source/monster.h

6
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;

8
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);
}
/**

Loading…
Cancel
Save