From 0147975faf939db389bebaa95e3a12e5e5a8753f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:16:02 +0200 Subject: New animation system --- src/helpers/AnimatedVariable.hpp | 131 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/helpers/AnimatedVariable.hpp (limited to 'src/helpers/AnimatedVariable.hpp') diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp new file mode 100644 index 00000000..bd10c920 --- /dev/null +++ b/src/helpers/AnimatedVariable.hpp @@ -0,0 +1,131 @@ +#pragma once + +#include "../defines.hpp" +#include + +enum ANIMATEDVARTYPE { + AVARTYPE_INVALID = -1, + AVARTYPE_FLOAT, + AVARTYPE_VECTOR, + AVARTYPE_COLOR +}; + +class CAnimationManager; + +class CAnimatedVariable { +public: + CAnimatedVariable(); // dummy var + + void create(ANIMATEDVARTYPE, float* speed, int64_t* enabled, void* pWindow); + void create(ANIMATEDVARTYPE, std::any val, float* speed, int64_t* enabled, void* pWindow); + + ~CAnimatedVariable(); + + Vector2D vec() { + ASSERT(m_eVarType == AVARTYPE_VECTOR); + return m_vValue; + } + + float fl() { + ASSERT(m_eVarType == AVARTYPE_FLOAT); + return m_fValue; + } + + CColor col() { + ASSERT(m_eVarType == AVARTYPE_COLOR); + return m_cValue; + } + + void operator=(const Vector2D& v) { + ASSERT(m_eVarType == AVARTYPE_VECTOR); + m_vGoal = v; + } + + void operator=(const float& v) { + ASSERT(m_eVarType == AVARTYPE_FLOAT); + m_fGoal = v; + } + + void operator=(const CColor& v) { + ASSERT(m_eVarType == AVARTYPE_COLOR); + m_cGoal = v; + } + + // Sets the actual stored value, without affecting the goal + void setValue(const Vector2D& v) { + ASSERT(m_eVarType == AVARTYPE_VECTOR); + m_vValue = v; + } + + // Sets the actual stored value, without affecting the goal + void setValue(const float& v) { + ASSERT(m_eVarType == AVARTYPE_FLOAT); + m_fValue = v; + } + + // Sets the actual stored value, without affecting the goal + void setValue(const CColor& v) { + ASSERT(m_eVarType == AVARTYPE_COLOR); + m_cValue = v; + } + + // Sets the actual value and goal + void setValueAndWarp(const Vector2D& v) { + ASSERT(m_eVarType == AVARTYPE_VECTOR); + m_vGoal = v; + warp(); + } + + // Sets the actual value and goal + void setValueAndWarp(const float& v) { + ASSERT(m_eVarType == AVARTYPE_FLOAT); + m_fGoal = v; + warp(); + } + + // Sets the actual value and goal + void setValueAndWarp(const CColor& v) { + ASSERT(m_eVarType == AVARTYPE_COLOR); + m_cGoal = v; + warp(); + } + +private: + + void warp() { + switch (m_eVarType) { + case AVARTYPE_FLOAT: { + m_fValue = m_fGoal; + break; + } + case AVARTYPE_VECTOR: { + m_vValue = m_vGoal; + break; + } + case AVARTYPE_COLOR: { + m_cValue = m_cGoal; + break; + } + default: + break; + } + } + + Vector2D m_vValue = Vector2D(0,0); + float m_fValue = 0; + CColor m_cValue; + + Vector2D m_vGoal = Vector2D(0,0); + float m_fGoal = 0; + CColor m_cGoal; + + float* m_pSpeed = nullptr; + int64_t* m_pEnabled = nullptr; + void* m_pWindow = nullptr; + + bool m_bDummy = true; + + ANIMATEDVARTYPE m_eVarType = AVARTYPE_INVALID; + + friend class CAnimationManager; +}; \ No newline at end of file -- cgit v1.2.3 From f84294fe07d3442ca62302de491717ef6355e902 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:35:34 +0200 Subject: fixed fullscreen, removed effective vars from windows --- src/helpers/AnimatedVariable.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/helpers/AnimatedVariable.hpp') diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index bd10c920..d6e058f0 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -21,21 +21,42 @@ public: ~CAnimatedVariable(); + // gets the current vector value (real time) Vector2D vec() { ASSERT(m_eVarType == AVARTYPE_VECTOR); return m_vValue; } + // gets the current float value (real time) float fl() { ASSERT(m_eVarType == AVARTYPE_FLOAT); return m_fValue; } + // gets the current color value (real time) CColor col() { ASSERT(m_eVarType == AVARTYPE_COLOR); return m_cValue; } + // gets the goal vector value + Vector2D goalv() { + ASSERT(m_eVarType == AVARTYPE_VECTOR); + return m_vGoal; + } + + // gets the goal float value + float goalf() { + ASSERT(m_eVarType == AVARTYPE_FLOAT); + return m_fGoal; + } + + // gets the goal color value + CColor goalc() { + ASSERT(m_eVarType == AVARTYPE_COLOR); + return m_cGoal; + } + void operator=(const Vector2D& v) { ASSERT(m_eVarType == AVARTYPE_VECTOR); m_vGoal = v; -- cgit v1.2.3 From 306d163613c6940e73ad58e852b42cdb236a5bc4 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:40:51 +0200 Subject: return const refs + vec constantize --- src/helpers/AnimatedVariable.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/helpers/AnimatedVariable.hpp') diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index d6e058f0..ccdd78e3 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -22,37 +22,37 @@ public: ~CAnimatedVariable(); // gets the current vector value (real time) - Vector2D vec() { + const Vector2D& vec() const { ASSERT(m_eVarType == AVARTYPE_VECTOR); return m_vValue; } // gets the current float value (real time) - float fl() { + const float& fl() const { ASSERT(m_eVarType == AVARTYPE_FLOAT); return m_fValue; } // gets the current color value (real time) - CColor col() { + const CColor& col() const { ASSERT(m_eVarType == AVARTYPE_COLOR); return m_cValue; } // gets the goal vector value - Vector2D goalv() { + const Vector2D& goalv() const { ASSERT(m_eVarType == AVARTYPE_VECTOR); return m_vGoal; } // gets the goal float value - float goalf() { + const float& goalf() const { ASSERT(m_eVarType == AVARTYPE_FLOAT); return m_fGoal; } // gets the goal color value - CColor goalc() { + const CColor& goalc() const { ASSERT(m_eVarType == AVARTYPE_COLOR); return m_cGoal; } -- cgit v1.2.3 From 3ebe7d79722c1bdc333b236960ff136ab607a02c Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:47:16 +0200 Subject: Added bezier curves --- src/helpers/AnimatedVariable.hpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src/helpers/AnimatedVariable.hpp') diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index ccdd78e3..197e5d4e 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -16,8 +16,8 @@ class CAnimatedVariable { public: CAnimatedVariable(); // dummy var - void create(ANIMATEDVARTYPE, float* speed, int64_t* enabled, void* pWindow); - void create(ANIMATEDVARTYPE, std::any val, float* speed, int64_t* enabled, void* pWindow); + void create(ANIMATEDVARTYPE, float* speed, int64_t* enabled, std::string* pBezier, void* pWindow); + void create(ANIMATEDVARTYPE, std::any val, float* speed, int64_t* enabled, std::string* pBezier, void* pWindow); ~CAnimatedVariable(); @@ -60,34 +60,46 @@ public: void operator=(const Vector2D& v) { ASSERT(m_eVarType == AVARTYPE_VECTOR); m_vGoal = v; + animationBegin = std::chrono::system_clock::now(); + m_vBegun = m_vValue; } void operator=(const float& v) { ASSERT(m_eVarType == AVARTYPE_FLOAT); m_fGoal = v; + animationBegin = std::chrono::system_clock::now(); + m_fBegun = m_fValue; } void operator=(const CColor& v) { ASSERT(m_eVarType == AVARTYPE_COLOR); m_cGoal = v; + animationBegin = std::chrono::system_clock::now(); + m_cBegun = m_cValue; } - // Sets the actual stored value, without affecting the goal + // Sets the actual stored value, without affecting the goal, but resets the timer void setValue(const Vector2D& v) { ASSERT(m_eVarType == AVARTYPE_VECTOR); m_vValue = v; + animationBegin = std::chrono::system_clock::now(); + m_vBegun = m_vValue; } - // Sets the actual stored value, without affecting the goal + // Sets the actual stored value, without affecting the goal, but resets the timer void setValue(const float& v) { ASSERT(m_eVarType == AVARTYPE_FLOAT); m_fValue = v; + animationBegin = std::chrono::system_clock::now(); + m_vBegun = m_vValue; } - // Sets the actual stored value, without affecting the goal + // Sets the actual stored value, without affecting the goal, but resets the timer void setValue(const CColor& v) { ASSERT(m_eVarType == AVARTYPE_COLOR); m_cValue = v; + animationBegin = std::chrono::system_clock::now(); + m_vBegun = m_vValue; } // Sets the actual value and goal @@ -140,12 +152,19 @@ private: float m_fGoal = 0; CColor m_cGoal; + Vector2D m_vBegun = Vector2D(0,0); + float m_fBegun = 0; + CColor m_cBegun; + float* m_pSpeed = nullptr; int64_t* m_pEnabled = nullptr; void* m_pWindow = nullptr; + std::string* m_pBezier = nullptr; bool m_bDummy = true; + std::chrono::system_clock::time_point animationBegin; + ANIMATEDVARTYPE m_eVarType = AVARTYPE_INVALID; friend class CAnimationManager; -- cgit v1.2.3