From 28f1f035b1599cdb270f3674d5df095bec480ba0 Mon Sep 17 00:00:00 2001 From: Dickby Date: Tue, 5 Sep 2023 15:06:39 +0200 Subject: [PATCH] animationmgr: Optimize CAnimationManager::scheduleTick a bit. (#3172) * Optimize CAnimationManager::scheduleTick a bit. * Use integer in wl_event_source_timer_update call. --- src/managers/AnimationManager.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 113b4851..4172a1ff 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -539,15 +539,14 @@ void CAnimationManager::scheduleTick() { const auto PMOSTHZ = g_pHyprRenderer->m_pMostHzMonitor; - float refreshRate = PMOSTHZ ? PMOSTHZ->refreshRate : 60.f; - float refreshDelayMs = std::floor(1000.0 / refreshRate); - if (!PMOSTHZ) { - wl_event_source_timer_update(m_pAnimationTick, refreshDelayMs); + wl_event_source_timer_update(m_pAnimationTick, 16); return; } - const float SINCEPRES = std::chrono::duration_cast(std::chrono::system_clock::now() - PMOSTHZ->lastPresentationTimer.chrono()).count() / 1000.0; + float refreshDelayMs = std::floor(1000.f / PMOSTHZ->refreshRate); + + const float SINCEPRES = std::chrono::duration_cast(std::chrono::system_clock::now() - PMOSTHZ->lastPresentationTimer.chrono()).count() / 1000.f; const auto TOPRES = std::clamp(refreshDelayMs - SINCEPRES, 1.1f, 1000.f); // we can't send 0, that will disarm it