optimize animationmanager

This commit is contained in:
vaxerski 2022-06-30 12:54:58 +02:00
parent a7ebf0ddc3
commit cfc1f6c211
1 changed files with 46 additions and 67 deletions

View File

@ -40,6 +40,16 @@ void CAnimationManager::tick() {
// get speed // get speed
const auto SPEED = *av->m_pSpeed == 0 ? *PANIMSPEED : *av->m_pSpeed; const auto SPEED = *av->m_pSpeed == 0 ? *PANIMSPEED : *av->m_pSpeed;
// get the spent % (0 - 1)
const auto DURATIONPASSED = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - av->animationBegin).count();
const float SPENT = std::clamp((DURATIONPASSED / 100.f) / SPEED, 0.f, 1.f);
// first of all, check if we need to update it at all
if (SPENT >= 1.f) {
av->warp();
continue;
}
// window stuff // window stuff
const auto PWINDOW = (CWindow*)av->m_pWindow; const auto PWINDOW = (CWindow*)av->m_pWindow;
const auto PWORKSPACE = (CWorkspace*)av->m_pWorkspace; const auto PWORKSPACE = (CWorkspace*)av->m_pWorkspace;
@ -58,14 +68,8 @@ void CAnimationManager::tick() {
// beziers are with a switch unforto // beziers are with a switch unforto
// TODO: maybe do something cleaner // TODO: maybe do something cleaner
// get the spent % (0 - 1)
const auto DURATIONPASSED = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - av->animationBegin).count();
const float SPENT = std::clamp((DURATIONPASSED / 100.f) / SPEED, 0.f, 1.f);
switch (av->m_eVarType) { switch (av->m_eVarType) {
case AVARTYPE_FLOAT: { case AVARTYPE_FLOAT: {
if (!deltazero(av->m_fValue, av->m_fGoal)) {
// for disabled anims just warp // for disabled anims just warp
if (*av->m_pEnabled == 0 || animationsDisabled) { if (*av->m_pEnabled == 0 || animationsDisabled) {
av->warp(); av->warp();
@ -79,18 +83,9 @@ void CAnimationManager::tick() {
av->m_fValue = av->m_fBegun + BEZIER->second.getYForPoint(SPENT) * DELTA; av->m_fValue = av->m_fBegun + BEZIER->second.getYForPoint(SPENT) * DELTA;
else else
av->m_fValue = av->m_fBegun + DEFAULTBEZIER->second.getYForPoint(SPENT) * DELTA; av->m_fValue = av->m_fBegun + DEFAULTBEZIER->second.getYForPoint(SPENT) * DELTA;
if (SPENT >= 1.f) {
av->warp();
}
} else {
continue; // dont process
}
break; break;
} }
case AVARTYPE_VECTOR: { case AVARTYPE_VECTOR: {
if (!deltazero(av->m_vValue, av->m_vGoal)) {
// for disabled anims just warp // for disabled anims just warp
if (*av->m_pEnabled == 0 || animationsDisabled) { if (*av->m_pEnabled == 0 || animationsDisabled) {
av->warp(); av->warp();
@ -104,18 +99,9 @@ void CAnimationManager::tick() {
av->m_vValue = av->m_vBegun + DELTA * BEZIER->second.getYForPoint(SPENT); av->m_vValue = av->m_vBegun + DELTA * BEZIER->second.getYForPoint(SPENT);
else else
av->m_vValue = av->m_vBegun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT); av->m_vValue = av->m_vBegun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT);
if (SPENT >= 1.f) {
av->warp();
}
} else {
continue; // dont process
}
break; break;
} }
case AVARTYPE_COLOR: { case AVARTYPE_COLOR: {
if (!deltazero(av->m_cValue, av->m_cGoal)) {
// for disabled anims just warp // for disabled anims just warp
if (*av->m_pEnabled == 0 || animationsDisabled) { if (*av->m_pEnabled == 0 || animationsDisabled) {
av->warp(); av->warp();
@ -129,13 +115,6 @@ void CAnimationManager::tick() {
av->m_cValue = av->m_cBegun + DELTA * BEZIER->second.getYForPoint(SPENT); av->m_cValue = av->m_cBegun + DELTA * BEZIER->second.getYForPoint(SPENT);
else else
av->m_cValue = av->m_cBegun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT); av->m_cValue = av->m_cBegun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT);
if (SPENT >= 1.f) {
av->warp();
}
} else {
continue; // dont process
}
break; break;
} }
default: { default: {