summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChip Collier <gregory.collier@kdab.com>2017-07-21 11:02:35 +0200
committerSean Harmer <sean.harmer@kdab.com>2017-07-24 09:02:37 +0000
commit721c44edfdedb0360181f8160144709867ed8749 (patch)
tree59f63b8a52a71632fac358b928daef35fb57a0ff
parente256972b2f1be3a0ccf2a0fa31424171ba856e01 (diff)
Add clock property to QAbstractClipAnimator
Introduces "clock" property to QAbstractClipAnimator and updates associated tests. Updated backend animator nodes and associated evaluation jobs. Change-Id: Id18cabdd710b9b7253772642f21f63043d316a42 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/animation/backend/animationutils_p.h5
-rw-r--r--src/animation/backend/blendedclipanimator.cpp10
-rw-r--r--src/animation/backend/blendedclipanimator_p.h3
-rw-r--r--src/animation/backend/clipanimator.cpp11
-rw-r--r--src/animation/backend/clipanimator_p.h3
-rw-r--r--src/animation/backend/clock.cpp1
-rw-r--r--src/animation/backend/clock_p.h1
-rw-r--r--src/animation/backend/evaluateblendclipanimatorjob.cpp4
-rw-r--r--src/animation/backend/evaluateclipanimatorjob.cpp4
-rw-r--r--src/animation/backend/handler.cpp1
-rw-r--r--src/animation/backend/handler_p.h3
-rw-r--r--src/animation/backend/managers_p.h11
-rw-r--r--src/animation/frontend/qabstractclipanimator.cpp26
-rw-r--r--src/animation/frontend/qabstractclipanimator.h5
-rw-r--r--src/animation/frontend/qabstractclipanimator_p.h3
-rw-r--r--src/animation/frontend/qanimationaspect.cpp6
-rw-r--r--src/animation/frontend/qclipanimator.cpp2
-rw-r--r--tests/auto/animation/animationutils/tst_animationutils.cpp13
-rw-r--r--tests/auto/animation/clipanimator/tst_clipanimator.cpp19
-rw-r--r--tests/auto/animation/qclipanimator/tst_qclipanimator.cpp57
20 files changed, 175 insertions, 13 deletions
diff --git a/src/animation/backend/animationutils_p.h b/src/animation/backend/animationutils_p.h
index 6f00fc632..bcc50fce2 100644
--- a/src/animation/backend/animationutils_p.h
+++ b/src/animation/backend/animationutils_p.h
@@ -49,6 +49,7 @@
//
#include <Qt3DAnimation/private/qt3danimation_global_p.h>
+#include <Qt3DAnimation/private/clock_p.h>
#include <Qt3DAnimation/qanimationcallback.h>
#include <Qt3DCore/qnodeid.h>
#include <Qt3DCore/qscenechange.h>
@@ -114,11 +115,11 @@ struct AnimationCallbackAndValue
};
template<typename Animator>
-AnimatorEvaluationData evaluationDataForAnimator(Animator animator, qint64 globalTime)
+AnimatorEvaluationData evaluationDataForAnimator(Animator animator, Clock* clock, qint64 globalTime)
{
AnimatorEvaluationData data;
data.loopCount = animator->loops();
- data.playbackRate = 1.0; // should be a property on the animator
+ data.playbackRate = clock != nullptr ? clock->playbackRate() : 1.0;
// Convert global time from nsec to sec
data.startTime = double(animator->startTime()) / 1.0e9;
data.globalTime = double(globalTime) / 1.0e9;
diff --git a/src/animation/backend/blendedclipanimator.cpp b/src/animation/backend/blendedclipanimator.cpp
index 46b3b87fa..ec0a5027a 100644
--- a/src/animation/backend/blendedclipanimator.cpp
+++ b/src/animation/backend/blendedclipanimator.cpp
@@ -60,6 +60,7 @@ void BlendedClipAnimator::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeB
const QBlendedClipAnimatorData &data = typedChange->data;
m_blendTreeRootId = data.blendTreeRootId;
m_mapperId = data.mapperId;
+ m_clockId = data.clockId;
m_running = data.running;
m_loops = data.loops;
setDirty(Handler::BlendedClipAnimatorDirty);
@@ -71,6 +72,7 @@ void BlendedClipAnimator::cleanup()
m_handler = nullptr;
m_blendTreeRootId = Qt3DCore::QNodeId();
m_mapperId = Qt3DCore::QNodeId();
+ m_clockId = Qt3DCore::QNodeId();
m_running = false;
m_startGlobalTime = 0;
m_currentLoop = 0;
@@ -89,6 +91,12 @@ void BlendedClipAnimator::setMapperId(Qt3DCore::QNodeId mapperId)
setDirty(Handler::BlendedClipAnimatorDirty);
}
+void BlendedClipAnimator::setClockId(Qt3DCore::QNodeId clockId)
+{
+ m_clockId = clockId;
+ setDirty(Handler::BlendedClipAnimatorDirty);
+}
+
void BlendedClipAnimator::setRunning(bool running)
{
m_running = running;
@@ -130,6 +138,8 @@ void BlendedClipAnimator::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
setBlendTreeRootId(change->value().value<Qt3DCore::QNodeId>());
else if (change->propertyName() == QByteArrayLiteral("channelMapper"))
setMapperId(change->value().value<Qt3DCore::QNodeId>());
+ else if (change->propertyName() == QByteArrayLiteral("clock"))
+ setClockId(change->value().value<Qt3DCore::QNodeId>());
else if (change->propertyName() == QByteArrayLiteral("running"))
setRunning(change->value().toBool());
else if (change->propertyName() == QByteArrayLiteral("loops"))
diff --git a/src/animation/backend/blendedclipanimator_p.h b/src/animation/backend/blendedclipanimator_p.h
index e6311bc59..e15a892bb 100644
--- a/src/animation/backend/blendedclipanimator_p.h
+++ b/src/animation/backend/blendedclipanimator_p.h
@@ -68,6 +68,7 @@ public:
Qt3DCore::QNodeId blendTreeRootId() const;
Qt3DCore::QNodeId mapperId() const { return m_mapperId; }
+ Qt3DCore::QNodeId clockId() const { return m_clockId; }
bool isRunning() const { return m_running; }
// Called by BuildBlendTreeJob
@@ -75,6 +76,7 @@ public:
void setBlendTreeRootId(Qt3DCore::QNodeId blendTreeRootId);
void setMapperId(Qt3DCore::QNodeId mapperId);
+ void setClockId(Qt3DCore::QNodeId clockId);
void setRunning(bool running);
void setStartTime(qint64 globalTime) { m_startGlobalTime = globalTime; }
@@ -96,6 +98,7 @@ private:
void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
Qt3DCore::QNodeId m_blendTreeRootId;
Qt3DCore::QNodeId m_mapperId;
+ Qt3DCore::QNodeId m_clockId;
bool m_running;
qint64 m_startGlobalTime;
diff --git a/src/animation/backend/clipanimator.cpp b/src/animation/backend/clipanimator.cpp
index ea31698d0..9a5cce2e2 100644
--- a/src/animation/backend/clipanimator.cpp
+++ b/src/animation/backend/clipanimator.cpp
@@ -53,6 +53,7 @@ ClipAnimator::ClipAnimator()
: BackendNode(ReadWrite)
, m_clipId()
, m_mapperId()
+ , m_clockId()
, m_running(false)
, m_loops(1)
, m_startGlobalTime(0)
@@ -67,6 +68,7 @@ void ClipAnimator::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr
const auto &data = typedChange->data;
m_clipId = data.clipId;
m_mapperId = data.mapperId;
+ m_clockId = data.clockId;
m_running = data.running;
m_loops = data.loops;
setDirty(Handler::ClipAnimatorDirty);
@@ -84,6 +86,12 @@ void ClipAnimator::setMapperId(Qt3DCore::QNodeId mapperId)
setDirty(Handler::ClipAnimatorDirty);
}
+void ClipAnimator::setClockId(Qt3DCore::QNodeId clockId)
+{
+ m_clockId = clockId;
+ setDirty(Handler::ClipAnimatorDirty);
+}
+
void ClipAnimator::setRunning(bool running)
{
m_running = running;
@@ -98,6 +106,7 @@ void ClipAnimator::cleanup()
m_handler = nullptr;
m_clipId = Qt3DCore::QNodeId();
m_mapperId = Qt3DCore::QNodeId();
+ m_clockId = Qt3DCore::QNodeId();
m_running = false;
m_loops = 1;
}
@@ -111,6 +120,8 @@ void ClipAnimator::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
setClipId(change->value().value<Qt3DCore::QNodeId>());
else if (change->propertyName() == QByteArrayLiteral("channelMapper"))
setMapperId(change->value().value<Qt3DCore::QNodeId>());
+ else if (change->propertyName() == QByteArrayLiteral("clock"))
+ setClockId(change->value().value<Qt3DCore::QNodeId>());
else if (change->propertyName() == QByteArrayLiteral("running"))
setRunning(change->value().toBool());
else if (change->propertyName() == QByteArrayLiteral("loops"))
diff --git a/src/animation/backend/clipanimator_p.h b/src/animation/backend/clipanimator_p.h
index f0f631a5c..628a15e24 100644
--- a/src/animation/backend/clipanimator_p.h
+++ b/src/animation/backend/clipanimator_p.h
@@ -70,6 +70,8 @@ public:
Qt3DCore::QNodeId clipId() const { return m_clipId; }
void setMapperId(Qt3DCore::QNodeId mapperId);
Qt3DCore::QNodeId mapperId() const { return m_mapperId; }
+ void setClockId(Qt3DCore::QNodeId clockId);
+ Qt3DCore::QNodeId clockId() const { return m_clockId; }
void setRunning(bool running);
bool isRunning() const { return m_running; }
@@ -98,6 +100,7 @@ private:
Qt3DCore::QNodeId m_clipId;
Qt3DCore::QNodeId m_mapperId;
+ Qt3DCore::QNodeId m_clockId;
bool m_running;
int m_loops;
diff --git a/src/animation/backend/clock.cpp b/src/animation/backend/clock.cpp
index 870c79078..13d82f2e5 100644
--- a/src/animation/backend/clock.cpp
+++ b/src/animation/backend/clock.cpp
@@ -37,6 +37,7 @@
#include "clock_p.h"
#include <Qt3DAnimation/qclock.h>
#include <Qt3DAnimation/private/qclock_p.h>
+#include <Qt3DAnimation/private/animationutils_p.h>
#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DCore/private/qpropertyupdatedchangebase_p.h>
diff --git a/src/animation/backend/clock_p.h b/src/animation/backend/clock_p.h
index a8dd86890..9ae8c60a9 100644
--- a/src/animation/backend/clock_p.h
+++ b/src/animation/backend/clock_p.h
@@ -49,7 +49,6 @@
//
#include <Qt3DAnimation/private/backendnode_p.h>
-#include <Qt3DAnimation/private/animationutils_p.h>
#include <Qt3DCore/qnodeid.h>
QT_BEGIN_NAMESPACE
diff --git a/src/animation/backend/evaluateblendclipanimatorjob.cpp b/src/animation/backend/evaluateblendclipanimatorjob.cpp
index e0f52765f..be05f7ec0 100644
--- a/src/animation/backend/evaluateblendclipanimatorjob.cpp
+++ b/src/animation/backend/evaluateblendclipanimatorjob.cpp
@@ -72,9 +72,11 @@ void EvaluateBlendClipAnimatorJob::run()
Q_ASSERT(blendTreeRootNode);
const double duration = blendTreeRootNode->duration();
+ Clock *clock = m_handler->clockManager()->lookupResource(blendedClipAnimator->clockId());
+
// Calculate the phase given the blend tree duration and global time
const qint64 globalTime = m_handler->simulationTime();
- const AnimatorEvaluationData animatorData = evaluationDataForAnimator(blendedClipAnimator, globalTime);
+ const AnimatorEvaluationData animatorData = evaluationDataForAnimator(blendedClipAnimator, clock, globalTime);
int currentLoop = 0;
const double phase = phaseFromGlobalTime(animatorData.globalTime,
animatorData.startTime,
diff --git a/src/animation/backend/evaluateclipanimatorjob.cpp b/src/animation/backend/evaluateclipanimatorjob.cpp
index e9f3d1da8..6dab51d63 100644
--- a/src/animation/backend/evaluateclipanimatorjob.cpp
+++ b/src/animation/backend/evaluateclipanimatorjob.cpp
@@ -62,11 +62,13 @@ void EvaluateClipAnimatorJob::run()
ClipAnimator *clipAnimator = m_handler->clipAnimatorManager()->data(m_clipAnimatorHandle);
Q_ASSERT(clipAnimator);
+ Clock *clock = m_handler->clockManager()->lookupResource(clipAnimator->clockId());
+
// Evaluate the fcurves
AnimationClip *clip = m_handler->animationClipLoaderManager()->lookupResource(clipAnimator->clipId());
Q_ASSERT(clip);
// Prepare for evaluation (convert global time to local time ....)
- const AnimatorEvaluationData animatorEvaluationData = evaluationDataForAnimator(clipAnimator, globalTime);
+ const AnimatorEvaluationData animatorEvaluationData = evaluationDataForAnimator(clipAnimator, clock, globalTime);
const ClipEvaluationData preEvaluationDataForClip = evaluationDataForClip(clip, animatorEvaluationData);
const ClipResults channelResults = evaluateClipAtLocalTime(clip, preEvaluationDataForClip.localTime);
diff --git a/src/animation/backend/handler.cpp b/src/animation/backend/handler.cpp
index 33bc8c9f4..8ced81cd1 100644
--- a/src/animation/backend/handler.cpp
+++ b/src/animation/backend/handler.cpp
@@ -52,6 +52,7 @@ namespace Animation {
Handler::Handler()
: m_animationClipLoaderManager(new AnimationClipLoaderManager)
+ , m_clockManager(new ClockManager)
, m_clipAnimatorManager(new ClipAnimatorManager)
, m_blendedClipAnimatorManager(new BlendedClipAnimatorManager)
, m_channelMappingManager(new ChannelMappingManager)
diff --git a/src/animation/backend/handler_p.h b/src/animation/backend/handler_p.h
index 97adfdc13..864d62cba 100644
--- a/src/animation/backend/handler_p.h
+++ b/src/animation/backend/handler_p.h
@@ -65,6 +65,7 @@ namespace Animation {
class AnimationClip;
class AnimationClipLoaderManager;
+class ClockManager;
class ClipAnimator;
class ClipAnimatorManager;
class BlendedClipAnimator;
@@ -108,6 +109,7 @@ public:
QVector<HBlendedClipAnimator> runningBlenndedClipAnimators() const { return m_runningBlendedClipAnimators; }
AnimationClipLoaderManager *animationClipLoaderManager() const Q_DECL_NOTHROW { return m_animationClipLoaderManager.data(); }
+ ClockManager *clockManager() const Q_DECL_NOTHROW { return m_clockManager.data(); }
ClipAnimatorManager *clipAnimatorManager() const Q_DECL_NOTHROW { return m_clipAnimatorManager.data(); }
BlendedClipAnimatorManager *blendedClipAnimatorManager() const Q_DECL_NOTHROW { return m_blendedClipAnimatorManager.data(); }
ChannelMappingManager *channelMappingManager() const Q_DECL_NOTHROW { return m_channelMappingManager.data(); }
@@ -121,6 +123,7 @@ public:
private:
QScopedPointer<AnimationClipLoaderManager> m_animationClipLoaderManager;
+ QScopedPointer<ClockManager> m_clockManager;
QScopedPointer<ClipAnimatorManager> m_clipAnimatorManager;
QScopedPointer<BlendedClipAnimatorManager> m_blendedClipAnimatorManager;
QScopedPointer<ChannelMappingManager> m_channelMappingManager;
diff --git a/src/animation/backend/managers_p.h b/src/animation/backend/managers_p.h
index f99ed0698..589e5ec3b 100644
--- a/src/animation/backend/managers_p.h
+++ b/src/animation/backend/managers_p.h
@@ -54,6 +54,7 @@
#include <QtGlobal>
#include <Qt3DAnimation/private/handle_types_p.h>
#include <Qt3DAnimation/private/animationclip_p.h>
+#include <Qt3DAnimation/private/clock_p.h>
#include <Qt3DAnimation/private/blendedclipanimator_p.h>
#include <Qt3DAnimation/private/clipanimator_p.h>
#include <Qt3DAnimation/private/channelmapping_p.h>
@@ -77,6 +78,16 @@ public:
AnimationClipLoaderManager() {}
};
+class ClockManager : public Qt3DCore::QResourceManager<
+ Clock,
+ Qt3DCore::QNodeId,
+ 16,
+ Qt3DCore::ArrayAllocatingPolicy>
+{
+public:
+ ClockManager() {}
+};
+
class ClipAnimatorManager : public Qt3DCore::QResourceManager<
ClipAnimator,
Qt3DCore::QNodeId,
diff --git a/src/animation/frontend/qabstractclipanimator.cpp b/src/animation/frontend/qabstractclipanimator.cpp
index 9484aea44..d72085b6e 100644
--- a/src/animation/frontend/qabstractclipanimator.cpp
+++ b/src/animation/frontend/qabstractclipanimator.cpp
@@ -40,6 +40,7 @@
#include "qabstractclipanimator.h"
#include "qabstractclipanimator_p.h"
#include <Qt3DAnimation/qchannelmapper.h>
+#include <Qt3DAnimation/qclock.h>
QT_BEGIN_NAMESPACE
@@ -48,6 +49,7 @@ namespace Qt3DAnimation {
QAbstractClipAnimatorPrivate::QAbstractClipAnimatorPrivate()
: Qt3DCore::QComponentPrivate()
, m_mapper(nullptr)
+ , m_clock(nullptr)
, m_running(false)
, m_loops(1)
{
@@ -174,6 +176,12 @@ int QAbstractClipAnimator::loopCount() const
return d->m_loops;
}
+QClock *QAbstractClipAnimator::clock() const
+{
+ Q_D(const QAbstractClipAnimator);
+ return d->m_clock;
+}
+
void QAbstractClipAnimator::setRunning(bool running)
{
Q_D(QAbstractClipAnimator);
@@ -213,6 +221,24 @@ void QAbstractClipAnimator::setLoopCount(int loops)
emit loopCountChanged(loops);
}
+void QAbstractClipAnimator::setClock(QClock *clock)
+{
+ Q_D(QAbstractClipAnimator);
+ if (d->m_clock == clock)
+ return;
+
+ if (d->m_clock)
+ d->unregisterDestructionHelper(d->m_clock);
+
+ if (clock && !clock->parent())
+ clock->setParent(this);
+ d->m_clock = clock;
+
+ if (d->m_clock)
+ d->registerDestructionHelper(d->m_clock, &QAbstractClipAnimator::setClock, d->m_clock);
+ emit clockChanged(clock);
+}
+
/*!
Starts the animation.
*/
diff --git a/src/animation/frontend/qabstractclipanimator.h b/src/animation/frontend/qabstractclipanimator.h
index bd38fd68b..8fdb114f3 100644
--- a/src/animation/frontend/qabstractclipanimator.h
+++ b/src/animation/frontend/qabstractclipanimator.h
@@ -49,6 +49,7 @@ namespace Qt3DAnimation {
class QAnimationClip;
class QChannelMapper;
+class QClock;
class QAbstractClipAnimatorPrivate;
class QT3DANIMATIONSHARED_EXPORT QAbstractClipAnimator : public Qt3DCore::QComponent
@@ -57,6 +58,7 @@ class QT3DANIMATIONSHARED_EXPORT QAbstractClipAnimator : public Qt3DCore::QCompo
Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
Q_PROPERTY(int loops READ loopCount WRITE setLoopCount NOTIFY loopCountChanged)
Q_PROPERTY(Qt3DAnimation::QChannelMapper *channelMapper READ channelMapper WRITE setChannelMapper NOTIFY channelMapperChanged)
+ Q_PROPERTY(Qt3DAnimation::QClock *clock READ clock WRITE setClock NOTIFY clockChanged)
public:
enum Loops { Infinite = -1 };
@@ -67,11 +69,13 @@ public:
bool isRunning() const;
Qt3DAnimation::QChannelMapper *channelMapper() const;
int loopCount() const;
+ Qt3DAnimation::QClock *clock() const;
public Q_SLOTS:
void setRunning(bool running);
void setChannelMapper(Qt3DAnimation::QChannelMapper *channelMapper);
void setLoopCount(int loops);
+ void setClock(Qt3DAnimation::QClock *clock);
void start();
void stop();
@@ -80,6 +84,7 @@ Q_SIGNALS:
void runningChanged(bool running);
void channelMapperChanged(Qt3DAnimation::QChannelMapper *channelMapper);
void loopCountChanged(int loops);
+ void clockChanged(Qt3DAnimation::QClock *clock);
protected:
explicit QAbstractClipAnimator(Qt3DCore::QNode *parent = nullptr);
diff --git a/src/animation/frontend/qabstractclipanimator_p.h b/src/animation/frontend/qabstractclipanimator_p.h
index 58553c8c1..4b0ef3339 100644
--- a/src/animation/frontend/qabstractclipanimator_p.h
+++ b/src/animation/frontend/qabstractclipanimator_p.h
@@ -58,6 +58,7 @@ QT_BEGIN_NAMESPACE
namespace Qt3DAnimation {
class QChannelMapper;
+class QClock;
class QAbstractClipAnimatorPrivate : public Qt3DCore::QComponentPrivate
{
@@ -67,6 +68,7 @@ public:
Q_DECLARE_PUBLIC(QAbstractClipAnimator)
Qt3DAnimation::QChannelMapper *m_mapper;
+ Qt3DAnimation::QClock *m_clock;
bool m_running;
int m_loops;
};
@@ -74,6 +76,7 @@ public:
struct QAbstractClipAnimatorData
{
Qt3DCore::QNodeId mapperId;
+ Qt3DCore::QNodeId clockId;
bool running;
int loops;
};
diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp
index 00f97d5b6..bb786afff 100644
--- a/src/animation/frontend/qanimationaspect.cpp
+++ b/src/animation/frontend/qanimationaspect.cpp
@@ -40,6 +40,7 @@
#include "qanimationaspect.h"
#include "qanimationaspect_p.h"
#include <Qt3DAnimation/qabstractanimationclip.h>
+#include <Qt3DAnimation/qclock.h>
#include <Qt3DAnimation/qblendedclipanimator.h>
#include <Qt3DAnimation/qclipanimator.h>
#include <Qt3DAnimation/qchannelmapping.h>
@@ -95,7 +96,10 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent)
registerBackendType<QAbstractAnimationClip>(
QSharedPointer<Animation::NodeFunctor<Animation::AnimationClip, Animation::AnimationClipLoaderManager>>::create(d->m_handler.data(),
- d->m_handler->animationClipLoaderManager()));
+ d->m_handler->animationClipLoaderManager()));
+ registerBackendType<QClock>(
+ QSharedPointer<Animation::NodeFunctor<Animation::Clock, Animation::ClockManager>>::create(d->m_handler.data(),
+ d->m_handler->clockManager()));
registerBackendType<QClipAnimator>(
QSharedPointer<Animation::NodeFunctor<Animation::ClipAnimator, Animation::ClipAnimatorManager>>::create(d->m_handler.data(),
d->m_handler->clipAnimatorManager()));
diff --git a/src/animation/frontend/qclipanimator.cpp b/src/animation/frontend/qclipanimator.cpp
index 3359a70ea..4fe21828f 100644
--- a/src/animation/frontend/qclipanimator.cpp
+++ b/src/animation/frontend/qclipanimator.cpp
@@ -41,6 +41,7 @@
#include "qclipanimator_p.h"
#include <Qt3DAnimation/qabstractanimationclip.h>
#include <Qt3DAnimation/qchannelmapper.h>
+#include <Qt3DAnimation/qclock.h>
#include <Qt3DAnimation/private/qanimationcallbacktrigger_p.h>
QT_BEGIN_NAMESPACE
@@ -161,6 +162,7 @@ Qt3DCore::QNodeCreatedChangeBasePtr QClipAnimator::createNodeCreationChange() co
Q_D(const QClipAnimator);
data.clipId = Qt3DCore::qIdForNode(d->m_clip);
data.mapperId = Qt3DCore::qIdForNode(d->m_mapper);
+ data.clockId = Qt3DCore::qIdForNode(d->m_clock);
data.running = d->m_running;
data.loops = d->m_loops;
return creationChange;
diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp
index ddde50fc3..14181b893 100644
--- a/tests/auto/animation/animationutils/tst_animationutils.cpp
+++ b/tests/auto/animation/animationutils/tst_animationutils.cpp
@@ -30,6 +30,7 @@
#include <Qt3DAnimation/private/animationclip_p.h>
#include <Qt3DAnimation/private/animationutils_p.h>
#include <Qt3DAnimation/private/blendedclipanimator_p.h>
+#include <Qt3DAnimation/private/clock_p.h>
#include <Qt3DAnimation/private/channelmapper_p.h>
#include <Qt3DAnimation/private/channelmapping_p.h>
#include <Qt3DAnimation/private/clipblendvalue_p.h>
@@ -51,6 +52,7 @@ using namespace Qt3DAnimation::Animation;
Q_DECLARE_METATYPE(Qt3DAnimation::Animation::Handler*)
Q_DECLARE_METATYPE(QVector<ChannelMapping *>)
+Q_DECLARE_METATYPE(Clock *)
Q_DECLARE_METATYPE(ChannelMapper *)
Q_DECLARE_METATYPE(AnimationClip *)
Q_DECLARE_METATYPE(QVector<MappingData>)
@@ -1836,6 +1838,7 @@ private Q_SLOTS:
AnimationClip *clip;
AnimatorEvaluationData animatorData;
ClipEvaluationData clipData;
+ auto* clock = new Clock;
{
handler = new Handler();
@@ -1844,7 +1847,7 @@ private Q_SLOTS:
const int loops = 1;
auto animator = createClipAnimator(handler, globalStartTimeNS, loops);
const qint64 globalTimeNS = 0;
- animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere
+ animatorData = evaluationDataForAnimator(animator, clock, globalTimeNS); // Tested elsewhere
clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime,
animatorData.startTime,
@@ -1865,7 +1868,7 @@ private Q_SLOTS:
const int loops = 1;
auto animator = createClipAnimator(handler, globalStartTimeNS, loops);
const qint64 globalTimeNS = (clip->duration() + 1.0) * 1.0e9; // +1 to ensure beyond end of clip
- animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere
+ animatorData = evaluationDataForAnimator(animator, nullptr, globalTimeNS); // Tested elsewhere
clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime,
animatorData.startTime,
@@ -1886,7 +1889,7 @@ private Q_SLOTS:
const int loops = 0; // Infinite loops
auto animator = createClipAnimator(handler, globalStartTimeNS, loops);
const qint64 globalTimeNS = 2.0 * clip->duration() * 1.0e9;
- animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere
+ animatorData = evaluationDataForAnimator(animator, clock, globalTimeNS); // Tested elsewhere
clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime,
animatorData.startTime,
@@ -1907,7 +1910,7 @@ private Q_SLOTS:
const int loops = 2;
auto animator = createClipAnimator(handler, globalStartTimeNS, loops);
const qint64 globalTimeNS = (2.0 * clip->duration() + 1.0) * 1.0e9; // +1 to ensure beyond end of clip
- animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere
+ animatorData = evaluationDataForAnimator(animator, nullptr, globalTimeNS); // Tested elsewhere
clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime,
animatorData.startTime,
@@ -2028,7 +2031,7 @@ private Q_SLOTS:
QFETCH(AnimatorEvaluationData, expectedAnimatorData);
// WHEN
- AnimatorEvaluationData actualAnimatorData = evaluationDataForAnimator(animator, globalTimeNS);
+ AnimatorEvaluationData actualAnimatorData = evaluationDataForAnimator(animator, nullptr, globalTimeNS);
// THEN
QCOMPARE(actualAnimatorData.loopCount, expectedAnimatorData.loopCount);
diff --git a/tests/auto/animation/clipanimator/tst_clipanimator.cpp b/tests/auto/animation/clipanimator/tst_clipanimator.cpp
index 615547405..b15e09869 100644
--- a/tests/auto/animation/clipanimator/tst_clipanimator.cpp
+++ b/tests/auto/animation/clipanimator/tst_clipanimator.cpp
@@ -30,6 +30,7 @@
#include <Qt3DAnimation/private/clipanimator_p.h>
#include <Qt3DAnimation/qanimationcliploader.h>
#include <Qt3DAnimation/qclipanimator.h>
+#include <Qt3DAnimation/qclock.h>
#include <Qt3DCore/private/qnode_p.h>
#include <Qt3DCore/private/qscene_p.h>
#include <Qt3DCore/qpropertyupdatedchange.h>
@@ -50,8 +51,10 @@ private Q_SLOTS:
backendAnimator.setHandler(&handler);
Qt3DAnimation::QClipAnimator animator;
auto clip = new Qt3DAnimation::QAnimationClipLoader();
+ auto clock = new Qt3DAnimation::QClock();
animator.setClip(clip);
+ animator.setClock(clock);
animator.setLoopCount(10);
// WHEN
@@ -61,6 +64,7 @@ private Q_SLOTS:
QCOMPARE(backendAnimator.peerId(), animator.id());
QCOMPARE(backendAnimator.isEnabled(), animator.isEnabled());
QCOMPARE(backendAnimator.clipId(), clip->id());
+ QCOMPARE(backendAnimator.clockId(), clock->id());
QCOMPARE(backendAnimator.isRunning(), animator.isRunning());
QCOMPARE(backendAnimator.loops(), animator.loopCount());
}
@@ -76,23 +80,28 @@ private Q_SLOTS:
QVERIFY(backendAnimator.peerId().isNull());
QCOMPARE(backendAnimator.isEnabled(), false);
QCOMPARE(backendAnimator.clipId(), Qt3DCore::QNodeId());
+ QCOMPARE(backendAnimator.clockId(), Qt3DCore::QNodeId());
QCOMPARE(backendAnimator.isRunning(), false);
QCOMPARE(backendAnimator.loops(), 1);
// GIVEN
Qt3DAnimation::QClipAnimator animator;
auto clip = new Qt3DAnimation::QAnimationClipLoader();
+ auto clock = new Qt3DAnimation::QClock();
animator.setClip(clip);
+ animator.setClock(clock);
animator.setRunning(true);
animator.setLoopCount(25);
// WHEN
simulateInitialization(&animator, &backendAnimator);
backendAnimator.setClipId(Qt3DCore::QNodeId::createId());
+ backendAnimator.setClockId(Qt3DCore::QNodeId::createId());
backendAnimator.cleanup();
// THEN
QCOMPARE(backendAnimator.clipId(), Qt3DCore::QNodeId());
+ QCOMPARE(backendAnimator.clockId(), Qt3DCore::QNodeId());
QCOMPARE(backendAnimator.isEnabled(), false);
QCOMPARE(backendAnimator.isRunning(), false);
QCOMPARE(backendAnimator.loops(), 1);
@@ -126,6 +135,16 @@ private Q_SLOTS:
QCOMPARE(backendAnimator.clipId(), newClip->id());
// WHEN
+ auto clock = new Qt3DAnimation::QClock();
+ updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setPropertyName("clock");
+ updateChange->setValue(QVariant::fromValue(clock->id()));
+ backendAnimator.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendAnimator.clockId(), clock->id());
+
+ // WHEN
updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
updateChange->setPropertyName("running");
updateChange->setValue(true);
diff --git a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp
index 1ed4b8f13..6a46b7008 100644
--- a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp
+++ b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp
@@ -30,6 +30,7 @@
#include <QtTest/QTest>
#include <Qt3DAnimation/qanimationcliploader.h>
#include <Qt3DAnimation/qchannelmapper.h>
+#include <Qt3DAnimation/qclock.h>
#include <Qt3DAnimation/qclipanimator.h>
#include <Qt3DAnimation/private/qanimationclip_p.h>
#include <Qt3DAnimation/private/qclipanimator_p.h>
@@ -49,6 +50,7 @@ private Q_SLOTS:
{
qRegisterMetaType<Qt3DAnimation::QAbstractAnimationClip*>();
qRegisterMetaType<Qt3DAnimation::QChannelMapper*>();
+ qRegisterMetaType<Qt3DAnimation::QClock*>();
}
void checkDefaultConstruction()
@@ -59,6 +61,7 @@ private Q_SLOTS:
// THEN
QCOMPARE(animator.clip(), static_cast<Qt3DAnimation::QAbstractAnimationClip *>(nullptr));
QCOMPARE(animator.channelMapper(), static_cast<Qt3DAnimation::QChannelMapper *>(nullptr));
+ QCOMPARE(animator.clock(), static_cast<Qt3DAnimation::QClock*>(nullptr));
QCOMPARE(animator.loopCount(), 1);
}
@@ -111,6 +114,27 @@ private Q_SLOTS:
{
// WHEN
+ QSignalSpy spy(&animator, SIGNAL(clockChanged(Qt3DAnimation::QClock *)));
+ auto clock = new Qt3DAnimation::QClock();
+ animator.setClock(clock);
+
+ // THEN
+ QVERIFY(spy.isValid());
+ QCOMPARE(animator.clock(), clock);
+ QCOMPARE(clock->parent(), &animator);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ animator.setClock(clock);
+
+ // THEN
+ QCOMPARE(animator.clock(), clock);
+ QCOMPARE(spy.count(), 0);
+ }
+
+ {
+ // WHEN
QSignalSpy spy(&animator, SIGNAL(loopCountChanged(int)));
const int newValue = 5;
animator.setLoopCount(newValue);
@@ -138,6 +162,8 @@ private Q_SLOTS:
animator.setClip(clip);
auto mapper = new Qt3DAnimation::QChannelMapper();
animator.setChannelMapper(mapper);
+ auto clock = new Qt3DAnimation::QClock();
+ animator.setClock(clock);
// WHEN
QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges;
@@ -148,7 +174,7 @@ private Q_SLOTS:
// THEN
{
- QCOMPARE(creationChanges.size(), 3);
+ QCOMPARE(creationChanges.size(), 4);
const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QClipAnimatorData>>(creationChanges.first());
const Qt3DAnimation::QClipAnimatorData data = creationChangeData->data;
@@ -159,6 +185,7 @@ private Q_SLOTS:
QCOMPARE(animator.metaObject(), creationChangeData->metaObject());
QCOMPARE(animator.clip()->id(), data.clipId);
QCOMPARE(animator.channelMapper()->id(), data.mapperId);
+ QCOMPARE(animator.clock()->id(), data.clockId);
QCOMPARE(animator.loopCount(), data.loops);
}
@@ -171,7 +198,7 @@ private Q_SLOTS:
// THEN
{
- QCOMPARE(creationChanges.size(), 3);
+ QCOMPARE(creationChanges.size(), 4);
const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QClipAnimatorData>>(creationChanges.first());
@@ -240,6 +267,32 @@ private Q_SLOTS:
QCOMPARE(arbiter.events.size(), 0);
}
+ // GIVEN
+ auto clock = new Qt3DAnimation::QClock;
+ {
+ // WHEN
+ animator.setClock(clock);
+ QCoreApplication::processEvents();
+
+ // THEN
+ QCOMPARE(arbiter.events.size(), 1);
+ auto change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
+ QCOMPARE(change->propertyName(), "clock");
+ QCOMPARE(change->type(), Qt3DCore::PropertyUpdated);
+ QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), clock->id());
+
+ arbiter.events.clear();
+ }
+
+ {
+ // WHEN
+ animator.setClock(clock);
+ QCoreApplication::processEvents();
+
+ // THEN
+ QCOMPARE(arbiter.events.size(), 0);
+ }
+
{
// WHEN
animator.setLoopCount(10);