From a295586636626c8d2091b2a04351b2ccfd88e65d Mon Sep 17 00:00:00 2001 From: obligaron Date: Wed, 19 May 2021 11:13:13 +0200 Subject: [PATCH] Support changing animation data on-the-fly even if the number of frames differ --- Source/engine/animationinfo.cpp | 16 ++++++++++++++++ Source/engine/animationinfo.h | 8 ++++++++ Source/items.cpp | 9 ++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 52ee177d8..efaeedd63 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -154,6 +154,22 @@ void AnimationInfo::SetNewAnimation(byte *pData, int numberOfFrames, int delayLe } } +void AnimationInfo::ChangeAnimationData(byte *pData, int numberOfFrames, int delayLen) +{ + if (numberOfFrames != NumberOfFrames || delayLen != DelayLen) { + // Ensure that the CurrentFrame is still valid and that we disable ADL cause the calculcated values (for example TickModifier) could be wrong + if (CurrentFrame > numberOfFrames) + CurrentFrame = numberOfFrames; + NumberOfFrames = numberOfFrames; + DelayLen = delayLen; + TicksSinceSequenceStarted = 0; + RelevantFramesForDistributing = 0; + TickModifier = 0.0f; + } + this->pData = pData; + DelayLen = delayLen; +} + void AnimationInfo::ProcessAnimation() { DelayCounter++; diff --git a/Source/engine/animationinfo.h b/Source/engine/animationinfo.h index b1db43b47..dd61f9c50 100644 --- a/Source/engine/animationinfo.h +++ b/Source/engine/animationinfo.h @@ -79,6 +79,14 @@ public: */ void SetNewAnimation(byte *pData, int numberOfFrames, int delayLen, AnimationDistributionFlags flags = AnimationDistributionFlags::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0); + /** + * @brief Changes the Animation Data on-the-fly. This is needed if a animation is currently in progress and the player changes his gear. + * @param pData Pointer to Animation Data + * @param numberOfFrames Number of Frames in Animation + * @param delayLen Delay after each Animation sequence + */ + void ChangeAnimationData(byte *pData, int numberOfFrames, int delayLen); + /* * @brief Process the Animation for a game tick (for example advances the frame) */ diff --git a/Source/items.cpp b/Source/items.cpp index 0ff3524b1..0bf50103b 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -883,8 +883,15 @@ void CalcPlrItemVals(int playerId, bool Loadgfx) if (player._pgfxnum != g && Loadgfx) { player._pgfxnum = g; player._pGFXLoad = 0; - LoadPlrGFX(playerId, static_cast(PFILE_STAND | PFILE_WALK)); SetPlrAnims(player); + LoadPlrGFX(playerId, static_cast(PFILE_STAND | PFILE_WALK)); + if (player._pmode == PM_STAND) { + player._pAnimWidth = player._pNWidth; + player.AnimInfo.ChangeAnimationData(player._pNAnim[player._pdir], player._pNFrames, 3); + } else { + player._pAnimWidth = player._pWWidth; + player.AnimInfo.ChangeAnimationData(player._pWAnim[player._pdir], player._pWFrames, 0); + } } else { player._pgfxnum = g; }