summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-07-05 09:03:00 +0200
committerPaul Lemire <paul.lemire@kdab.com>2019-08-07 09:33:58 +0200
commit260af7338d3a4216dbac292a4fd9112ad7512f44 (patch)
tree637e1d2b476bf0d0367237d1084d1299c7e8f8fc
parent8daa8bcb8e9a7110289d15c94f53a4be9adac1ac (diff)
QAspectEngine: add run loop driving modes
Can be either Automatic (Qt3D is in charge or driving it) or manual where the user has to call QAspectManager::processFrame() manually. Change-Id: I3e41d24aea0ddc5cce61328d9731b23f91b54215 Reviewed-by: Mike Krus <mike.krus@kdab.com>
-rw-r--r--src/core/aspects/qaspectengine.cpp31
-rw-r--r--src/core/aspects/qaspectengine.h11
-rw-r--r--src/core/aspects/qaspectengine_p.h3
-rw-r--r--src/core/aspects/qaspectmanager.cpp17
-rw-r--r--src/core/aspects/qaspectmanager_p.h5
5 files changed, 61 insertions, 6 deletions
diff --git a/src/core/aspects/qaspectengine.cpp b/src/core/aspects/qaspectengine.cpp
index 2e7e51247..9c98e9613 100644
--- a/src/core/aspects/qaspectengine.cpp
+++ b/src/core/aspects/qaspectengine.cpp
@@ -77,6 +77,7 @@ QAspectEnginePrivate::QAspectEnginePrivate()
, m_postman(nullptr)
, m_scene(nullptr)
, m_initialized(false)
+ , m_runMode(QAspectEngine::Automatic)
#if QT_CONFIG(qt3d_profile_jobs)
, m_commandDebugger(new Debug::AspectCommandDebugger(q_func()))
#endif
@@ -393,6 +394,19 @@ QVariant QAspectEngine::executeCommand(const QString &command)
}
/*!
+ * If using the manual run mode, this function executes the jobs for each aspect.
+ * It is blocking and won't return until all jobs have been completed.
+ *
+ * If you are using the QRenderAspect,
+ */
+void QAspectEngine::processFrame()
+{
+ Q_D(QAspectEngine);
+ Q_ASSERT(d->m_runMode == QAspectEngine::Manual);
+ d->m_aspectManager->processFrame();
+}
+
+/*!
* Sets the \a root entity for the aspect engine.
*/
void QAspectEngine::setRootEntity(QEntityPtr root)
@@ -432,6 +446,9 @@ void QAspectEngine::setRootEntity(QEntityPtr root)
// Traverse tree to generate a vector of creation changes
d->generateCreationChanges(root.data());
+ // Specify if the AspectManager should be driving the simulation loop or not
+ d->m_aspectManager->setRunMode(d->m_runMode);
+
// Finally, tell the aspects about the new scene object tree. This is done
// in a blocking manner to allow the aspects to get synchronized before the
// main thread starts triggering potentially more notifications
@@ -453,6 +470,20 @@ QEntityPtr QAspectEngine::rootEntity() const
return d->m_root;
}
+void QAspectEngine::setRunMode(QAspectEngine::RunMode mode)
+{
+ Q_D(QAspectEngine);
+ d->m_runMode = mode;
+ if (d->m_aspectManager)
+ d->m_aspectManager->setRunMode(mode);
+}
+
+QAspectEngine::RunMode QAspectEngine::runMode() const
+{
+ Q_D(const QAspectEngine);
+ return d->m_runMode;
+}
+
} // namespace Qt3DCore
QT_END_NAMESPACE
diff --git a/src/core/aspects/qaspectengine.h b/src/core/aspects/qaspectengine.h
index 7f900ad52..1d5d7e220 100644
--- a/src/core/aspects/qaspectengine.h
+++ b/src/core/aspects/qaspectengine.h
@@ -60,12 +60,21 @@ class Q_3DCORESHARED_EXPORT QAspectEngine : public QObject
{
Q_OBJECT
public:
+ enum RunMode {
+ Manual = 0,
+ Automatic
+ };
+ Q_ENUM(RunMode)
+
explicit QAspectEngine(QObject *parent = nullptr);
~QAspectEngine();
void setRootEntity(QEntityPtr root);
QEntityPtr rootEntity() const;
+ void setRunMode(RunMode mode);
+ RunMode runMode() const;
+
void registerAspect(QAbstractAspect *aspect);
void registerAspect(const QString &name);
void unregisterAspect(QAbstractAspect *aspect);
@@ -75,6 +84,8 @@ public:
QVariant executeCommand(const QString &command);
+ void processFrame();
+
private:
Q_DECLARE_PRIVATE(QAspectEngine)
};
diff --git a/src/core/aspects/qaspectengine_p.h b/src/core/aspects/qaspectengine_p.h
index 9c042b5a5..e1aaa9de9 100644
--- a/src/core/aspects/qaspectengine_p.h
+++ b/src/core/aspects/qaspectengine_p.h
@@ -56,6 +56,7 @@
#include <QtCore/qsharedpointer.h>
#include <Qt3DCore/private/qaspectfactory_p.h>
+#include <Qt3DCore/private/qaspectengine_p.h>
#include <QtCore/private/qobject_p.h>
QT_BEGIN_NAMESPACE
@@ -64,7 +65,6 @@ namespace Qt3DCore {
class QEntity;
class QNode;
-class QAspectEngine;
class QAspectManager;
class QPostman;
class QScene;
@@ -91,6 +91,7 @@ public:
QVector<QAbstractAspect*> m_aspects;
QHash<QString, QAbstractAspect *> m_namedAspects;
bool m_initialized;
+ QAspectEngine::RunMode m_runMode;
#if QT_CONFIG(qt3d_profile_jobs)
Debug::AspectCommandDebugger *m_commandDebugger;
diff --git a/src/core/aspects/qaspectmanager.cpp b/src/core/aspects/qaspectmanager.cpp
index a028e38cb..6502590d8 100644
--- a/src/core/aspects/qaspectmanager.cpp
+++ b/src/core/aspects/qaspectmanager.cpp
@@ -103,6 +103,7 @@ QAspectManager::QAspectManager(QObject *parent)
, m_changeArbiter(new QChangeArbiter(this))
, m_serviceLocator(new QServiceLocator())
, m_simulationLoopRunning(false)
+ , m_driveMode(QAspectEngine::Automatic)
{
qRegisterMetaType<QSurface *>("QSurface*");
qCDebug(Aspects) << Q_FUNC_INFO;
@@ -115,6 +116,12 @@ QAspectManager::~QAspectManager()
delete m_scheduler;
}
+void QAspectManager::setRunMode(QAspectEngine::RunMode mode)
+{
+ qCDebug(Aspects) << Q_FUNC_INFO << "Running Loop Drive Mode set to" << mode;
+ m_driveMode = mode;
+}
+
// Main thread (called by QAspectEngine)
void QAspectManager::enterSimulationLoop()
{
@@ -137,8 +144,9 @@ void QAspectManager::enterSimulationLoop()
}
qCDebug(Aspects) << "Done calling onEngineStartup() for each aspect";
- // Trigger event loop
- requestNextFrame();
+ // Start running loop if Qt3D is in charge of driving it
+ if (m_driveMode == QAspectEngine::Automatic)
+ requestNextFrame();
}
// Main thread (called by QAspectEngine)
@@ -319,8 +327,9 @@ bool QAspectManager::event(QEvent *e)
// Process current frame
processFrame();
- // Request next frame if we are still running
- if (m_simulationLoopRunning)
+ // Request next frame if we are still running and if Qt3D is driving
+ // the loop
+ if (m_simulationLoopRunning && m_driveMode == QAspectEngine::Automatic)
requestNextFrame();
}
diff --git a/src/core/aspects/qaspectmanager_p.h b/src/core/aspects/qaspectmanager_p.h
index 1c07ab797..d654f7b5a 100644
--- a/src/core/aspects/qaspectmanager_p.h
+++ b/src/core/aspects/qaspectmanager_p.h
@@ -52,6 +52,7 @@
//
#include <Qt3DCore/qnodecreatedchange.h>
+#include <Qt3DCore/qaspectengine.h>
#include <QtCore/QObject>
#include <QtCore/QScopedPointer>
#include <QtCore/QSemaphore>
@@ -82,6 +83,7 @@ public:
explicit QAspectManager(QObject *parent = 0);
~QAspectManager();
+ void setRunMode(QAspectEngine::RunMode mode);
void enterSimulationLoop();
void exitSimulationLoop();
@@ -90,6 +92,7 @@ public:
public Q_SLOTS:
void initialize();
void shutdown();
+ void processFrame();
void setRootEntity(Qt3DCore::QEntity *root, const QVector<Qt3DCore::QNodeCreatedChangeBasePtr> &changes);
void registerAspect(Qt3DCore::QAbstractAspect *aspect);
@@ -104,7 +107,6 @@ public:
private:
bool event(QEvent *event) override;
void requestNextFrame();
- void processFrame();
QVector<QAbstractAspect *> m_aspects;
QEntity *m_root;
@@ -115,6 +117,7 @@ private:
QScopedPointer<QServiceLocator> m_serviceLocator;
bool m_mainLoopRunning;
bool m_simulationLoopRunning;
+ QAspectEngine::RunMode m_driveMode;
};