summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2019-09-20 07:32:08 +0100
committerMike Krus <mike.krus@kdab.com>2019-09-20 11:11:31 +0100
commit722425eccd099936a15b850698c5fc3047f162a2 (patch)
tree21406593fac2594c4bdfa936beaf73e3046d7138
parent6d65beef4118e896980ba881e270e5da50a1299a (diff)
Update QLerpClipBlend to use direct sync
Change-Id: I91ce052b27eb822e79b80fa11ccd3d4b9f76ded4 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/animation/backend/lerpclipblend.cpp34
-rw-r--r--src/animation/backend/lerpclipblend_p.h4
-rw-r--r--src/animation/frontend/qanimationaspect.cpp2
-rw-r--r--tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp18
-rw-r--r--tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp35
5 files changed, 39 insertions, 54 deletions
diff --git a/src/animation/backend/lerpclipblend.cpp b/src/animation/backend/lerpclipblend.cpp
index eef0072f9..b2ba2ff7e 100644
--- a/src/animation/backend/lerpclipblend.cpp
+++ b/src/animation/backend/lerpclipblend.cpp
@@ -35,9 +35,8 @@
****************************************************************************/
#include "lerpclipblend_p.h"
-#include <Qt3DAnimation/qclipblendnodecreatedchange.h>
+#include <Qt3DAnimation/qlerpclipblend.h>
#include <Qt3DAnimation/private/qlerpclipblend_p.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
QT_BEGIN_NAMESPACE
@@ -57,17 +56,16 @@ LerpClipBlend::~LerpClipBlend()
{
}
-void LerpClipBlend::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void LerpClipBlend::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- if (e->type() == Qt3DCore::PropertyUpdated) {
- Qt3DCore::QPropertyUpdatedChangePtr change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("blendFactor"))
- m_blendFactor = change->value().toFloat();
- else if (change->propertyName() == QByteArrayLiteral("startClip"))
- m_startClipId = change->value().value<Qt3DCore::QNodeId>();
- else if (change->propertyName() == QByteArrayLiteral("endClip"))
- m_endClipId = change->value().value<Qt3DCore::QNodeId>();
- }
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const QLerpClipBlend *node = qobject_cast<const QLerpClipBlend *>(frontEnd);
+ if (!node)
+ return;
+
+ m_blendFactor = node->blendFactor();
+ m_startClipId = Qt3DCore::qIdForNode(node->startClip());
+ m_endClipId = Qt3DCore::qIdForNode(node->endClip());
}
ClipResults LerpClipBlend::doBlend(const QVector<ClipResults> &blendData) const
@@ -83,16 +81,6 @@ ClipResults LerpClipBlend::doBlend(const QVector<ClipResults> &blendData) const
return blendResults;
}
-void LerpClipBlend::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- ClipBlendNode::initializeFromPeer(change);
- const auto creationChangeData = qSharedPointerCast<Qt3DAnimation::QClipBlendNodeCreatedChange<Qt3DAnimation::QLerpClipBlendData>>(change);
- const Qt3DAnimation::QLerpClipBlendData cloneData = creationChangeData->data;
- m_startClipId = cloneData.startClipId;
- m_endClipId = cloneData.endClipId;
- m_blendFactor = cloneData.blendFactor;
-}
-
double LerpClipBlend::duration() const
{
ClipBlendNode *startNode = clipBlendNodeManager()->lookupNode(m_startClipId);
@@ -101,7 +89,7 @@ double LerpClipBlend::duration() const
ClipBlendNode *endNode = clipBlendNodeManager()->lookupNode(m_endClipId);
const double endNodeDuration = endNode ? endNode->duration() : 0.0;
- return (1.0f - m_blendFactor) * startNodeDuration + m_blendFactor * endNodeDuration;
+ return (1.0 - static_cast<double>(m_blendFactor)) * startNodeDuration + static_cast<double>(m_blendFactor) * endNodeDuration;
}
} // Animation
diff --git a/src/animation/backend/lerpclipblend_p.h b/src/animation/backend/lerpclipblend_p.h
index 6120f8afa..61434af2c 100644
--- a/src/animation/backend/lerpclipblend_p.h
+++ b/src/animation/backend/lerpclipblend_p.h
@@ -71,7 +71,7 @@ public:
inline Qt3DCore::QNodeId endClipId() const { return m_endClipId; }
void setEndClipId(Qt3DCore::QNodeId endClipId) { m_endClipId = endClipId; } // For unit tests
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) final;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) final;
inline QVector<Qt3DCore::QNodeId> allDependencyIds() const override
{
@@ -89,8 +89,6 @@ protected:
ClipResults doBlend(const QVector<ClipResults> &blendData) const final;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
Qt3DCore::QNodeId m_startClipId;
Qt3DCore::QNodeId m_endClipId;
float m_blendFactor;
diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp
index 3b7946714..986ab3d22 100644
--- a/src/animation/frontend/qanimationaspect.cpp
+++ b/src/animation/frontend/qanimationaspect.cpp
@@ -122,7 +122,7 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent)
registerBackendType<QChannelMapper>(
QSharedPointer<Animation::NodeFunctor<Animation::ChannelMapper, Animation::ChannelMapperManager>>::create(d->m_handler.data(),
d->m_handler->channelMapperManager()));
- registerBackendType<QLerpClipBlend>(
+ registerBackendType<QLerpClipBlend, true>(
QSharedPointer<Animation::ClipBlendNodeFunctor<Animation::LerpClipBlend, Animation::ClipAnimatorManager>>::create(d->m_handler.data(),
d->m_handler->clipBlendNodeManager()));
registerBackendType<QAdditiveClipBlend, true>(
diff --git a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp
index 3f705e713..54de87b1e 100644
--- a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp
+++ b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp
@@ -73,11 +73,11 @@ private Q_SLOTS:
manager.appendNode(childBlendNode12.id(), backendChildBlendNode12);
// WHEN
- simulateInitialization(&rootBlendNode, backendRootBlendNode);
- simulateInitialization(&childBlendNode1, backendChildBlendNode1);
- simulateInitialization(&childBlendNode2, backendChildBlendNode2);
- simulateInitialization(&childBlendNode11, backendChildBlendNode11);
- simulateInitialization(&childBlendNode12, backendChildBlendNode12);
+ simulateInitializationSync(&rootBlendNode, backendRootBlendNode);
+ simulateInitializationSync(&childBlendNode1, backendChildBlendNode1);
+ simulateInitializationSync(&childBlendNode2, backendChildBlendNode2);
+ simulateInitializationSync(&childBlendNode11, backendChildBlendNode11);
+ simulateInitializationSync(&childBlendNode12, backendChildBlendNode12);
// THEN
QCOMPARE(backendRootBlendNode->allDependencyIds().size(), 2);
@@ -121,7 +121,7 @@ private Q_SLOTS:
// We purposely forgot the to do: manager.appendNode(rootBlendNode.id(), backendRootBlendNode);
// WHEN
- simulateInitialization(&rootBlendNode, backendRootBlendNode);
+ simulateInitializationSync(&rootBlendNode, backendRootBlendNode);
// THEN
QCOMPARE(backendRootBlendNode->allDependencyIds().size(), 2);
@@ -159,9 +159,9 @@ private Q_SLOTS:
// WHEN
- simulateInitialization(&rootBlendNode, backendRootBlendNode);
- simulateInitialization(&childBlendNode1, backendChildBlendNode1);
- simulateInitialization(&childBlendNode2, backendChildBlendNode2);
+ simulateInitializationSync(&rootBlendNode, backendRootBlendNode);
+ simulateInitializationSync(&childBlendNode1, backendChildBlendNode1);
+ simulateInitializationSync(&childBlendNode2, backendChildBlendNode2);
// THEN
QCOMPARE(backendRootBlendNode->allDependencyIds().size(), 2);
diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp
index e75c4f2f8..732a87770 100644
--- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp
+++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp
@@ -137,7 +137,7 @@ private Q_SLOTS:
{
// WHEN
LerpClipBlend backendLerpBlend;
- simulateInitialization(&lerpBlend, &backendLerpBlend);
+ simulateInitializationSync(&lerpBlend, &backendLerpBlend);
// THEN
QCOMPARE(backendLerpBlend.isEnabled(), true);
@@ -148,7 +148,7 @@ private Q_SLOTS:
// WHEN
LerpClipBlend backendLerpBlend;
lerpBlend.setEnabled(false);
- simulateInitialization(&lerpBlend, &backendLerpBlend);
+ simulateInitializationSync(&lerpBlend, &backendLerpBlend);
// THEN
QCOMPARE(backendLerpBlend.peerId(), lerpBlend.id());
@@ -159,27 +159,26 @@ private Q_SLOTS:
void checkSceneChangeEvents()
{
// GIVEN
+ Qt3DAnimation::QLerpClipBlend lerpBlend;
LerpClipBlend backendLerpBlend;
+ simulateInitializationSync(&lerpBlend, &backendLerpBlend);
+
{
- // WHEN
- const bool newValue = false;
- const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
- change->setPropertyName("enabled");
- change->setValue(newValue);
- backendLerpBlend.sceneChangeEvent(change);
-
- // THEN
+ // WHEN
+ const bool newValue = false;
+ lerpBlend.setEnabled(newValue);
+ backendLerpBlend.syncFromFrontEnd(&lerpBlend, false);
+
+ // THEN
QCOMPARE(backendLerpBlend.isEnabled(), newValue);
}
{
- // WHEN
- const float newValue = 0.883f;
- const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
- change->setPropertyName("blendFactor");
- change->setValue(QVariant::fromValue(newValue));
- backendLerpBlend.sceneChangeEvent(change);
-
- // THEN
+ // WHEN
+ const float newValue = 0.883f;
+ lerpBlend.setBlendFactor(newValue);
+ backendLerpBlend.syncFromFrontEnd(&lerpBlend, false);
+
+ // THEN
QCOMPARE(backendLerpBlend.blendFactor(), newValue);
}
}