summaryrefslogtreecommitdiffstats
path: root/src/core/aspects/qaspectmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/aspects/qaspectmanager.cpp')
-rw-r--r--src/core/aspects/qaspectmanager.cpp48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/core/aspects/qaspectmanager.cpp b/src/core/aspects/qaspectmanager.cpp
index f24248399..74803349c 100644
--- a/src/core/aspects/qaspectmanager.cpp
+++ b/src/core/aspects/qaspectmanager.cpp
@@ -65,6 +65,7 @@
#include <Qt3DCore/private/qscene_p.h>
#include <QtCore/QCoreApplication>
+#include <QtCore/QAbstractAnimation>
#if defined(QT3D_CORE_JOB_TIMING)
#include <QElapsedTimer>
@@ -74,6 +75,23 @@ QT_BEGIN_NAMESPACE
namespace Qt3DCore {
+#if QT_CONFIG(animation)
+class RequestFrameAnimation final : public QAbstractAnimation
+{
+public:
+ RequestFrameAnimation(QObject *parent)
+ : QAbstractAnimation(parent)
+ {
+ }
+
+ ~RequestFrameAnimation() override;
+
+ int duration() const override { return 1; }
+ void updateCurrentTime(int currentTime) override { Q_UNUSED(currentTime) }
+};
+
+RequestFrameAnimation::~RequestFrameAnimation() = default;
+#else
namespace {
class RequestFrameEvent : public QEvent
@@ -92,7 +110,7 @@ private:
int RequestFrameEvent::requestEventType = QEvent::registerEventType();
} // anonymous
-
+#endif
/*!
\class Qt3DCore::QAspectManager
@@ -108,6 +126,9 @@ QAspectManager::QAspectManager(QObject *parent)
, m_simulationLoopRunning(false)
, m_driveMode(QAspectEngine::Automatic)
, m_postConstructorInit(nullptr)
+#if QT_CONFIG(animation)
+ , m_simulationAnimation(nullptr)
+#endif
{
qRegisterMetaType<QSurface *>("QSurface*");
qCDebug(Aspects) << Q_FUNC_INFO;
@@ -149,8 +170,19 @@ void QAspectManager::enterSimulationLoop()
qCDebug(Aspects) << "Done calling onEngineStartup() for each aspect";
// Start running loop if Qt3D is in charge of driving it
- if (m_driveMode == QAspectEngine::Automatic)
+ if (m_driveMode == QAspectEngine::Automatic) {
+#if QT_CONFIG(animation)
+ if (!m_simulationAnimation) {
+ m_simulationAnimation = new RequestFrameAnimation(this);
+ connect(m_simulationAnimation, &QAbstractAnimation::finished, this, [this]() {
+ processFrame();
+ if (m_simulationLoopRunning && m_driveMode == QAspectEngine::Automatic)
+ requestNextFrame();
+ });
+ }
+#endif
requestNextFrame();
+ }
}
// Main thread (called by QAspectEngine)
@@ -164,6 +196,11 @@ void QAspectManager::exitSimulationLoop()
return;
}
+#if QT_CONFIG(animation)
+ if (m_simulationAnimation)
+ m_simulationAnimation->stop();
+#endif
+
QAbstractFrameAdvanceService *frameAdvanceService =
m_serviceLocator->service<QAbstractFrameAdvanceService>(QServiceLocator::FrameAdvanceService);
if (frameAdvanceService)
@@ -193,7 +230,6 @@ void QAspectManager::exitSimulationLoop()
}
qCDebug(Aspects) << "Done calling onEngineShutdown() for each aspect";
-
m_simulationLoopRunning = false;
qCDebug(Aspects) << "exitSimulationLoop completed";
}
@@ -399,6 +435,7 @@ QVector<QNode *> QAspectManager::lookupNodes(const QVector<QNodeId> &ids) const
return d->m_scene ? d->m_scene->lookupNodes(ids) : QVector<QNode *>{};
}
+#if !QT_CONFIG(animation)
/*!
\internal
\brief Drives the Qt3D simulation loop in the main thread
@@ -420,13 +457,18 @@ bool QAspectManager::event(QEvent *e)
return QObject::event(e);
}
+#endif
void QAspectManager::requestNextFrame()
{
qCDebug(Aspects) << "Requesting new Frame";
// Post event in the event loop to force
// next frame to be processed
+#if QT_CONFIG(animation)
+ m_simulationAnimation->start();
+#else
QCoreApplication::postEvent(this, new RequestFrameEvent());
+#endif
}
void QAspectManager::processFrame()