diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-04-23 14:16:02 +0200 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-04-23 14:16:02 +0200 |
| commit | 0147975faf939db389bebaa95e3a12e5e5a8753f (patch) | |
| tree | c6933763435812460ebdc9609ed90eae21110753 /src/helpers | |
| parent | fa38dfd416b664033a96bb4af764fd54f7257d7b (diff) | |
New animation system
Diffstat (limited to 'src/helpers')
| -rw-r--r-- | src/helpers/AnimatedVariable.cpp | 54 | ||||
| -rw-r--r-- | src/helpers/AnimatedVariable.hpp | 131 |
2 files changed, 185 insertions, 0 deletions
diff --git a/src/helpers/AnimatedVariable.cpp b/src/helpers/AnimatedVariable.cpp new file mode 100644 index 00000000..581ea1c8 --- /dev/null +++ b/src/helpers/AnimatedVariable.cpp @@ -0,0 +1,54 @@ +#include "AnimatedVariable.hpp" +#include "../managers/AnimationManager.hpp" + +CAnimatedVariable::CAnimatedVariable() { + ; // dummy var +} + +void CAnimatedVariable::create(ANIMATEDVARTYPE type, float* speed, int64_t* enabled, void* pWindow) { + m_eVarType = type; + m_pSpeed = speed; + m_pEnabled = enabled; + m_pWindow = pWindow; + + g_pAnimationManager->m_lAnimatedVariables.push_back(this); + + m_bDummy = false; +} + +void CAnimatedVariable::create(ANIMATEDVARTYPE type, std::any val, float* speed, int64_t* enabled, void* pWindow) { + create(type, speed, enabled, pWindow); + + try { + switch (type) { + case AVARTYPE_FLOAT: { + const auto V = std::any_cast<float>(val); + m_fValue = V; + m_fGoal = V; + break; + } + case AVARTYPE_VECTOR: { + const auto V = std::any_cast<Vector2D>(val); + m_vValue = V; + m_vGoal = V; + break; + } + case AVARTYPE_COLOR: { + const auto V = std::any_cast<CColor>(val); + m_cValue = V; + m_cGoal = V; + break; + } + default: + ASSERT(false); + break; + } + } catch (std::exception& e) { + Debug::log(ERR, "CAnimatedVariable create error: %s", e.what()); + RASSERT(false, "CAnimatedVariable create error: %s", e.what()); + } +} + +CAnimatedVariable::~CAnimatedVariable() { + g_pAnimationManager->m_lAnimatedVariables.remove(this); +}
\ No newline at end of file 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 <any> + +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 |
