diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 45d4fced4..524fe3895 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -81,7 +81,7 @@ void AnimationInfo::SetNewAnimation(uint8_t *pData, int numberOfFrames, int dela if (params == AnimationDistributionParams::ProcessAnimationPending) { // If ProcessAnimation will be called after SetNewAnimation (in same GameTick as NewPlrAnim), we increment the Animation-Counter. - // If no delay is specified, this will result in complete skipped frame (see ProcessPlayerAnimation). + // If no delay is specified, this will result in complete skipped frame (see ProcessAnimation). // But if we have a delay specified, this would only result in a reduced time the first frame is shown (one skipped delay). // Because of that, we only the remove one GameTick from the time the Animation is shown relevantAnimationGameTicksWithSkipping -= 1; @@ -122,4 +122,18 @@ void AnimationInfo::SetNewAnimation(uint8_t *pData, int numberOfFrames, int dela } } +void AnimationInfo::ProcessAnimation() +{ + DelayCounter++; + GameTicksSinceSequenceStarted++; + if (DelayCounter > DelayLen) { + DelayCounter = 0; + CurrentFrame++; + if (CurrentFrame > NumberOfFrames) { + CurrentFrame = 1; + GameTicksSinceSequenceStarted = 0; + } + } +} + } // namespace devilution diff --git a/Source/engine/animationinfo.h b/Source/engine/animationinfo.h index 2b9c639ec..ecc34ec54 100644 --- a/Source/engine/animationinfo.h +++ b/Source/engine/animationinfo.h @@ -67,6 +67,12 @@ public: */ void SetNewAnimation(uint8_t *pData, int numberOfFrames, int delayLen, AnimationDistributionParams params = AnimationDistributionParams::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0); + /* + * @brief Process the Animation for a GameTick (for example advances the frame) + */ + void ProcessAnimation(); + +private: /* * @brief Specifies how many animations-fractions are displayed between two gameticks. this can be > 0, if animations are skipped or < 0 if the same animation is shown in multiple times (delay specified). */ diff --git a/Source/player.cpp b/Source/player.cpp index 01556377d..868a6dc5a 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3637,21 +3637,7 @@ void ProcessPlayers() CheckNewPath(pnum); } while (tplayer); - ProcessPlayerAnimation(pnum); - } - } -} - -void ProcessPlayerAnimation(int pnum) -{ - plr[pnum].AnimInfo.DelayCounter++; - plr[pnum].AnimInfo.GameTicksSinceSequenceStarted++; - if (plr[pnum].AnimInfo.DelayCounter > plr[pnum].AnimInfo.DelayLen) { - plr[pnum].AnimInfo.DelayCounter = 0; - plr[pnum].AnimInfo.CurrentFrame++; - if (plr[pnum].AnimInfo.CurrentFrame > plr[pnum].AnimInfo.FrameLen) { - plr[pnum].AnimInfo.CurrentFrame = 1; - plr[pnum].AnimInfo.GameTicksSinceSequenceStarted = 0; + plr[pnum].AnimInfo.ProcessAnimation(); } } } diff --git a/Source/player.h b/Source/player.h index 56538f142..e8678c4f6 100644 --- a/Source/player.h +++ b/Source/player.h @@ -398,7 +398,6 @@ void FreePlayerGFX(int pnum); */ void NewPlrAnim(int pnum, BYTE *pData, int numberOfFrames, int delayLen, int width, AnimationDistributionParams params = AnimationDistributionParams::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0); void SetPlrAnims(int pnum); -void ProcessPlayerAnimation(int pnum); void CreatePlayer(int pnum, HeroClass c); int CalcStatDiff(int pnum); #ifdef _DEBUG diff --git a/test/animationinfo_test.cpp b/test/animationinfo_test.cpp index e1eaaa4f3..1f37f58eb 100644 --- a/test/animationinfo_test.cpp +++ b/test/animationinfo_test.cpp @@ -63,7 +63,7 @@ void RunAnimationTest(int numFrames, int delay, AnimationDistributionParams para currentGameTick += 1; if (gameTickData->_FramesToSkip != 0) pPlayer->AnimInfo.CurrentFrame += gameTickData->_FramesToSkip; - ProcessPlayerAnimation(pnum); + pPlayer->AnimInfo.ProcessAnimation(); EXPECT_EQ(pPlayer->AnimInfo.CurrentFrame, gameTickData->_ExpectedAnimationFrame); EXPECT_EQ(pPlayer->AnimInfo.DelayCounter, gameTickData->_ExpectedAnimationCnt); }