Browse Source

Support changing animation data on-the-fly even if the number of frames differ

pull/2024/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
a295586636
  1. 16
      Source/engine/animationinfo.cpp
  2. 8
      Source/engine/animationinfo.h
  3. 9
      Source/items.cpp

16
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++;

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

9
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<player_graphic>(PFILE_STAND | PFILE_WALK));
SetPlrAnims(player);
LoadPlrGFX(playerId, static_cast<player_graphic>(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;
}

Loading…
Cancel
Save