Browse Source

Move ProcessPlayerAnimation to AnimationInfo

pull/1753/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
ff995adc2b
  1. 16
      Source/engine/animationinfo.cpp
  2. 6
      Source/engine/animationinfo.h
  3. 16
      Source/player.cpp
  4. 1
      Source/player.h
  5. 2
      test/animationinfo_test.cpp

16
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

6
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).
*/

16
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();
}
}
}

1
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

2
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);
}

Loading…
Cancel
Save