From 8f6c6f9827ef7901fe62efb91d8e8bf34b6312b7 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Mon, 11 Nov 2024 23:51:22 -0500 Subject: [PATCH 1/5] Fix getAnimationProgress --- Source/engine/animationinfo.cpp | 6 +++++- Source/engine/animationinfo.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 4fe9c0ace5f..c41925c152d 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -59,12 +59,16 @@ int8_t AnimationInfo::getFrameToUseForRendering() const return absoluteAnimationFrame; } -uint8_t AnimationInfo::getAnimationProgress() const +uint8_t AnimationInfo::getAnimationProgress() { int16_t ticksSinceSequenceStarted = std::max(0, ticksSinceSequenceStarted_); int32_t tickModifier = tickModifier_; if (relevantFramesForDistributing_ <= 0) { + if (ticksPerFrame <= 0) { + Log("getAnimationProgress: Invalid ticksPerFrame {}", ticksPerFrame); + ticksPerFrame = 1; + } // This logic is used if animation distribution 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. ticksSinceSequenceStarted = ((currentFrame * ticksPerFrame) + tickCounterOfCurrentFrame) * baseValueFraction; diff --git a/Source/engine/animationinfo.h b/Source/engine/animationinfo.h index ae0947f7a5f..401faadf4e9 100644 --- a/Source/engine/animationinfo.h +++ b/Source/engine/animationinfo.h @@ -80,7 +80,7 @@ class AnimationInfo { /** * @brief Calculates the progress of the current animation as a fraction (see baseValueFraction) */ - [[nodiscard]] uint8_t getAnimationProgress() const; + [[nodiscard]] uint8_t getAnimationProgress(); /** * @brief Sets the new Animation with all relevant information for rendering From 80ee87bfdde3ad6db22ea614e4c5b407aed51895 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Mon, 11 Nov 2024 23:54:38 -0500 Subject: [PATCH 2/5] const --- Source/engine/animationinfo.cpp | 7 +++---- Source/engine/animationinfo.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index c41925c152d..4777ae93d50 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -59,7 +59,7 @@ int8_t AnimationInfo::getFrameToUseForRendering() const return absoluteAnimationFrame; } -uint8_t AnimationInfo::getAnimationProgress() +uint8_t AnimationInfo::getAnimationProgress() const { int16_t ticksSinceSequenceStarted = std::max(0, ticksSinceSequenceStarted_); int32_t tickModifier = tickModifier_; @@ -67,12 +67,11 @@ uint8_t AnimationInfo::getAnimationProgress() if (relevantFramesForDistributing_ <= 0) { if (ticksPerFrame <= 0) { Log("getAnimationProgress: Invalid ticksPerFrame {}", ticksPerFrame); - ticksPerFrame = 1; } // This logic is used if animation distribution 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. - ticksSinceSequenceStarted = ((currentFrame * ticksPerFrame) + tickCounterOfCurrentFrame) * baseValueFraction; - tickModifier = baseValueFraction / ticksPerFrame; + ticksSinceSequenceStarted = ((currentFrame * std::max(static_cast(1), ticksPerFrame)) + tickCounterOfCurrentFrame) * baseValueFraction; + tickModifier = baseValueFraction / std::max(static_cast(1), ticksPerFrame); } int32_t totalTicksForCurrentAnimationSequence = getProgressToNextGameTick() + ticksSinceSequenceStarted; diff --git a/Source/engine/animationinfo.h b/Source/engine/animationinfo.h index 401faadf4e9..ae0947f7a5f 100644 --- a/Source/engine/animationinfo.h +++ b/Source/engine/animationinfo.h @@ -80,7 +80,7 @@ class AnimationInfo { /** * @brief Calculates the progress of the current animation as a fraction (see baseValueFraction) */ - [[nodiscard]] uint8_t getAnimationProgress(); + [[nodiscard]] uint8_t getAnimationProgress() const; /** * @brief Sets the new Animation with all relevant information for rendering From 7ebf92bddf5957446c715a5c674d6685d8efcdef Mon Sep 17 00:00:00 2001 From: Eric Robinson <68359262+kphoenix137@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:57:09 -0500 Subject: [PATCH 3/5] Update Source/engine/animationinfo.cpp Co-authored-by: Andrew James --- Source/engine/animationinfo.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 4777ae93d50..6b000fee366 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -70,8 +70,9 @@ uint8_t AnimationInfo::getAnimationProgress() const } // This logic is used if animation distribution 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. - ticksSinceSequenceStarted = ((currentFrame * std::max(static_cast(1), ticksPerFrame)) + tickCounterOfCurrentFrame) * baseValueFraction; - tickModifier = baseValueFraction / std::max(static_cast(1), ticksPerFrame); + ticksSinceSequenceStarted = ((currentFrame * std::max(1, ticksPerFrame)) + tickCounterOfCurrentFrame) * baseValueFraction; + tickModifier = baseValueFraction / std::max(1, ticksPerFrame); + } int32_t totalTicksForCurrentAnimationSequence = getProgressToNextGameTick() + ticksSinceSequenceStarted; From c905dee5ff4908b0d4637dde059f7133fe531330 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Tue, 12 Nov 2024 20:25:29 -0500 Subject: [PATCH 4/5] Update animationinfo.cpp --- Source/engine/animationinfo.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 6b000fee366..b254ba3c772 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -72,7 +72,6 @@ uint8_t AnimationInfo::getAnimationProgress() const // 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. ticksSinceSequenceStarted = ((currentFrame * std::max(1, ticksPerFrame)) + tickCounterOfCurrentFrame) * baseValueFraction; tickModifier = baseValueFraction / std::max(1, ticksPerFrame); - } int32_t totalTicksForCurrentAnimationSequence = getProgressToNextGameTick() + ticksSinceSequenceStarted; From 7b86dc11d55a20c1d796ab5efa8e7ecedf8427d0 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Thu, 14 Nov 2024 19:11:25 -0500 Subject: [PATCH 5/5] Update animationinfo.cpp --- Source/engine/animationinfo.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index b254ba3c772..44ad6009f05 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -67,11 +67,12 @@ uint8_t AnimationInfo::getAnimationProgress() const if (relevantFramesForDistributing_ <= 0) { if (ticksPerFrame <= 0) { Log("getAnimationProgress: Invalid ticksPerFrame {}", ticksPerFrame); + return 0; } // This logic is used if animation distribution 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. - ticksSinceSequenceStarted = ((currentFrame * std::max(1, ticksPerFrame)) + tickCounterOfCurrentFrame) * baseValueFraction; - tickModifier = baseValueFraction / std::max(1, ticksPerFrame); + ticksSinceSequenceStarted = ((currentFrame * ticksPerFrame) + tickCounterOfCurrentFrame) * baseValueFraction; + tickModifier = baseValueFraction / ticksPerFrame; } int32_t totalTicksForCurrentAnimationSequence = getProgressToNextGameTick() + ticksSinceSequenceStarted;