summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2023-07-19 22:40:03 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2023-07-19 22:40:03 +0200
commit7091d4e5979720ddb30f540b2d7da48080bf2487 (patch)
treed30fc8f48a5f166a694bddc627701ea28739f5c7 /src
parent80cd2ef3d7b95846314961823a19d5e1015d206a (diff)
animationmanager: optimize avar state
Diffstat (limited to 'src')
-rw-r--r--src/helpers/AnimatedVariable.hpp24
-rw-r--r--src/managers/AnimationManager.cpp3
2 files changed, 13 insertions, 14 deletions
diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp
index d819ce1f..ccba625d 100644
--- a/src/helpers/AnimatedVariable.hpp
+++ b/src/helpers/AnimatedVariable.hpp
@@ -148,17 +148,8 @@ class CAnimatedVariable {
}
// checks if an animation is in progress
- bool isBeingAnimated() {
- switch (m_eVarType) {
- case AVARTYPE_FLOAT: return m_fValue != m_fGoal;
- case AVARTYPE_VECTOR: return m_vValue != m_vGoal;
- case AVARTYPE_COLOR: return m_cValue != m_cGoal;
- default: UNREACHABLE();
- }
-
- UNREACHABLE();
-
- return false; // just so that the warning is suppressed
+ inline bool isBeingAnimated() {
+ return m_bIsBeingAnimated;
}
void warp(bool endCallback = true) {
@@ -178,6 +169,8 @@ class CAnimatedVariable {
default: UNREACHABLE();
}
+ m_bIsBeingAnimated = false;
+
if (endCallback)
onAnimationEnd();
}
@@ -251,8 +244,9 @@ class CAnimatedVariable {
SAnimationPropertyConfig* m_pConfig = nullptr;
- bool m_bDummy = true;
- bool m_bIsRegistered = false;
+ bool m_bDummy = true;
+ bool m_bIsRegistered = false;
+ bool m_bIsBeingAnimated = false;
std::chrono::system_clock::time_point animationBegin;
@@ -267,6 +261,8 @@ class CAnimatedVariable {
// methods
void onAnimationEnd() {
+ m_bIsBeingAnimated = false;
+
if (m_fEndCallback) {
// loading m_bRemoveEndAfterRan before calling the callback allows the callback to delete this animation safely if it is false.
auto removeEndCallback = m_bRemoveEndAfterRan;
@@ -277,6 +273,8 @@ class CAnimatedVariable {
}
void onAnimationBegin() {
+ m_bIsBeingAnimated = true;
+
if (m_fBeginCallback) {
m_fBeginCallback(this);
if (m_bRemoveBeginAfterRan)
diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp
index fa1e2941..0973c759 100644
--- a/src/managers/AnimationManager.cpp
+++ b/src/managers/AnimationManager.cpp
@@ -61,7 +61,8 @@ void CAnimationManager::tick() {
for (auto& av : m_lAnimatedVariables) {
// first of all, check if we need to update it at all
- if (!av->isBeingAnimated())
+ // TODO: this has a 100% cache miss rate, maybe move active avars to a separate vec
+ if (!av->m_bIsBeingAnimated)
continue;
if (av->m_eDamagePolicy == AVARDAMAGE_SHADOW && !*PSHADOWSENABLED) {