mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-07 19:25:59 +01:00
animationmgr: avoid looping over all avars in favor of only active ones
This commit is contained in:
parent
7940f779e9
commit
6c1f4faff2
4 changed files with 23 additions and 9 deletions
|
@ -51,13 +51,14 @@ CAnimatedVariable::~CAnimatedVariable() {
|
|||
}
|
||||
|
||||
void CAnimatedVariable::unregister() {
|
||||
g_pAnimationManager->m_lAnimatedVariables.remove(this);
|
||||
std::erase_if(g_pAnimationManager->m_vAnimatedVariables, [&](const auto& other) { return other == this; });
|
||||
m_bIsRegistered = false;
|
||||
disconnectFromActive();
|
||||
}
|
||||
|
||||
void CAnimatedVariable::registerVar() {
|
||||
if (!m_bIsRegistered)
|
||||
g_pAnimationManager->m_lAnimatedVariables.push_back(this);
|
||||
g_pAnimationManager->m_vAnimatedVariables.push_back(this);
|
||||
m_bIsRegistered = true;
|
||||
}
|
||||
|
||||
|
@ -79,3 +80,14 @@ float CAnimatedVariable::getCurveValue() {
|
|||
|
||||
return g_pAnimationManager->getBezier(m_pConfig->pValues->internalBezier)->getYForPoint(SPENT);
|
||||
}
|
||||
|
||||
void CAnimatedVariable::connectToActive() {
|
||||
if (!m_bIsConnectedToActive)
|
||||
g_pAnimationManager->m_vActiveAnimatedVariables.push_back(this);
|
||||
m_bIsConnectedToActive = true;
|
||||
}
|
||||
|
||||
void CAnimatedVariable::disconnectFromActive() {
|
||||
std::erase_if(g_pAnimationManager->m_vActiveAnimatedVariables, [&](const auto& other) { return other == this; });
|
||||
m_bIsConnectedToActive = false;
|
||||
}
|
|
@ -259,9 +259,14 @@ class CAnimatedVariable {
|
|||
std::function<void(void* thisptr)> m_fBeginCallback;
|
||||
std::function<void(void* thisptr)> m_fUpdateCallback;
|
||||
|
||||
bool m_bIsConnectedToActive = false;
|
||||
void connectToActive();
|
||||
void disconnectFromActive();
|
||||
|
||||
// methods
|
||||
void onAnimationEnd() {
|
||||
m_bIsBeingAnimated = false;
|
||||
disconnectFromActive();
|
||||
|
||||
if (m_fEndCallback) {
|
||||
// loading m_bRemoveEndAfterRan before calling the callback allows the callback to delete this animation safely if it is false.
|
||||
|
@ -274,6 +279,7 @@ class CAnimatedVariable {
|
|||
|
||||
void onAnimationBegin() {
|
||||
m_bIsBeingAnimated = true;
|
||||
connectToActive();
|
||||
|
||||
if (m_fBeginCallback) {
|
||||
m_fBeginCallback(this);
|
||||
|
|
|
@ -58,12 +58,7 @@ void CAnimationManager::tick() {
|
|||
|
||||
std::vector<CAnimatedVariable*> animationEndedVars;
|
||||
|
||||
for (auto& av : m_lAnimatedVariables) {
|
||||
|
||||
// first of all, check if we need to update it at all
|
||||
// TODO: this has a 100% cache miss rate, maybe move active avars to a separate vec
|
||||
if (!av->m_bIsBeingAnimated)
|
||||
continue;
|
||||
for (auto& av : m_vActiveAnimatedVariables) {
|
||||
|
||||
if (av->m_eDamagePolicy == AVARDAMAGE_SHADOW && !*PSHADOWSENABLED) {
|
||||
av->warp(false);
|
||||
|
|
|
@ -25,7 +25,8 @@ class CAnimationManager {
|
|||
|
||||
std::unordered_map<std::string, CBezierCurve> getAllBeziers();
|
||||
|
||||
std::list<CAnimatedVariable*> m_lAnimatedVariables;
|
||||
std::vector<CAnimatedVariable*> m_vAnimatedVariables;
|
||||
std::vector<CAnimatedVariable*> m_vActiveAnimatedVariables;
|
||||
|
||||
wl_event_source* m_pAnimationTick;
|
||||
|
||||
|
|
Loading…
Reference in a new issue