From 26601c98dc84aaaa69a3fc028786ab5aa58b67f4 Mon Sep 17 00:00:00 2001 From: obligaron Date: Sun, 25 Apr 2021 17:08:28 +0200 Subject: [PATCH] Simplify GetFrameToUseForRendering (remove local variables and use member variables) --- Source/engine/animationinfo.cpp | 19 ++++++++----------- Source/engine/animationinfo.h | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 524fe3895..14b0b729e 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -11,35 +11,32 @@ namespace devilution { -int AnimationInfo::GetFrameToUseForRendering() +int AnimationInfo::GetFrameToUseForRendering() const { // Normal logic is used, // - if no frame-skipping is required and so we have exactly one Animationframe per GameTick // or // - if we load from a savegame where the new variables are not stored (we don't want to break savegame compatiblity because of smoother rendering of one animation) - int relevantAnimationFramesForDistributing = RelevantFramesForDistributing; - if (relevantAnimationFramesForDistributing <= 0) + if (RelevantFramesForDistributing <= 0) return CurrentFrame; - if (CurrentFrame > relevantAnimationFramesForDistributing) + if (CurrentFrame > RelevantFramesForDistributing) return CurrentFrame; assert(GameTicksSinceSequenceStarted >= 0); - float progressToNextGameTick = gfProgressToNextGameTick; - // we don't use the processed game ticks alone but also the fragtion of the next game tick (if a rendering happens between game ticks). This helps to smooth the animations. - float totalGameTicksForCurrentAnimationSequence = progressToNextGameTick + (float)GameTicksSinceSequenceStarted; + float totalGameTicksForCurrentAnimationSequence = gfProgressToNextGameTick + (float)GameTicksSinceSequenceStarted; // 1 added for rounding reasons. float to int cast always truncate. int absoluteAnimationFrame = 1 + (int)(totalGameTicksForCurrentAnimationSequence * GameTickModifier); - if (absoluteAnimationFrame > relevantAnimationFramesForDistributing) { + if (absoluteAnimationFrame > RelevantFramesForDistributing) { // this can happen if we are at the last frame and the next game tick is due (nthread_GetProgressToNextGameTick returns 1.0f) - if (absoluteAnimationFrame > (relevantAnimationFramesForDistributing + 1)) { + if (absoluteAnimationFrame > (RelevantFramesForDistributing + 1)) { // we should never have +2 frames even if next game tick is due - Log("GetFrameToUseForRendering: Calculated an invalid Animation Frame (Calculated {} MaxFrame {})", absoluteAnimationFrame, relevantAnimationFramesForDistributing); + Log("GetFrameToUseForRendering: Calculated an invalid Animation Frame (Calculated {} MaxFrame {})", absoluteAnimationFrame, RelevantFramesForDistributing); } - return relevantAnimationFramesForDistributing; + return RelevantFramesForDistributing; } if (absoluteAnimationFrame <= 0) { Log("GetFrameToUseForRendering: Calculated an invalid Animation Frame (Calculated {})", absoluteAnimationFrame); diff --git a/Source/engine/animationinfo.h b/Source/engine/animationinfo.h index ecc34ec54..a8f3853e0 100644 --- a/Source/engine/animationinfo.h +++ b/Source/engine/animationinfo.h @@ -54,7 +54,7 @@ public: * @brief Calculates the Frame to use for the Animation rendering * @return The Frame to use for rendering */ - int GetFrameToUseForRendering(); + int GetFrameToUseForRendering() const; /** * @brief Sets the new Animation with all relevant information for rendering