diff options
author | Mike Krus <mike.krus@kdab.com> | 2019-09-19 21:01:13 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2019-09-20 08:18:58 +0100 |
commit | de4c982ceeb2abcdec8b214fd95e6e5d5d72b9ff (patch) | |
tree | 5a9e956859a9b38f2758d3d99c35e8d39b70fc55 /src/animation | |
parent | 37e1808b9d24540a962aa6103e6d2638daea15c0 (diff) |
Update QBlendedClipAnimator to use direct sync
Change-Id: I6b00f22196d29b5219e27e5084c379b69b68c6e5
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/backend/blendedclipanimator.cpp | 64 | ||||
-rw-r--r-- | src/animation/backend/blendedclipanimator_p.h | 3 | ||||
-rw-r--r-- | src/animation/frontend/qanimationaspect.cpp | 2 |
3 files changed, 30 insertions, 39 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>( |