From e67ea3639f833566f714d776acf2df08f59ef6eb Mon Sep 17 00:00:00 2001 From: obligaron Date: Wed, 15 Sep 2021 17:36:13 +0200 Subject: [PATCH] Fix AnimationInfo::GetAnimationProgress() when normal animation logic is used (for example loaded save games) --- Source/engine/animationinfo.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index bae4f5fc6..0fd07017f 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -19,7 +19,7 @@ int AnimationInfo::GetFrameToUseForRendering() const // 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) if (RelevantFramesForDistributing <= 0) - return CurrentFrame; + return std::max(1, CurrentFrame); if (CurrentFrame > RelevantFramesForDistributing) return CurrentFrame; @@ -62,9 +62,9 @@ float AnimationInfo::GetAnimationProgress() const if (RelevantFramesForDistributing <= 0) { // This logic is used if animation distrubtion is not active (see GetFrameToUseForRendering). // In this case the variables calculated with animation distribution are not initialized and we have to calculate them on the fly with the given information. - float ticksPerFrame = TicksPerFrame + 1.F; - float totalTicksForCurrentAnimationSequence = GetProgressToNextGameTick() + CurrentFrame + (TickCounterOfCurrentFrame / ticksPerFrame); - float fAnimationFraction = totalTicksForCurrentAnimationSequence / (NumberOfFrames * ticksPerFrame); + int passedTicks = ((CurrentFrame - 1) * TicksPerFrame) + TickCounterOfCurrentFrame; + float totalTicksForCurrentAnimationSequence = GetProgressToNextGameTick() + (float)passedTicks; + float fAnimationFraction = totalTicksForCurrentAnimationSequence / (float)(NumberOfFrames * TicksPerFrame); return fAnimationFraction; }