diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2019-10-03 16:19:01 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2019-10-07 15:15:25 +0200 |
commit | 222c7f3c57d94eec1df231e46646470ddd1e3655 (patch) | |
tree | 9b8940857804d709df71d0d004a0ff66dc83bdb3 /src/render/io | |
parent | fa78d129ffad21f1c506aadf4f6408dceda6e08f (diff) |
Update LoadSceneJob to use direct sync
Change-Id: Ie615b903e2bd2307e0b7fe853022ea9a17342ab8
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/render/io')
-rw-r--r-- | src/render/io/qsceneloader.cpp | 53 | ||||
-rw-r--r-- | src/render/io/qsceneloader.h | 1 | ||||
-rw-r--r-- | src/render/io/qsceneloader_p.h | 1 | ||||
-rw-r--r-- | src/render/io/scene.cpp | 26 | ||||
-rw-r--r-- | src/render/io/scene_p.h | 1 |
5 files changed, 22 insertions, 60 deletions
diff --git a/src/render/io/qsceneloader.cpp b/src/render/io/qsceneloader.cpp index d66fe3080..cf1e45355 100644 --- a/src/render/io/qsceneloader.cpp +++ b/src/render/io/qsceneloader.cpp @@ -219,6 +219,27 @@ void QSceneLoaderPrivate::setStatus(QSceneLoader::Status status) } } +void QSceneLoaderPrivate::setSceneRoot(QEntity *root) +{ + // If we already have a scene sub tree, delete it + if (m_subTreeRoot) { + delete m_subTreeRoot; + m_subTreeRoot = nullptr; + } + + // If we have successfully loaded a scene, graft it in + if (root) { + // Get the entity to which this component is attached + const Qt3DCore::QNodeIdVector entities = m_scene->entitiesForComponent(m_id); + Q_ASSERT(entities.size() == 1); + Qt3DCore::QNodeId parentEntityId = entities.first(); + QEntity *parentEntity = qobject_cast<QEntity *>(m_scene->lookupNode(parentEntityId)); + root->setParent(parentEntity); + m_subTreeRoot = root; + populateEntityMap(m_subTreeRoot); + } +} + /*! The constructor creates an instance with the specified \a parent. */ @@ -238,38 +259,6 @@ QSceneLoader::QSceneLoader(QSceneLoaderPrivate &dd, QNode *parent) { } -// Called in main thread -/*! \internal */ -void QSceneLoader::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) -{ - Q_D(QSceneLoader); - QPropertyUpdatedChangePtr e = qSharedPointerCast<QPropertyUpdatedChange>(change); - if (e->type() == PropertyUpdated) { - if (e->propertyName() == QByteArrayLiteral("scene")) { - // If we already have a scene sub tree, delete it - if (d->m_subTreeRoot) { - delete d->m_subTreeRoot; - d->m_subTreeRoot = nullptr; - } - - // If we have successfully loaded a scene, graft it in - auto *subTreeRoot = e->value().value<Qt3DCore::QEntity *>(); - if (subTreeRoot) { - // Get the entity to which this component is attached - const Qt3DCore::QNodeIdVector entities = d->m_scene->entitiesForComponent(d->m_id); - Q_ASSERT(entities.size() == 1); - Qt3DCore::QNodeId parentEntityId = entities.first(); - QEntity *parentEntity = qobject_cast<QEntity *>(d->m_scene->lookupNode(parentEntityId)); - subTreeRoot->setParent(parentEntity); - d->m_subTreeRoot = subTreeRoot; - d->populateEntityMap(d->m_subTreeRoot); - } - } else if (e->propertyName() == QByteArrayLiteral("status")) { - d->setStatus(e->value().value<QSceneLoader::Status>()); - } - } -} - QUrl QSceneLoader::source() const { Q_D(const QSceneLoader); diff --git a/src/render/io/qsceneloader.h b/src/render/io/qsceneloader.h index 4cb743333..6842a6926 100644 --- a/src/render/io/qsceneloader.h +++ b/src/render/io/qsceneloader.h @@ -60,7 +60,6 @@ public: explicit QSceneLoader(Qt3DCore::QNode *parent = nullptr); ~QSceneLoader(); - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override; enum Status { None = 0, Loading, diff --git a/src/render/io/qsceneloader_p.h b/src/render/io/qsceneloader_p.h index 50745c66f..213bc1104 100644 --- a/src/render/io/qsceneloader_p.h +++ b/src/render/io/qsceneloader_p.h @@ -67,6 +67,7 @@ public: QSceneLoaderPrivate(); void setStatus(QSceneLoader::Status status); + void setSceneRoot(Qt3DCore::QEntity *root); Q_DECLARE_PUBLIC(QSceneLoader) diff --git a/src/render/io/scene.cpp b/src/render/io/scene.cpp index e7f289f8a..089091701 100644 --- a/src/render/io/scene.cpp +++ b/src/render/io/scene.cpp @@ -66,16 +66,6 @@ void Scene::cleanup() m_source.clear(); } -void Scene::setStatus(QSceneLoader::Status status) -{ - // Send the new subtree to the frontend or notify failure - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId()); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("status"); - e->setValue(QVariant::fromValue(status)); - notifyObservers(e); -} - void Scene::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) { const QSceneLoader *node = qobject_cast<const QSceneLoader *>(frontEnd); @@ -99,22 +89,6 @@ QUrl Scene::source() const return m_source; } -void Scene::setSceneSubtree(Qt3DCore::QEntity *subTree) -{ - if (subTree) { - // Move scene sub tree to the application thread so that it can be grafted in. - const auto appThread = QCoreApplication::instance()->thread(); - subTree->moveToThread(appThread); - } - - // Send the new subtree to the frontend or notify failure - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId()); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("scene"); - e->setValue(QVariant::fromValue(subTree)); - notifyObservers(e); -} - void Scene::setSceneManager(SceneManager *manager) { if (m_sceneManager != manager) diff --git a/src/render/io/scene_p.h b/src/render/io/scene_p.h index 04b9bba1a..bf625b369 100644 --- a/src/render/io/scene_p.h +++ b/src/render/io/scene_p.h @@ -74,7 +74,6 @@ public: void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; QUrl source() const; - void setSceneSubtree(Qt3DCore::QEntity *subTree); void setSceneManager(SceneManager *manager); void cleanup(); |