From b1ee8c00b33aca4a92a4388ff5116cb4f6143941 Mon Sep 17 00:00:00 2001 From: obligaron Date: Sat, 24 Apr 2021 09:55:54 +0200 Subject: [PATCH] change AnimationDistributionFlags to enum class and rename to AnimationDistributionParams --- Source/player.cpp | 22 +++++++++++----------- Source/player.h | 10 +++++----- test/animationinformation_test.cpp | 16 ++++++++-------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Source/player.cpp b/Source/player.cpp index 68d6788f3..30c88cfb6 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -545,7 +545,7 @@ void FreePlayerGFX(int pnum) plr[pnum]._pGFXLoad = 0; } -void NewPlrAnim(int pnum, BYTE *Peq, int numFrames, int Delay, int width, AnimationDistributionFlags flags /*= AnimationDistributionFlags::None*/, int numSkippedFrames /*= 0*/, int distributeFramesBeforeFrame /*= 0*/) +void NewPlrAnim(int pnum, BYTE *Peq, int numFrames, int Delay, int width, AnimationDistributionParams params /*= AnimationDistributionParams::None*/, int numSkippedFrames /*= 0*/, int distributeFramesBeforeFrame /*= 0*/) { if ((DWORD)pnum >= MAX_PLRS) { app_fatal("NewPlrAnim: illegal player %d", pnum); @@ -562,7 +562,7 @@ void NewPlrAnim(int pnum, BYTE *Peq, int numFrames, int Delay, int width, Animat plr[pnum]._pAnimRelevantAnimationFramesForDistributing = 0; plr[pnum]._pAnimGameTickModifier = 0.0f; - if (numSkippedFrames != 0 || flags != AnimationDistributionFlags::None) { + if (numSkippedFrames != 0 || params != AnimationDistributionParams::None) { // Animation Frames that will be adjusted for the skipped Frames/GameTicks int relevantAnimationFramesForDistributing = numFrames; if (distributeFramesBeforeFrame != 0) { @@ -582,7 +582,7 @@ void NewPlrAnim(int pnum, BYTE *Peq, int numFrames, int Delay, int width, Animat // How many GameTicks will the Animation be really shown (skipped Frames and GameTicks removed) int relevantAnimationGameTicksWithSkipping = relevantAnimationGameTicksForDistribution - (numSkippedFrames * gameTicksPerFrame); - if ((flags & AnimationDistributionFlags::ProcessAnimationPending) == AnimationDistributionFlags::ProcessAnimationPending) { + if (params == AnimationDistributionParams::ProcessAnimationPending) { // If ProcessAnimation will be called after NewPlrAnim (in same GameTick as NewPlrAnim), we increment the Animation-Counter. // If no delay is specified, this will result in complete skipped frame (see ProcessPlayerAnimation). // But if we have a delay specified, this would only result in a reduced time the first frame is shown (one skipped delay). @@ -594,7 +594,7 @@ void NewPlrAnim(int pnum, BYTE *Peq, int numFrames, int Delay, int width, Animat plr[pnum]._pAnimGameTicksSinceSequenceStarted = -1; } - if ((flags & AnimationDistributionFlags::SkipsDelayOfLastFrame) == AnimationDistributionFlags::SkipsDelayOfLastFrame) { + if (params == AnimationDistributionParams::SkipsDelayOfLastFrame) { // The logic for player/monster/... (not ProcessAnimation) only checks the frame not the delay. // That means if a delay is specified, the last-frame is shown less then the other frames // Example: @@ -1593,7 +1593,7 @@ void StartAttack(int pnum, direction d) skippedAnimationFrames += 2; } - NewPlrAnim(pnum, plr[pnum]._pAAnim[d], plr[pnum]._pAFrames, 0, plr[pnum]._pAWidth, AnimationDistributionFlags::ProcessAnimationPending, skippedAnimationFrames, plr[pnum]._pAFNum); + NewPlrAnim(pnum, plr[pnum]._pAAnim[d], plr[pnum]._pAFrames, 0, plr[pnum]._pAWidth, AnimationDistributionParams::ProcessAnimationPending, skippedAnimationFrames, plr[pnum]._pAFNum); plr[pnum]._pmode = PM_ATTACK; FixPlayerLocation(pnum, d); SetPlayerOld(pnum); @@ -1621,7 +1621,7 @@ void StartRangeAttack(int pnum, direction d, int cx, int cy) } } - NewPlrAnim(pnum, plr[pnum]._pAAnim[d], plr[pnum]._pAFrames, 0, plr[pnum]._pAWidth, AnimationDistributionFlags::ProcessAnimationPending, skippedAnimationFrames, plr[pnum]._pAFNum); + NewPlrAnim(pnum, plr[pnum]._pAAnim[d], plr[pnum]._pAFrames, 0, plr[pnum]._pAWidth, AnimationDistributionParams::ProcessAnimationPending, skippedAnimationFrames, plr[pnum]._pAFNum); plr[pnum]._pmode = PM_RATTACK; FixPlayerLocation(pnum, d); @@ -1652,7 +1652,7 @@ void StartPlrBlock(int pnum, direction dir) skippedAnimationFrames = (plr[pnum]._pBFrames - 2); // ISPL_FASTBLOCK means we cancel the animation if frame 2 was shown } - NewPlrAnim(pnum, plr[pnum]._pBAnim[dir], plr[pnum]._pBFrames, 2, plr[pnum]._pBWidth, AnimationDistributionFlags::SkipsDelayOfLastFrame, skippedAnimationFrames); + NewPlrAnim(pnum, plr[pnum]._pBAnim[dir], plr[pnum]._pBFrames, 2, plr[pnum]._pBWidth, AnimationDistributionParams::SkipsDelayOfLastFrame, skippedAnimationFrames); plr[pnum]._pmode = PM_BLOCK; FixPlayerLocation(pnum, dir); @@ -1675,19 +1675,19 @@ void StartSpell(int pnum, direction d, int cx, int cy) if ((plr[pnum]._pGFXLoad & PFILE_FIRE) == 0) { LoadPlrGFX(pnum, PFILE_FIRE); } - NewPlrAnim(pnum, plr[pnum]._pFAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth, AnimationDistributionFlags::ProcessAnimationPending); + NewPlrAnim(pnum, plr[pnum]._pFAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth, AnimationDistributionParams::ProcessAnimationPending); break; case STYPE_LIGHTNING: if ((plr[pnum]._pGFXLoad & PFILE_LIGHTNING) == 0) { LoadPlrGFX(pnum, PFILE_LIGHTNING); } - NewPlrAnim(pnum, plr[pnum]._pLAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth, AnimationDistributionFlags::ProcessAnimationPending); + NewPlrAnim(pnum, plr[pnum]._pLAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth, AnimationDistributionParams::ProcessAnimationPending); break; case STYPE_MAGIC: if ((plr[pnum]._pGFXLoad & PFILE_MAGIC) == 0) { LoadPlrGFX(pnum, PFILE_MAGIC); } - NewPlrAnim(pnum, plr[pnum]._pTAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth, AnimationDistributionFlags::ProcessAnimationPending); + NewPlrAnim(pnum, plr[pnum]._pTAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth, AnimationDistributionParams::ProcessAnimationPending); break; } } @@ -1799,7 +1799,7 @@ void StartPlrHit(int pnum, int dam, bool forcehit) skippedAnimationFrames = 0; } - NewPlrAnim(pnum, plr[pnum]._pHAnim[pd], plr[pnum]._pHFrames, 0, plr[pnum]._pHWidth, AnimationDistributionFlags::None, skippedAnimationFrames); + NewPlrAnim(pnum, plr[pnum]._pHAnim[pd], plr[pnum]._pHFrames, 0, plr[pnum]._pHWidth, AnimationDistributionParams::None, skippedAnimationFrames); plr[pnum]._pmode = PM_GOTHIT; FixPlayerLocation(pnum, pd); diff --git a/Source/player.h b/Source/player.h index d90770424..f9acec8e0 100644 --- a/Source/player.h +++ b/Source/player.h @@ -419,16 +419,16 @@ void FreePlayerGFX(int pnum); /** * @brief Specifies what special logics are applied for a Animation */ -enum AnimationDistributionFlags : uint8_t { +enum class AnimationDistributionParams : uint8_t { None = 0, /* * @brief ProcessAnimation will be called after NewPlrAnim (in same GameTick as NewPlrAnim) */ - ProcessAnimationPending = 1 << 0, + ProcessAnimationPending, /* * @brief Delay of last Frame is ignored (for example, because only Frame and not delay is checked in game_logic) */ - SkipsDelayOfLastFrame = 1 << 1, + SkipsDelayOfLastFrame, }; /** @@ -439,11 +439,11 @@ enum AnimationDistributionFlags : uint8_t { * @param numFrames Number of Frames in Animation * @param Delay Delay after each Animation sequence * @param width Width of sprite - * @param flags Specifies what special logics are applied to this Animation + * @param params Specifies what special logics are applied to this Animation * @param numSkippedFrames Number of Frames that will be skipped (for example with modifier "faster attack") * @param distributeFramesBeforeFrame Distribute the numSkippedFrames only before this frame */ -void NewPlrAnim(int pnum, BYTE *Peq, int numFrames, int Delay, int width, AnimationDistributionFlags flags = AnimationDistributionFlags::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0); +void NewPlrAnim(int pnum, BYTE *Peq, int numFrames, int Delay, int width, AnimationDistributionParams params = AnimationDistributionParams::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0); void SetPlrAnims(int pnum); void ProcessPlayerAnimation(int pnum); /** diff --git a/test/animationinformation_test.cpp b/test/animationinformation_test.cpp index 53723795b..90c44556f 100644 --- a/test/animationinformation_test.cpp +++ b/test/animationinformation_test.cpp @@ -50,11 +50,11 @@ struct RenderingData : TestData { * Rendering can happen more often then GameTicks and at any time between two GameTicks. * The Animation Distribution Logic must adjust to the Rendering that happens at any give point in time. */ -void RunAnimationTest(int numFrames, int delay, AnimationDistributionFlags flags, int numSkippedFrames, int distributeFramesBeforeFrame, const std::vector &vecTestData) +void RunAnimationTest(int numFrames, int delay, AnimationDistributionParams params, int numSkippedFrames, int distributeFramesBeforeFrame, const std::vector &vecTestData) { const int pnum = 0; PlayerStruct *pPlayer = &plr[pnum]; - NewPlrAnim(pnum, nullptr, numFrames, delay, 128, flags, numSkippedFrames, distributeFramesBeforeFrame); + NewPlrAnim(pnum, nullptr, numFrames, delay, 128, params, numSkippedFrames, distributeFramesBeforeFrame); int currentGameTick = 0; for (TestData *x : vecTestData) { @@ -86,7 +86,7 @@ void RunAnimationTest(int numFrames, int delay, AnimationDistributionFlags flags TEST(AnimationInformation, AttackSwordWarrior) // ProcessAnimationPending should be considered by distribution logic { - RunAnimationTest(16, 0, AnimationDistributionFlags::ProcessAnimationPending, 0, 9, + RunAnimationTest(16, 0, AnimationDistributionParams::ProcessAnimationPending, 0, 9, { // ProcessPlayer directly after StartAttack (in same GameTick). So we don't see any rendering before. new GameTickData(2, 0), @@ -148,7 +148,7 @@ TEST(AnimationInformation, AttackSwordWarrior) // ProcessAnimationPending should TEST(AnimationInformation, AttackSwordWarriorWithFastestAttack) // Skipped frames and ProcessAnimationPending should be considered by distribution logic { - RunAnimationTest(16, 0, AnimationDistributionFlags::ProcessAnimationPending, 2, 9, + RunAnimationTest(16, 0, AnimationDistributionParams::ProcessAnimationPending, 2, 9, { // ProcessPlayer directly after StartAttack (in same GameTick). So we don't see any rendering before. new GameTickData(2, 0), @@ -200,7 +200,7 @@ TEST(AnimationInformation, AttackSwordWarriorWithFastestAttack) // Skipped frame TEST(AnimationInformation, BlockingWarriorNormal) // Ignored delay for last Frame should be considered by distribution logic { - RunAnimationTest(2, 2, AnimationDistributionFlags::SkipsDelayOfLastFrame, 0, 0, + RunAnimationTest(2, 2, AnimationDistributionParams::SkipsDelayOfLastFrame, 0, 0, { new RenderingData(0.0f, 1), new RenderingData(0.3f, 1), @@ -227,7 +227,7 @@ TEST(AnimationInformation, BlockingWarriorNormal) // Ignored delay for last Fram TEST(AnimationInformation, BlockingSorcererWithFastBlock) // Skipped frames and ignored delay for last Frame should be considered by distribution logic { - RunAnimationTest(6, 2, AnimationDistributionFlags::SkipsDelayOfLastFrame, 4, 0, + RunAnimationTest(6, 2, AnimationDistributionParams::SkipsDelayOfLastFrame, 4, 0, { new RenderingData(0.0f, 1), new RenderingData(0.3f, 1), @@ -254,7 +254,7 @@ TEST(AnimationInformation, BlockingSorcererWithFastBlock) // Skipped frames and TEST(AnimationInformation, HitRecoverySorcererZenMode) // Skipped frames and ignored delay for last Frame should be considered by distribution logic { - RunAnimationTest(8, 0, AnimationDistributionFlags::None, 4, 0, + RunAnimationTest(8, 0, AnimationDistributionParams::None, 4, 0, { new RenderingData(0.0f, 1), new RenderingData(0.3f, 1), @@ -280,7 +280,7 @@ TEST(AnimationInformation, HitRecoverySorcererZenMode) // Skipped frames and ign } TEST(AnimationInformation, Stand) // Distribution Logic shouldn't change anything here { - RunAnimationTest(10, 3, AnimationDistributionFlags::None, 0, 0, + RunAnimationTest(10, 3, AnimationDistributionParams::None, 0, 0, { new RenderingData(0.1f, 1), new GameTickData(1, 1),