summaryrefslogtreecommitdiffstats
path: root/src/animation
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-09-12 12:10:03 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-09-12 12:39:05 +0100
commit3f03499bf8a7cf3c3f8d19a020179c1205980bde (patch)
tree518b0ef3fb1b31d3856f43124150ef41acb8c1aa /src/animation
parent8a4b9ebadb9e63ae367694f04786c7faf6306f27 (diff)
parentbf5fd7a78c91e29332ce70ad844b756150f32f18 (diff)
Merge branch '5.9' into 5.10
Diffstat (limited to 'src/animation')
-rw-r--r--src/animation/backend/animationclip.cpp31
-rw-r--r--src/animation/backend/animationclip_p.h9
-rw-r--r--src/animation/backend/blendedclipanimator_p.h2
-rw-r--r--src/animation/backend/buildblendtreesjob.cpp5
-rw-r--r--src/animation/backend/clipanimator.cpp5
-rw-r--r--src/animation/backend/clipanimator_p.h2
-rw-r--r--src/animation/backend/handler.cpp6
-rw-r--r--src/animation/backend/handler_p.h2
-rw-r--r--src/animation/backend/managers_p.h21
9 files changed, 68 insertions, 15 deletions
diff --git a/src/animation/backend/animationclip.cpp b/src/animation/backend/animationclip.cpp
index 0f90ff493..daee4008d 100644
--- a/src/animation/backend/animationclip.cpp
+++ b/src/animation/backend/animationclip.cpp
@@ -40,6 +40,7 @@
#include <Qt3DAnimation/private/qanimationclip_p.h>
#include <Qt3DAnimation/private/qanimationcliploader_p.h>
#include <Qt3DAnimation/private/animationlogging_p.h>
+#include <Qt3DAnimation/private/managers_p.h>
#include <Qt3DRender/private/qurlhelper_p.h>
#include <Qt3DCore/qpropertyupdatedchange.h>
@@ -176,6 +177,24 @@ void AnimationClip::loadAnimation()
setStatus(QAnimationClipLoader::Ready);
}
+ // notify all ClipAnimators and BlendedClipAnimators that depend on this clip,
+ // that the clip has changed and that they are now dirty
+ {
+ QMutexLocker lock(&m_mutex);
+ for (const Qt3DCore::QNodeId id : qAsConst(m_dependingAnimators)) {
+ ClipAnimator *animator = m_handler->clipAnimatorManager()->lookupResource(id);
+ if (animator)
+ animator->animationClipMarkedDirty();
+ }
+ for (const Qt3DCore::QNodeId id : qAsConst(m_dependingBlendedAnimators)) {
+ BlendedClipAnimator *animator = m_handler->blendedClipAnimatorManager()->lookupResource(id);
+ if (animator)
+ animator->animationClipMarkedDirty();
+ }
+ m_dependingAnimators.clear();
+ m_dependingBlendedAnimators.clear();
+ }
+
qCDebug(Jobs) << "Loaded animation data:" << *this;
}
@@ -224,6 +243,18 @@ void AnimationClip::loadAnimationFromData()
m_channels[i++].setFromQChannel(frontendChannel);
}
+void AnimationClip::addDependingClipAnimator(const Qt3DCore::QNodeId &id)
+{
+ QMutexLocker lock(&m_mutex);
+ m_dependingAnimators.push_back(id);
+}
+
+void AnimationClip::addDependingBlendedClipAnimator(const Qt3DCore::QNodeId &id)
+{
+ QMutexLocker lock(&m_mutex);
+ m_dependingBlendedAnimators.push_back(id);
+}
+
void AnimationClip::setDuration(float duration)
{
if (qFuzzyCompare(duration, m_duration))
diff --git a/src/animation/backend/animationclip_p.h b/src/animation/backend/animationclip_p.h
index 5e5d54ac8..9eb94d45e 100644
--- a/src/animation/backend/animationclip_p.h
+++ b/src/animation/backend/animationclip_p.h
@@ -53,6 +53,7 @@
#include <Qt3DAnimation/qanimationcliploader.h>
#include <Qt3DAnimation/private/fcurve_p.h>
#include <QtCore/qurl.h>
+#include <QtCore/qmutex.h>
QT_BEGIN_NAMESPACE
@@ -73,6 +74,9 @@ public:
QAnimationClipLoader::Status status() const { return m_status; }
void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE;
+ void addDependingClipAnimator(const Qt3DCore::QNodeId &id);
+ void addDependingBlendedClipAnimator(const Qt3DCore::QNodeId &id);
+
QString name() const { return m_name; }
const QVector<Channel> &channels() const { return m_channels; }
@@ -106,6 +110,8 @@ private:
float findDuration();
int findChannelComponentCount();
+ QMutex m_mutex;
+
QUrl m_source;
QAnimationClipLoader::Status m_status;
QAnimationClipData m_clipData;
@@ -115,6 +121,9 @@ private:
QVector<Channel> m_channels;
float m_duration;
int m_channelComponentCount;
+
+ Qt3DCore::QNodeIdVector m_dependingAnimators;
+ Qt3DCore::QNodeIdVector m_dependingBlendedAnimators;
};
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/animation/backend/blendedclipanimator_p.h b/src/animation/backend/blendedclipanimator_p.h
index e15a892bb..d9f89b5f9 100644
--- a/src/animation/backend/blendedclipanimator_p.h
+++ b/src/animation/backend/blendedclipanimator_p.h
@@ -94,6 +94,8 @@ public:
void sendPropertyChanges(const QVector<Qt3DCore::QSceneChangePtr> &changes);
void sendCallbacks(const QVector<AnimationCallbackAndValue> &callbacks);
+ void animationClipMarkedDirty() { setDirty(Handler::BlendedClipAnimatorDirty); }
+
private:
void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
Qt3DCore::QNodeId m_blendTreeRootId;
diff --git a/src/animation/backend/buildblendtreesjob.cpp b/src/animation/backend/buildblendtreesjob.cpp
index fe56099a2..f35280cbf 100644
--- a/src/animation/backend/buildblendtreesjob.cpp
+++ b/src/animation/backend/buildblendtreesjob.cpp
@@ -95,7 +95,7 @@ void BuildBlendTreesJob::run()
Q_ASSERT(valueNode);
const Qt3DCore::QNodeId clipId = valueNode->clipId();
- const AnimationClip *clip = m_handler->animationClipLoaderManager()->lookupResource(clipId);
+ AnimationClip *clip = m_handler->animationClipLoaderManager()->lookupResource(clipId);
Q_ASSERT(clip);
const ComponentIndices formatIndices
@@ -103,6 +103,9 @@ void BuildBlendTreesJob::run()
channelComponentIndices,
clip);
valueNode->setFormatIndices(blendClipAnimator->peerId(), formatIndices);
+
+ // this BlendClipAnimator needs to be notified when the clip has been loaded
+ clip->addDependingBlendedClipAnimator(blendClipAnimator->peerId());
}
// Finally, build the mapping data vector for this blended clip animator. This
diff --git a/src/animation/backend/clipanimator.cpp b/src/animation/backend/clipanimator.cpp
index 9a5cce2e2..2f4dca63f 100644
--- a/src/animation/backend/clipanimator.cpp
+++ b/src/animation/backend/clipanimator.cpp
@@ -78,6 +78,11 @@ void ClipAnimator::setClipId(Qt3DCore::QNodeId clipId)
{
m_clipId = clipId;
setDirty(Handler::ClipAnimatorDirty);
+
+ // register at the clip to make sure we are marked dirty when the clip finished loading
+ AnimationClip *clip = m_handler->animationClipLoaderManager()->lookupResource(clipId);
+ if (clip)
+ clip->addDependingClipAnimator(peerId());
}
void ClipAnimator::setMapperId(Qt3DCore::QNodeId mapperId)
diff --git a/src/animation/backend/clipanimator_p.h b/src/animation/backend/clipanimator_p.h
index 628a15e24..b3389f8da 100644
--- a/src/animation/backend/clipanimator_p.h
+++ b/src/animation/backend/clipanimator_p.h
@@ -95,6 +95,8 @@ public:
void sendPropertyChanges(const QVector<Qt3DCore::QSceneChangePtr> &changes);
void sendCallbacks(const QVector<AnimationCallbackAndValue> &callbacks);
+ void animationClipMarkedDirty() { setDirty(Handler::ClipAnimatorDirty); }
+
private:
void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
diff --git a/src/animation/backend/handler.cpp b/src/animation/backend/handler.cpp
index b8e89703e..071343791 100644
--- a/src/animation/backend/handler.cpp
+++ b/src/animation/backend/handler.cpp
@@ -77,24 +77,28 @@ void Handler::setDirty(DirtyFlag flag, Qt3DCore::QNodeId nodeId)
{
switch (flag) {
case AnimationClipDirty: {
+ QMutexLocker lock(&m_mutex);
const auto handle = m_animationClipLoaderManager->lookupHandle(nodeId);
m_dirtyAnimationClips.push_back(handle);
break;
}
case ChannelMappingsDirty: {
+ QMutexLocker lock(&m_mutex);
const auto handle = m_channelMapperManager->lookupHandle(nodeId);
m_dirtyChannelMappers.push_back(handle);
break;
}
case ClipAnimatorDirty: {
+ QMutexLocker lock(&m_mutex);
const auto handle = m_clipAnimatorManager->lookupHandle(nodeId);
m_dirtyClipAnimators.push_back(handle);
break;
}
case BlendedClipAnimatorDirty: {
+ QMutexLocker lock(&m_mutex);
const HBlendedClipAnimator handle = m_blendedClipAnimatorManager->lookupHandle(nodeId);
m_dirtyBlendedAnimators.push_back(handle);
break;
@@ -174,6 +178,8 @@ QVector<Qt3DCore::QAspectJobPtr> Handler::jobsToExecute(qint64 time)
QVector<Qt3DCore::QAspectJobPtr> jobs;
+ QMutexLocker lock(&m_mutex);
+
// If there are any dirty animation clips that need loading,
// queue up a job for them
if (!m_dirtyAnimationClips.isEmpty()) {
diff --git a/src/animation/backend/handler_p.h b/src/animation/backend/handler_p.h
index 0dccdae75..d35d5a132 100644
--- a/src/animation/backend/handler_p.h
+++ b/src/animation/backend/handler_p.h
@@ -53,6 +53,7 @@
#include <Qt3DCore/qaspectjob.h>
#include <Qt3DCore/qnodeid.h>
#include <QtCore/qscopedpointer.h>
+#include <QtCore/qmutex.h>
QT_BEGIN_NAMESPACE
@@ -124,6 +125,7 @@ public:
void cleanupHandleList(QVector<HBlendedClipAnimator> *animators);
private:
+ QMutex m_mutex;
QScopedPointer<AnimationClipLoaderManager> m_animationClipLoaderManager;
QScopedPointer<ClockManager> m_clockManager;
QScopedPointer<ClipAnimatorManager> m_clipAnimatorManager;
diff --git a/src/animation/backend/managers_p.h b/src/animation/backend/managers_p.h
index c5f3cafba..b88f1b8ae 100644
--- a/src/animation/backend/managers_p.h
+++ b/src/animation/backend/managers_p.h
@@ -72,8 +72,7 @@ class ClipBlendNode;
class AnimationClipLoaderManager : public Qt3DCore::QResourceManager<
AnimationClip,
Qt3DCore::QNodeId,
- 16,
- Qt3DCore::ArrayAllocatingPolicy>
+ 16>
{
public:
AnimationClipLoaderManager() {}
@@ -82,8 +81,7 @@ public:
class ClockManager : public Qt3DCore::QResourceManager<
Clock,
Qt3DCore::QNodeId,
- 16,
- Qt3DCore::ArrayAllocatingPolicy>
+ 16>
{
public:
ClockManager() {}
@@ -92,8 +90,7 @@ public:
class ClipAnimatorManager : public Qt3DCore::QResourceManager<
ClipAnimator,
Qt3DCore::QNodeId,
- 16,
- Qt3DCore::ArrayAllocatingPolicy>
+ 16>
{
public:
ClipAnimatorManager() {}
@@ -102,8 +99,7 @@ public:
class BlendedClipAnimatorManager : public Qt3DCore::QResourceManager<
BlendedClipAnimator,
Qt3DCore::QNodeId,
- 12,
- Qt3DCore::ArrayAllocatingPolicy>
+ 12>
{
public:
BlendedClipAnimatorManager() {}
@@ -112,8 +108,7 @@ public:
class ChannelMappingManager : public Qt3DCore::QResourceManager<
ChannelMapping,
Qt3DCore::QNodeId,
- 16,
- Qt3DCore::ArrayAllocatingPolicy>
+ 16>
{
public:
ChannelMappingManager() {}
@@ -122,8 +117,7 @@ public:
class ChannelMapperManager : public Qt3DCore::QResourceManager<
ChannelMapper,
Qt3DCore::QNodeId,
- 16,
- Qt3DCore::ArrayAllocatingPolicy>
+ 16>
{
public:
ChannelMapperManager() {}
@@ -147,8 +141,7 @@ private:
class SkeletonManager : public Qt3DCore::QResourceManager<
Skeleton,
Qt3DCore::QNodeId,
- 16,
- Qt3DCore::ArrayAllocatingPolicy>
+ 16>
{
public:
SkeletonManager() {}