From 11403080bac956870ad904846830d808b9005ee6 Mon Sep 17 00:00:00 2001 From: attila Date: Fri, 4 Oct 2024 11:29:58 +0200 Subject: [PATCH] VBlankAnimatorUpdater: Use the timestamp provided by VBlankAttachment --- .../animation/juce_AnimatorUpdater.cpp | 7 +++++-- .../animation/juce_AnimatorUpdater.h | 15 +++++++++++++++ .../animation/juce_VBlankAnimatorUpdater.h | 6 +++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/modules/juce_animation/animation/juce_AnimatorUpdater.cpp b/modules/juce_animation/animation/juce_AnimatorUpdater.cpp index 80318bebb7..6c3b3a4dee 100644 --- a/modules/juce_animation/animation/juce_AnimatorUpdater.cpp +++ b/modules/juce_animation/animation/juce_AnimatorUpdater.cpp @@ -62,6 +62,11 @@ void AnimatorUpdater::removeAnimator (const Animator& animator) } void AnimatorUpdater::update() +{ + update (Time::getMillisecondCounterHiRes()); +} + +void AnimatorUpdater::update (double timestampMs) { if (reentrancyGuard) { @@ -74,8 +79,6 @@ void AnimatorUpdater::update() const ScopedValueSetter setter { reentrancyGuard, true }; - const auto timestampMs = Time::getMillisecondCounterHiRes(); - for (currentIterator = animators.begin(); currentIterator != animators.end();) { auto& current = *currentIterator; diff --git a/modules/juce_animation/animation/juce_AnimatorUpdater.h b/modules/juce_animation/animation/juce_AnimatorUpdater.h index a2cdc461d0..e95042ff72 100644 --- a/modules/juce_animation/animation/juce_AnimatorUpdater.h +++ b/modules/juce_animation/animation/juce_AnimatorUpdater.h @@ -80,9 +80,24 @@ public: /** Calls Animator::update() for all registered Animators that are still alive. References to deleted Animators are removed. + + Uses Time::getMillisecondCounterHiRes() to calculate the necessary timestamp. Consider using + a VBlankAnimatorUpdater instead for using timestamps that are synchronised across all + VBlankAnimatorUpdater instances. */ void update(); + /** Calls Animator::update() for all registered Animators that are still alive. References to + deleted Animators are removed. + + The supplied timestamp should be monotonically increasing for correct behaviour. Ideally + this should be a timestamp supplied by a VBlankAttachment. Consider using the + VBlankAnimatorUpdater class, which takes care of supplying the right timestamp. + + @see VBlankAnimatorUpdater + */ + void update (double timestampMs); + private: struct JUCE_API Entry { diff --git a/modules/juce_animation/animation/juce_VBlankAnimatorUpdater.h b/modules/juce_animation/animation/juce_VBlankAnimatorUpdater.h index aa6d7fd050..247fdc1eb1 100644 --- a/modules/juce_animation/animation/juce_VBlankAnimatorUpdater.h +++ b/modules/juce_animation/animation/juce_VBlankAnimatorUpdater.h @@ -46,7 +46,11 @@ public: /** Constructs a VBlankAnimatorUpdater that is synchronised to the refresh rate of the monitor that the provided Component is being displayed on. */ - explicit VBlankAnimatorUpdater (Component* c) : vBlankAttachment (c, [this] { update(); }) + explicit VBlankAnimatorUpdater (Component* c) + : vBlankAttachment (c, [this] (double timestampSec) + { + update (timestampSec * 1000.0); + }) { }