summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2019-09-19 21:01:13 +0100
committerMike Krus <mike.krus@kdab.com>2019-09-20 08:18:58 +0100
commitde4c982ceeb2abcdec8b214fd95e6e5d5d72b9ff (patch)
tree5a9e956859a9b38f2758d3d99c35e8d39b70fc55
parent37e1808b9d24540a962aa6103e6d2638daea15c0 (diff)
Update QBlendedClipAnimator to use direct sync
Change-Id: I6b00f22196d29b5219e27e5084c379b69b68c6e5 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/animation/backend/blendedclipanimator.cpp64
-rw-r--r--src/animation/backend/blendedclipanimator_p.h3
-rw-r--r--src/animation/frontend/qanimationaspect.cpp2
-rw-r--r--tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp73
4 files changed, 63 insertions, 79 deletions
diff --git a/src/animation/backend/blendedclipanimator.cpp b/src/animation/backend/blendedclipanimator.cpp
index fe8a5d815..254883478 100644
--- a/src/animation/backend/blendedclipanimator.cpp
+++ b/src/animation/backend/blendedclipanimator.cpp
@@ -36,6 +36,9 @@
#include "blendedclipanimator_p.h"
#include <Qt3DAnimation/qblendedclipanimator.h>
+#include <Qt3DAnimation/qchannelmapper.h>
+#include <Qt3DAnimation/qclock.h>
+#include <Qt3DAnimation/qabstractclipblendnode.h>
#include <Qt3DAnimation/private/qblendedclipanimator_p.h>
#include <Qt3DAnimation/private/qanimationcallbacktrigger_p.h>
#include <Qt3DCore/qpropertyupdatedchange.h>
@@ -57,19 +60,6 @@ BlendedClipAnimator::BlendedClipAnimator()
{
}
-void BlendedClipAnimator::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QBlendedClipAnimatorData>>(change);
- 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;
- m_normalizedLocalTime = data.normalizedTime;
- setDirty(Handler::BlendedClipAnimatorDirty);
-}
-
double BlendedClipAnimator::lastLocalTime() const
{
return m_lastLocalTime;
@@ -167,30 +157,32 @@ void BlendedClipAnimator::setNormalizedLocalTime(float normalizedTime)
setDirty(Handler::BlendedClipAnimatorDirty);
}
-void BlendedClipAnimator::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
-{
- switch (e->type()) {
- case Qt3DCore::PropertyUpdated: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("blendTree"))
- 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"))
- m_loops = change->value().toInt();
- else if (change->propertyName() == QByteArrayLiteral("normalizedTime"))
- setNormalizedLocalTime(change->value().toFloat());
- break;
- }
+void BlendedClipAnimator::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
+{
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const QBlendedClipAnimator *node = qobject_cast<const QBlendedClipAnimator *>(frontEnd);
+ if (!node)
+ return;
- default:
- break;
- }
- BackendNode::sceneChangeEvent(e);
+ auto id = Qt3DCore::qIdForNode(node->blendTree());
+ if (id != m_blendTreeRootId)
+ setBlendTreeRootId(id);
+ id = Qt3DCore::qIdForNode(node->channelMapper());
+ if (m_mapperId != id)
+ setMapperId(id);
+ id = Qt3DCore::qIdForNode(node->clock());
+ if (m_clockId != id)
+ setClockId(id);
+
+ if (m_running != node->isRunning())
+ setRunning(node->isRunning());
+ if (m_loops != node->loopCount())
+ m_loops = node->loopCount();
+ if (!qFuzzyCompare(m_normalizedLocalTime, node->normalizedTime()))
+ setNormalizedLocalTime(node->normalizedTime());
+
+ if (firstTime)
+ setDirty(Handler::BlendedClipAnimatorDirty);
}
} // namespace Animation
diff --git a/src/animation/backend/blendedclipanimator_p.h b/src/animation/backend/blendedclipanimator_p.h
index 09a071c06..f47b55796 100644
--- a/src/animation/backend/blendedclipanimator_p.h
+++ b/src/animation/backend/blendedclipanimator_p.h
@@ -64,7 +64,7 @@ public:
BlendedClipAnimator();
void cleanup();
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
Qt3DCore::QNodeId blendTreeRootId() const;
Qt3DCore::QNodeId mapperId() const { return m_mapperId; }
@@ -112,7 +112,6 @@ public:
}
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
Qt3DCore::QNodeId m_blendTreeRootId;
Qt3DCore::QNodeId m_mapperId;
Qt3DCore::QNodeId m_clockId;
diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp
index 8e7103732..13477ab57 100644
--- a/src/animation/frontend/qanimationaspect.cpp
+++ b/src/animation/frontend/qanimationaspect.cpp
@@ -113,7 +113,7 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent)
registerBackendType<QClipAnimator, true>(
QSharedPointer<Animation::NodeFunctor<Animation::ClipAnimator, Animation::ClipAnimatorManager>>::create(d->m_handler.data(),
d->m_handler->clipAnimatorManager()));
- registerBackendType<QBlendedClipAnimator>(
+ registerBackendType<QBlendedClipAnimator, true>(
QSharedPointer<Animation::NodeFunctor<Animation::BlendedClipAnimator, Animation::BlendedClipAnimatorManager>>::create(d->m_handler.data(),
d->m_handler->blendedClipAnimatorManager()));
registerBackendType<QAbstractChannelMapping>(
diff --git a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp
index c0e1581f9..bb95fe979 100644
--- a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp
+++ b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp
@@ -29,6 +29,7 @@
#include <QtTest/QTest>
#include <Qt3DAnimation/private/blendedclipanimator_p.h>
#include <Qt3DAnimation/qanimationcliploader.h>
+#include <Qt3DAnimation/qadditiveclipblend.h>
#include <Qt3DAnimation/qblendedclipanimator.h>
#include <Qt3DCore/private/qnode_p.h>
#include <Qt3DCore/private/qscene_p.h>
@@ -114,7 +115,7 @@ private Q_SLOTS:
Qt3DAnimation::Animation::Handler handler;
backendBlendedClipAnimator.setHandler(&handler);
- simulateInitialization(&blendedClipAnimator, &backendBlendedClipAnimator);
+ simulateInitializationSync(&blendedClipAnimator, &backendBlendedClipAnimator);
// THEN
QCOMPARE(backendBlendedClipAnimator.isEnabled(), true);
@@ -131,7 +132,7 @@ private Q_SLOTS:
backendBlendedClipAnimator.setHandler(&handler);
blendedClipAnimator.setEnabled(false);
- simulateInitialization(&blendedClipAnimator, &backendBlendedClipAnimator);
+ simulateInitializationSync(&blendedClipAnimator, &backendBlendedClipAnimator);
// THEN
QCOMPARE(backendBlendedClipAnimator.peerId(), blendedClipAnimator.id());
@@ -142,61 +143,53 @@ private Q_SLOTS:
void checkSceneChangeEvents()
{
// GIVEN
+ Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator;
Qt3DAnimation::Animation::Handler handler;
backendBlendedClipAnimator.setHandler(&handler);
+ simulateInitializationSync(&blendedClipAnimator, &backendBlendedClipAnimator);
{
- // WHEN
- const bool newValue = false;
- const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
- change->setPropertyName("enabled");
- change->setValue(newValue);
- backendBlendedClipAnimator.sceneChangeEvent(change);
-
- // THEN
+ // WHEN
+ const bool newValue = false;
+ blendedClipAnimator.setEnabled(newValue);
+ backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
+
+ // THEN
QCOMPARE(backendBlendedClipAnimator.isEnabled(), newValue);
}
{
- // WHEN
- const Qt3DCore::QNodeId newValue = Qt3DCore::QNodeId::createId();
- const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
- change->setPropertyName("blendTree");
- change->setValue(QVariant::fromValue(newValue));
- backendBlendedClipAnimator.sceneChangeEvent(change);
-
- // THEN
- QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), newValue);
+ // WHEN
+ auto blendTree = new Qt3DAnimation::QAdditiveClipBlend();
+ blendedClipAnimator.setBlendTree(blendTree);
+ backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
+
+ // THEN
+ QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), blendTree->id());
}
{
- // WHEN
- const Qt3DCore::QNodeId newValue = Qt3DCore::QNodeId::createId();
- const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
- change->setPropertyName("channelMapper");
- change->setValue(QVariant::fromValue(newValue));
- backendBlendedClipAnimator.sceneChangeEvent(change);
-
- // THEN
- QCOMPARE(backendBlendedClipAnimator.mapperId(), newValue);
+ // WHEN
+ auto channelMapper = new Qt3DAnimation::QChannelMapper();
+ blendedClipAnimator.setChannelMapper(channelMapper);
+ backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
+
+ // THEN
+ QCOMPARE(backendBlendedClipAnimator.mapperId(), channelMapper->id());
}
{
- // WHEN
- const bool newValue = true;
- const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
- change->setPropertyName("running");
- change->setValue(QVariant::fromValue(newValue));
- backendBlendedClipAnimator.sceneChangeEvent(change);
-
- // THEN
+ // WHEN
+ const bool newValue = true;
+ blendedClipAnimator.setRunning(newValue);
+ backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
+
+ // THEN
QCOMPARE(backendBlendedClipAnimator.isRunning(), newValue);
}
{
// WHEN
const int newValue = 883;
- const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
- change->setPropertyName("loops");
- change->setValue(QVariant::fromValue(newValue));
- backendBlendedClipAnimator.sceneChangeEvent(change);
+ blendedClipAnimator.setLoopCount(newValue);
+ backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
// THEN
QCOMPARE(backendBlendedClipAnimator.loops(), newValue);