summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@qt.io>2018-05-25 13:16:42 +0200
committerAndy Nichols <andy.nichols@qt.io>2018-06-01 13:46:19 +0000
commit00278e1e10b3c53beb7d13d44ed5e0bc829f8127 (patch)
treeb4af675980bcd5efe7caf732016d7cb6910fb5b1
parentb9b13f7c0a621dfbeedefd8b94b43b052786d22e (diff)
Move the slide position callback out of the animation class
The callback for the time updates belongs to the slideplayer and also deserves a better name the "DummyCallback", so moved it into the slideplayer's source file and renamed it to Q3DSSlidePositionCallback. Change-Id: I073dfd59ef4f95f0c03b73205069ed5af7fb912b Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r--src/runtime/q3dsanimationmanager.cpp88
-rw-r--r--src/runtime/q3dsslideplayer.cpp91
-rw-r--r--src/runtime/q3dsslideplayer_p.h2
3 files changed, 92 insertions, 89 deletions
diff --git a/src/runtime/q3dsanimationmanager.cpp b/src/runtime/q3dsanimationmanager.cpp
index 60b52f6..c0d2907 100644
--- a/src/runtime/q3dsanimationmanager.cpp
+++ b/src/runtime/q3dsanimationmanager.cpp
@@ -532,52 +532,10 @@ void Q3DSAnimationManager::updateAnimationHelper(const AnimationTrackListMap<T *
}
}
-class DummyCallback : public Qt3DAnimation::QAnimationCallback
-{
-public:
- DummyCallback(Q3DSSlide *slide)
- : m_slide(slide) {}
-
- void valueChanged(const QVariant &value) override {
- Q_ASSERT(m_slide);
-
- const float newValue = value.toFloat();
- if (qFuzzyCompare(m_previousValue, newValue))
- return;
-
- Q3DSSlidePlayer *slidePlayer = m_slide->attached<Q3DSSlideAttached>()->slidePlayer;
- // TODO: See QT3DS-1302
- if (!slidePlayer)
- return;
-
- slidePlayer->setSlideTime(m_slide, newValue * 1000.0f);
- m_previousValue = newValue;
- }
-
-private:
- Q3DSSlide *m_slide;
- float m_previousValue = -1.0f;
-};
-
void Q3DSAnimationManager::clearAnimations(Q3DSSlide *slide)
{
qCDebug(lcAnim, "Clearing animations for slide (%s)", qPrintable(slide->name()));
- // Clear the old slide animator
- // TODO: We no longer need this (keep the running check though).
- static const auto clearSlideAnimator = [](Q3DSSlide *slide) {
- Q_ASSERT(slide);
- Q3DSSlideAttached *data = slide->attached<Q3DSSlideAttached>();
- auto animator = data->animator;
- if (animator) {
- Q_ASSERT(!animator->isRunning());
- slide->attached()->entity->removeComponent(animator);
- }
- };
-
- if (slide)
- clearSlideAnimator(slide);
-
Q3DSSlide *masterSlide = static_cast<Q3DSSlide *>(slide->parent());
const bool hasAnimationData = !slide->animations().isEmpty()
@@ -620,50 +578,6 @@ void Q3DSAnimationManager::clearAnimations(Q3DSSlide *slide)
cleanUpAnimationData(slide->animations(), slide);
}
-// Dummy animator for keeping track of the time line for the current slide
-void Q3DSAnimationManager::buildClipAnimator(Q3DSSlide *slide)
-{
- using namespace Qt3DAnimation;
-
- qint32 startTime = 0.0f; // We always start from 0.0
- qint32 endTime = 0.0f;
- Q3DSSlideUtils::getStartAndEndTime(slide, nullptr, &endTime);
-
- Q3DSSlideAttached *data = slide->attached<Q3DSSlideAttached>();
- QClipAnimator *animator = data->animator ? data->animator : (data->animator = new QClipAnimator);
- if (!animator->clock())
- animator->setClock(new QClock);
-
- QAnimationClip *clip = animator->clip() ? static_cast<QAnimationClip *>(animator->clip()) : new QAnimationClip;
-
- const QString channelName = slide->name() + QLatin1String("_timeDummy");
- QKeyFrame keyFrameStart(QVector2D(startTime / 1000.0f, 0.0f));
- QKeyFrame keyFrameEnd(QVector2D(endTime / 1000.0f, endTime / 1000.0f));
-
- // New clip data
- QAnimationClipData clipData;
- QChannel channel(channelName);
- QChannelComponent component;
- component.appendKeyFrame(keyFrameStart);
- component.appendKeyFrame(keyFrameEnd);
- channel.appendChannelComponent(component);
- clipData.appendChannel(channel);
-
- if (!animator->channelMapper()) {
- QChannelMapper *mapper = new QChannelMapper;
- QCallbackMapping *mapping = new QCallbackMapping;
- mapping->setChannelName(channelName);
- mapping->setCallback(QMetaType::Float, new DummyCallback(slide));
- mapper->addMapping(mapping);
- animator->setChannelMapper(mapper);
- }
-
- clip->setClipData(clipData);
- animator->setClip(clip);
-
- data->entity->addComponent(animator);
-}
-
template <typename T>
static void insertTrack(T &trackList, const Q3DSAnimationTrack &animTrack, bool overWrite)
{
@@ -687,8 +601,6 @@ void Q3DSAnimationManager::updateAnimations(Q3DSSlide *slide, bool editorMode)
qCDebug(lcAnim, "Updating animations for slide (%s)", qPrintable(slide->name()));
- buildClipAnimator(slide);
-
Q3DSSlide *masterSlide = static_cast<Q3DSSlide *>(slide->parent());
const bool hasAnimationData = !slide->animations().isEmpty()
diff --git a/src/runtime/q3dsslideplayer.cpp b/src/runtime/q3dsslideplayer.cpp
index 136d335..f1baf01 100644
--- a/src/runtime/q3dsslideplayer.cpp
+++ b/src/runtime/q3dsslideplayer.cpp
@@ -38,12 +38,101 @@
#include <Qt3DAnimation/qclipanimator.h>
#include <Qt3DAnimation/qclock.h>
#include <Qt3DAnimation/qanimationclip.h>
+#include <Qt3DAnimation/qanimationcallback.h>
+#include <Qt3DAnimation/qchannel.h>
+#include <Qt3DAnimation/qchannelmapper.h>
+#include <Qt3DAnimation/qcallbackmapping.h>
#include <Qt3DCore/QEntity>
#include <Qt3DRender/QLayer>
QT_BEGIN_NAMESPACE
+class Q3DSSlidePositionCallback : public Qt3DAnimation::QAnimationCallback
+{
+public:
+ Q3DSSlidePositionCallback(Q3DSSlide *slide)
+ : m_slide(slide) {}
+
+ void valueChanged(const QVariant &value) override {
+ Q_ASSERT(m_slide);
+
+ const float newValue = value.toFloat();
+ if (qFuzzyCompare(m_previousValue, newValue))
+ return;
+
+ Q3DSSlidePlayer *slidePlayer = m_slide->attached<Q3DSSlideAttached>()->slidePlayer;
+ // TODO: See QT3DS-1302
+ if (!slidePlayer)
+ return;
+
+ slidePlayer->setSlideTime(m_slide, newValue * 1000.0f);
+ m_previousValue = newValue;
+ }
+
+private:
+ Q3DSSlide *m_slide;
+ float m_previousValue = -1.0f;
+};
+
+// Dummy animator for keeping track of the time line for the current slide
+static void attatchPositionCallback(Q3DSSlide *slide)
+{
+ using namespace Qt3DAnimation;
+
+ Q_ASSERT(slide);
+ qint32 startTime = 0.0f; // We always start from 0.0
+ qint32 endTime = 0.0f;
+ Q3DSSlideUtils::getStartAndEndTime(slide, nullptr, &endTime);
+
+ Q3DSSlideAttached *data = slide->attached<Q3DSSlideAttached>();
+ QClipAnimator *animator = data->animator ? data->animator : (data->animator = new QClipAnimator);
+ if (!animator->clock())
+ animator->setClock(new QClock);
+
+ QAnimationClip *clip = animator->clip() ? static_cast<QAnimationClip *>(animator->clip()) : new QAnimationClip;
+
+ const QString channelName = slide->name() + QLatin1String("_timeDummy");
+ QKeyFrame keyFrameStart(QVector2D(startTime / 1000.0f, 0.0f));
+ QKeyFrame keyFrameEnd(QVector2D(endTime / 1000.0f, endTime / 1000.0f));
+
+ // New clip data
+ QAnimationClipData clipData;
+ QChannel channel(channelName);
+ QChannelComponent component;
+ component.appendKeyFrame(keyFrameStart);
+ component.appendKeyFrame(keyFrameEnd);
+ channel.appendChannelComponent(component);
+ clipData.appendChannel(channel);
+
+ if (!animator->channelMapper()) {
+ QChannelMapper *mapper = new QChannelMapper;
+ QCallbackMapping *mapping = new QCallbackMapping;
+ mapping->setChannelName(channelName);
+ mapping->setCallback(QMetaType::Float, new Q3DSSlidePositionCallback(slide));
+ mapper->addMapping(mapping);
+ animator->setChannelMapper(mapper);
+ }
+
+ clip->setClipData(clipData);
+ animator->setClip(clip);
+
+ data->entity->addComponent(animator);
+}
+
+static void detatchPositionCallback(Q3DSSlide *slide)
+{
+ if (!slide)
+ return;
+
+ Q3DSSlideAttached *data = slide->attached<Q3DSSlideAttached>();
+ auto animator = data->animator;
+ if (animator) {
+ Q_ASSERT(!animator->isRunning());
+ slide->attached()->entity->removeComponent(animator);
+ }
+}
+
void Q3DSSlideUtils::getStartAndEndTime(Q3DSSlide *slide, qint32 *startTime, qint32 *endTime)
{
Q_ASSERT(startTime != nullptr || endTime != nullptr);
@@ -592,12 +681,14 @@ void Q3DSSlidePlayer::handleCurrentSlideChanged(Q3DSSlide *slide,
// TODO: We probably want to be a bit less brute.
if (slide) Q_ASSERT(previousSlide->parent() == slide->parent());
updateAnimators(previousSlide, false, false, 1.0f);
+ detatchPositionCallback(previousSlide);
m_animationManager->clearAnimations(previousSlide);
}
}
if (slide && slideDidChange && isSlideVisible(slide)) {
processPropertyChanges(slide);
+ attatchPositionCallback(slide);
m_animationManager->updateAnimations(slide, (m_mode == PlayerMode::Editor));
if (parentChanged)
setSlideTime(static_cast<Q3DSSlide *>(slide->parent()), 0.0f);
diff --git a/src/runtime/q3dsslideplayer_p.h b/src/runtime/q3dsslideplayer_p.h
index 7441bb5..2b0fdbc 100644
--- a/src/runtime/q3dsslideplayer_p.h
+++ b/src/runtime/q3dsslideplayer_p.h
@@ -165,7 +165,7 @@ private:
PlayerType m_type = PlayerType::Slide;
// This class handles animation callback from animationmanager and calls setSlideTime
- friend class DummyCallback;
+ friend class Q3DSSlidePositionCallback;
};
class Q3DSV_PRIVATE_EXPORT Q3DSSlideDeck