2022-04-23 14:16:02 +02:00
|
|
|
#include "AnimatedVariable.hpp"
|
|
|
|
#include "../managers/AnimationManager.hpp"
|
2022-07-28 13:28:43 +02:00
|
|
|
#include "../config/ConfigManager.hpp"
|
2022-04-23 14:16:02 +02:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
CBaseAnimatedVariable::CBaseAnimatedVariable(ANIMATEDVARTYPE type) : m_Type(type) {
|
2022-04-23 14:16:02 +02:00
|
|
|
; // dummy var
|
|
|
|
}
|
|
|
|
|
2024-03-29 01:23:16 +01:00
|
|
|
void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, CWindow* pWindow, AVARDAMAGEPOLICY policy) {
|
2022-05-05 14:02:30 +02:00
|
|
|
m_eDamagePolicy = policy;
|
2022-12-16 18:17:31 +01:00
|
|
|
m_pConfig = pAnimConfig;
|
|
|
|
m_pWindow = pWindow;
|
2022-04-23 14:16:02 +02:00
|
|
|
|
|
|
|
m_bDummy = false;
|
|
|
|
}
|
|
|
|
|
2024-03-29 01:23:16 +01:00
|
|
|
void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, SLayerSurface* pLayer, AVARDAMAGEPOLICY policy) {
|
|
|
|
m_eDamagePolicy = policy;
|
|
|
|
m_pConfig = pAnimConfig;
|
|
|
|
m_pLayer = pLayer;
|
|
|
|
|
|
|
|
m_bDummy = false;
|
|
|
|
}
|
|
|
|
|
2024-04-02 21:32:39 +02:00
|
|
|
void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, PHLWORKSPACE pWorkspace, AVARDAMAGEPOLICY policy) {
|
2024-03-29 01:23:16 +01:00
|
|
|
m_eDamagePolicy = policy;
|
|
|
|
m_pConfig = pAnimConfig;
|
|
|
|
m_pWorkspace = pWorkspace;
|
|
|
|
|
|
|
|
m_bDummy = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, AVARDAMAGEPOLICY policy) {
|
|
|
|
m_eDamagePolicy = policy;
|
|
|
|
m_pConfig = pAnimConfig;
|
|
|
|
|
|
|
|
m_bDummy = false;
|
|
|
|
}
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
CBaseAnimatedVariable::~CBaseAnimatedVariable() {
|
2022-05-12 11:27:31 +02:00
|
|
|
unregister();
|
|
|
|
}
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
void CBaseAnimatedVariable::unregister() {
|
2023-09-22 12:06:09 +02:00
|
|
|
if (!g_pAnimationManager)
|
|
|
|
return;
|
2023-07-20 19:26:10 +02:00
|
|
|
std::erase_if(g_pAnimationManager->m_vAnimatedVariables, [&](const auto& other) { return other == this; });
|
2022-11-05 14:37:29 +01:00
|
|
|
m_bIsRegistered = false;
|
2023-07-20 19:26:10 +02:00
|
|
|
disconnectFromActive();
|
2022-07-28 13:28:43 +02:00
|
|
|
}
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
void CBaseAnimatedVariable::registerVar() {
|
2022-11-05 14:37:29 +01:00
|
|
|
if (!m_bIsRegistered)
|
2023-07-20 19:26:10 +02:00
|
|
|
g_pAnimationManager->m_vAnimatedVariables.push_back(this);
|
2022-11-05 14:37:29 +01:00
|
|
|
m_bIsRegistered = true;
|
2022-11-04 16:56:31 +01:00
|
|
|
}
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
int CBaseAnimatedVariable::getDurationLeftMs() {
|
2022-12-16 18:17:31 +01:00
|
|
|
return std::max(
|
|
|
|
(int)(m_pConfig->pValues->internalSpeed * 100) - (int)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - animationBegin).count(), 0);
|
2022-07-28 13:28:43 +02:00
|
|
|
}
|
2022-11-06 18:52:09 +01:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
float CBaseAnimatedVariable::getPercent() {
|
2022-11-06 18:52:09 +01:00
|
|
|
const auto DURATIONPASSED = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - animationBegin).count();
|
|
|
|
return std::clamp((DURATIONPASSED / 100.f) / m_pConfig->pValues->internalSpeed, 0.f, 1.f);
|
2022-12-29 12:30:43 +01:00
|
|
|
}
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
float CBaseAnimatedVariable::getCurveValue() {
|
2024-02-27 23:34:02 +01:00
|
|
|
if (!m_bIsBeingAnimated)
|
|
|
|
return 1.f;
|
|
|
|
|
2022-12-29 12:30:43 +01:00
|
|
|
const auto SPENT = getPercent();
|
|
|
|
|
|
|
|
if (SPENT >= 1.f)
|
|
|
|
return 1.f;
|
|
|
|
|
|
|
|
return g_pAnimationManager->getBezier(m_pConfig->pValues->internalBezier)->getYForPoint(SPENT);
|
2023-07-20 19:26:10 +02:00
|
|
|
}
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
void CBaseAnimatedVariable::connectToActive() {
|
2023-08-05 23:29:33 +02:00
|
|
|
g_pAnimationManager->scheduleTick(); // otherwise the animation manager will never pick this up
|
|
|
|
|
2023-07-20 19:26:10 +02:00
|
|
|
if (!m_bIsConnectedToActive)
|
|
|
|
g_pAnimationManager->m_vActiveAnimatedVariables.push_back(this);
|
2023-08-05 23:29:33 +02:00
|
|
|
|
2023-07-20 19:26:10 +02:00
|
|
|
m_bIsConnectedToActive = true;
|
|
|
|
}
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
void CBaseAnimatedVariable::disconnectFromActive() {
|
2023-07-20 19:26:10 +02:00
|
|
|
std::erase_if(g_pAnimationManager->m_vActiveAnimatedVariables, [&](const auto& other) { return other == this; });
|
|
|
|
m_bIsConnectedToActive = false;
|
2024-03-02 01:35:17 +01:00
|
|
|
}
|