summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2020-04-14 11:46:03 +0200
committerPaul Lemire <paul.lemire@kdab.com>2020-04-14 15:32:34 +0200
commitc1a18553530765054021e04662e923b8da505468 (patch)
treec10fcf28052336a28853e0c2373237766466442a /src
parent199953915b073cad0c751c0e6feedaa1111c1e68 (diff)
Animations: prevent FindRunningClipAnimatorJob from running every frame
The job it does takes a fair amount of time and only needs to run occasionally. We would reset the normalized time on the backend node every frame which then lead to a dirty set being set when synching again with the frontend. This might not have happened every frame prior to the synching refactorings. However currently, after every animation step, the dirty set would be reset and the job scheduled to run again even though nothing had really changed. This patch fixes that by setting the normalized time on the backend node prior to the synching with the frontend. That way, when we sync with the frontend the values are either identical when playing the animation unless the user really has changed the normalizedTime value. Change-Id: Iade4e7bfd47d34ef083d8e3398180a71630c0c81 Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/animation/backend/blendedclipanimator.cpp4
-rw-r--r--src/animation/backend/blendedclipanimator_p.h2
-rw-r--r--src/animation/backend/clipanimator.cpp4
-rw-r--r--src/animation/backend/clipanimator_p.h2
-rw-r--r--src/animation/backend/evaluateblendclipanimatorjob.cpp6
-rw-r--r--src/animation/backend/evaluateclipanimatorjob.cpp6
6 files changed, 16 insertions, 8 deletions
diff --git a/src/animation/backend/blendedclipanimator.cpp b/src/animation/backend/blendedclipanimator.cpp
index 7d771745b..14771247a 100644
--- a/src/animation/backend/blendedclipanimator.cpp
+++ b/src/animation/backend/blendedclipanimator.cpp
@@ -127,10 +127,10 @@ Qt3DCore::QNodeId BlendedClipAnimator::blendTreeRootId() const
return m_blendTreeRootId;
}
-void BlendedClipAnimator::setNormalizedLocalTime(float normalizedTime)
+void BlendedClipAnimator::setNormalizedLocalTime(float normalizedTime, bool allowMarkDirty)
{
m_normalizedLocalTime = normalizedTime;
- if (isValidNormalizedTime(m_normalizedLocalTime))
+ if (isValidNormalizedTime(m_normalizedLocalTime) && allowMarkDirty)
setDirty(Handler::BlendedClipAnimatorDirty);
}
diff --git a/src/animation/backend/blendedclipanimator_p.h b/src/animation/backend/blendedclipanimator_p.h
index 04f609438..2396cdd74 100644
--- a/src/animation/backend/blendedclipanimator_p.h
+++ b/src/animation/backend/blendedclipanimator_p.h
@@ -70,7 +70,7 @@ public:
Qt3DCore::QNodeId mapperId() const { return m_mapperId; }
Qt3DCore::QNodeId clockId() const { return m_clockId; }
bool isRunning() const { return m_running; }
- void setNormalizedLocalTime(float normalizedTime);
+ void setNormalizedLocalTime(float normalizedTime, bool allowMarkDirty = true);
float normalizedLocalTime() const { return m_normalizedLocalTime; }
// Called by BuildBlendTreeJob
diff --git a/src/animation/backend/clipanimator.cpp b/src/animation/backend/clipanimator.cpp
index 32b02d2bb..5d46e321a 100644
--- a/src/animation/backend/clipanimator.cpp
+++ b/src/animation/backend/clipanimator.cpp
@@ -95,10 +95,10 @@ void ClipAnimator::setRunning(bool running)
setDirty(Handler::ClipAnimatorDirty);
}
-void ClipAnimator::setNormalizedLocalTime(float normalizedTime)
+void ClipAnimator::setNormalizedLocalTime(float normalizedTime, bool allowMarkDirty)
{
m_normalizedLocalTime = normalizedTime;
- if (isValidNormalizedTime(normalizedTime))
+ if (isValidNormalizedTime(normalizedTime) && allowMarkDirty)
setDirty(Handler::ClipAnimatorDirty);
}
diff --git a/src/animation/backend/clipanimator_p.h b/src/animation/backend/clipanimator_p.h
index d154bdab9..65fc6bdc8 100644
--- a/src/animation/backend/clipanimator_p.h
+++ b/src/animation/backend/clipanimator_p.h
@@ -77,7 +77,7 @@ public:
bool isRunning() const { return m_running; }
void setLoops(int loops) { m_loops = loops; }
int loops() const { return m_loops; }
- void setNormalizedLocalTime(float normalizedLocalTime);
+ void setNormalizedLocalTime(float normalizedLocalTime, bool allowMarkDirty = true);
float normalizedLocalTime() const { return m_normalizedLocalTime; }
void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
diff --git a/src/animation/backend/evaluateblendclipanimatorjob.cpp b/src/animation/backend/evaluateblendclipanimatorjob.cpp
index 8a5f1e533..69df26992 100644
--- a/src/animation/backend/evaluateblendclipanimatorjob.cpp
+++ b/src/animation/backend/evaluateblendclipanimatorjob.cpp
@@ -125,7 +125,6 @@ void EvaluateBlendClipAnimatorJob::run()
blendedClipAnimator->setLastGlobalTimeNS(globalTimeNS);
blendedClipAnimator->setLastLocalTime(localTime);
blendedClipAnimator->setLastNormalizedLocalTime(float(phase));
- blendedClipAnimator->setNormalizedLocalTime(-1.0f); // Re-set to something invalid.
blendedClipAnimator->setCurrentLoop(animatorData.currentLoop);
// Prepare the change record
@@ -140,6 +139,11 @@ void EvaluateBlendClipAnimatorJob::run()
// Trigger callbacks either on this thread or by notifying the gui thread.
auto callbacks = prepareCallbacks(mappingData, blendedResults);
+ // Update the normalized time on the backend node so that
+ // frontend <-> backend sync will not mark things dirty
+ // unless the frontend normalized time really is different
+ blendedClipAnimator->setNormalizedLocalTime(record.normalizedTime, false);
+
setPostFrameData(record, callbacks);
}
diff --git a/src/animation/backend/evaluateclipanimatorjob.cpp b/src/animation/backend/evaluateclipanimatorjob.cpp
index 914a38139..84d08543e 100644
--- a/src/animation/backend/evaluateclipanimatorjob.cpp
+++ b/src/animation/backend/evaluateclipanimatorjob.cpp
@@ -100,7 +100,6 @@ void EvaluateClipAnimatorJob::run()
clipAnimator->setLastGlobalTimeNS(globalTimeNS);
clipAnimator->setLastLocalTime(preEvaluationDataForClip.localTime);
clipAnimator->setLastNormalizedLocalTime(preEvaluationDataForClip.normalizedLocalTime);
- clipAnimator->setNormalizedLocalTime(-1.0f); // Re-set to something invalid.
// Prepare property changes (if finalFrame it also prepares the change for the running property for the frontend)
auto record = prepareAnimationRecord(clipAnimator->peerId(),
@@ -112,6 +111,11 @@ void EvaluateClipAnimatorJob::run()
// Trigger callbacks either on this thread or by notifying the gui thread.
auto callbacks = prepareCallbacks(clipAnimator->mappingData(), formattedClipResults);
+ // Update the normalized time on the backend node so that
+ // frontend <-> backend sync will not mark things dirty
+ // unless the frontend normalized time really is different
+ clipAnimator->setNormalizedLocalTime(record.normalizedTime, false);
+
setPostFrameData(record, callbacks);
}