diff options
-rw-r--r-- | src/animation/backend/clipanimator.cpp | 61 | ||||
-rw-r--r-- | src/animation/backend/clipanimator_p.h | 4 | ||||
-rw-r--r-- | src/animation/frontend/qanimationaspect.cpp | 2 | ||||
-rw-r--r-- | tests/auto/animation/clipanimator/tst_clipanimator.cpp | 54 |
4 files changed, 54 insertions, 67 deletions
diff --git a/src/animation/backend/clipanimator.cpp b/src/animation/backend/clipanimator.cpp index acb3c8170..b6bcc9239 100644 --- a/src/animation/backend/clipanimator.cpp +++ b/src/animation/backend/clipanimator.cpp @@ -36,6 +36,8 @@ #include "clipanimator_p.h" #include <Qt3DAnimation/qclipanimator.h> +#include <Qt3DAnimation/qchannelmapper.h> +#include <Qt3DAnimation/qclock.h> #include <Qt3DAnimation/private/qclipanimator_p.h> #include <Qt3DAnimation/private/animationclip_p.h> #include <Qt3DAnimation/private/managers_p.h> @@ -65,19 +67,6 @@ ClipAnimator::ClipAnimator() { } -void ClipAnimator::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) -{ - const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QClipAnimatorData>>(change); - 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; - m_normalizedLocalTime = data.normalizedTime; - setDirty(Handler::ClipAnimatorDirty); -} - void ClipAnimator::setClipId(Qt3DCore::QNodeId clipId) { m_clipId = clipId; @@ -129,30 +118,32 @@ void ClipAnimator::cleanup() m_normalizedLocalTime = m_lastNormalizedLocalTime = -1.0f; } -void ClipAnimator::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +void ClipAnimator::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) { - switch (e->type()) { - case Qt3DCore::PropertyUpdated: { - const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e); - if (change->propertyName() == QByteArrayLiteral("clip")) - 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")) - m_loops = change->value().toInt(); - else if (change->propertyName() == QByteArrayLiteral("normalizedTime")) - setNormalizedLocalTime(change->value().toFloat()); - break; - } + BackendNode::syncFromFrontEnd(frontEnd, firstTime); + const QClipAnimator *node = qobject_cast<const QClipAnimator *>(frontEnd); + if (!node) + return; - default: - break; - } - QBackendNode::sceneChangeEvent(e); + auto id = Qt3DCore::qIdForNode(node->clip()); + if (m_clipId != id) + setClipId(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::ClipAnimatorDirty); } void ClipAnimator::sendPropertyChanges(const QVector<Qt3DCore::QSceneChangePtr> &changes) diff --git a/src/animation/backend/clipanimator_p.h b/src/animation/backend/clipanimator_p.h index f4c04a4bf..54d1527a4 100644 --- a/src/animation/backend/clipanimator_p.h +++ b/src/animation/backend/clipanimator_p.h @@ -80,7 +80,7 @@ public: void setNormalizedLocalTime(float normalizedLocalTime); float normalizedLocalTime() const { return m_normalizedLocalTime; } - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override; + void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; void setHandler(Handler *handler) { m_handler = handler; } // Called by jobs @@ -116,8 +116,6 @@ public: } private: - void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final; - Qt3DCore::QNodeId m_clipId; Qt3DCore::QNodeId m_mapperId; Qt3DCore::QNodeId m_clockId; diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp index a76916409..8e7103732 100644 --- a/src/animation/frontend/qanimationaspect.cpp +++ b/src/animation/frontend/qanimationaspect.cpp @@ -110,7 +110,7 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent) registerBackendType<QClock, true>( QSharedPointer<Animation::NodeFunctor<Animation::Clock, Animation::ClockManager>>::create(d->m_handler.data(), d->m_handler->clockManager())); - registerBackendType<QClipAnimator>( + registerBackendType<QClipAnimator, true>( QSharedPointer<Animation::NodeFunctor<Animation::ClipAnimator, Animation::ClipAnimatorManager>>::create(d->m_handler.data(), d->m_handler->clipAnimatorManager())); registerBackendType<QBlendedClipAnimator>( diff --git a/tests/auto/animation/clipanimator/tst_clipanimator.cpp b/tests/auto/animation/clipanimator/tst_clipanimator.cpp index 0272bcfaa..5f297306a 100644 --- a/tests/auto/animation/clipanimator/tst_clipanimator.cpp +++ b/tests/auto/animation/clipanimator/tst_clipanimator.cpp @@ -29,6 +29,7 @@ #include <QtTest/QTest> #include <Qt3DAnimation/private/clipanimator_p.h> #include <Qt3DAnimation/qanimationcliploader.h> +#include <Qt3DAnimation/qchannelmapper.h> #include <Qt3DAnimation/qclipanimator.h> #include <Qt3DAnimation/qclock.h> #include <Qt3DCore/private/qnode_p.h> @@ -59,7 +60,7 @@ private Q_SLOTS: animator.setNormalizedTime(0.5f); // WHEN - simulateInitialization(&animator, &backendAnimator); + simulateInitializationSync(&animator, &backendAnimator); // THEN QCOMPARE(backendAnimator.peerId(), animator.id()); @@ -98,7 +99,7 @@ private Q_SLOTS: animator.setNormalizedTime(1.0f); // WHEN - simulateInitialization(&animator, &backendAnimator); + simulateInitializationSync(&animator, &backendAnimator); backendAnimator.setClipId(Qt3DCore::QNodeId::createId()); backendAnimator.setClockId(Qt3DCore::QNodeId::createId()); backendAnimator.cleanup(); @@ -115,63 +116,60 @@ private Q_SLOTS: void checkPropertyChanges() { // GIVEN + Qt3DAnimation::QClipAnimator animator; Qt3DAnimation::Animation::Handler handler; Qt3DAnimation::Animation::ClipAnimator backendAnimator; backendAnimator.setHandler(&handler); - Qt3DCore::QPropertyUpdatedChangePtr updateChange; + simulateInitializationSync(&animator, &backendAnimator); // WHEN - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("enabled"); - updateChange->setValue(true); - backendAnimator.sceneChangeEvent(updateChange); + animator.setEnabled(false); + backendAnimator.syncFromFrontEnd(&animator, false); // THEN - QCOMPARE(backendAnimator.isEnabled(), true); + QCOMPARE(backendAnimator.isEnabled(), false); // WHEN auto newClip = new Qt3DAnimation::QAnimationClipLoader(); - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("clip"); - updateChange->setValue(QVariant::fromValue(newClip->id())); - backendAnimator.sceneChangeEvent(updateChange); + animator.setClip(newClip); + backendAnimator.syncFromFrontEnd(&animator, false); // THEN QCOMPARE(backendAnimator.clipId(), newClip->id()); // WHEN + auto newMapper = new Qt3DAnimation::QChannelMapper(); + animator.setChannelMapper(newMapper); + backendAnimator.syncFromFrontEnd(&animator, false); + + // THEN + QCOMPARE(backendAnimator.mapperId(), newMapper->id()); + + // WHEN auto clock = new Qt3DAnimation::QClock(); - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("clock"); - updateChange->setValue(QVariant::fromValue(clock->id())); - backendAnimator.sceneChangeEvent(updateChange); + animator.setClock(clock); + backendAnimator.syncFromFrontEnd(&animator, false); // THEN QCOMPARE(backendAnimator.clockId(), clock->id()); // WHEN - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("running"); - updateChange->setValue(true); - backendAnimator.sceneChangeEvent(updateChange); + animator.setRunning(true); + backendAnimator.syncFromFrontEnd(&animator, false); // THEN QCOMPARE(backendAnimator.isRunning(), true); // WHEN - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("loops"); - updateChange->setValue(64); - backendAnimator.sceneChangeEvent(updateChange); + animator.setLoopCount(64); + backendAnimator.syncFromFrontEnd(&animator, false); // THEN QCOMPARE(backendAnimator.loops(), 64); // WHEN - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("normalizedTime"); - updateChange->setValue(0.5f); - backendAnimator.sceneChangeEvent(updateChange); + animator.setNormalizedTime(0.5f); + backendAnimator.syncFromFrontEnd(&animator, false); // THEN QVERIFY(qFuzzyCompare(backendAnimator.normalizedLocalTime(), 0.5f)); |