summaryrefslogtreecommitdiffstats
path: root/src/core/nodes
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2019-08-14 11:50:10 +0100
committerPaul Lemire <paul.lemire@kdab.com>2019-08-29 08:32:29 +0200
commitc1b1bbbb72a9d0c11d92c8cdb998c52d515932da (patch)
treeea126554b3dde2505deb10b1a5b381fd82384b13 /src/core/nodes
parentfa801839d384e9d6eea09350433e354cf753c267 (diff)
Use sync method when initializing new backend nodes
If the node type supports syncing, use that rather than the creation message. The message is still needed since that is passed to the instantiation functor (none of qt3d's classes appear to use anything but the node id, but can't be sure no other classes do, and can't add other virtual method without breaking BC). Change-Id: Id99f448070b8722a7809b968798772c9eb3c8397 Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/core/nodes')
-rw-r--r--src/core/nodes/qbackendnode.h2
-rw-r--r--src/core/nodes/qentity.cpp9
-rw-r--r--src/core/nodes/qnode.cpp26
-rw-r--r--src/core/nodes/qnode.h1
-rw-r--r--src/core/nodes/qnode_p.h2
5 files changed, 21 insertions, 19 deletions
diff --git a/src/core/nodes/qbackendnode.h b/src/core/nodes/qbackendnode.h
index 21485cd5f..550ced04f 100644
--- a/src/core/nodes/qbackendnode.h
+++ b/src/core/nodes/qbackendnode.h
@@ -62,7 +62,7 @@ class Q_3DCORESHARED_EXPORT QBackendNodeMapper
{
public:
virtual ~QBackendNodeMapper();
- virtual QBackendNode *create(const QNodeCreatedChangeBasePtr &change) const = 0;
+ virtual QBackendNode *create(const QNodeCreatedChangeBasePtr &change) const = 0; // TODO QT6 change to only take a NodeId
virtual QBackendNode *get(QNodeId id) const = 0;
virtual void destroy(QNodeId id) const = 0;
};
diff --git a/src/core/nodes/qentity.cpp b/src/core/nodes/qentity.cpp
index a1f7d2859..546f1d670 100644
--- a/src/core/nodes/qentity.cpp
+++ b/src/core/nodes/qentity.cpp
@@ -125,6 +125,7 @@ QEntity::QEntity(QNode *parent)
QEntity::QEntity(QEntityPrivate &dd, QNode *parent)
: QNode(dd, parent)
{
+ connect(this, &QNode::parentChanged, this, &QEntity::onParentChanged);
}
QEntity::~QEntity()
@@ -259,10 +260,6 @@ QNodeId QEntityPrivate::parentEntityId() const
QNodeCreatedChangeBasePtr QEntity::createNodeCreationChange() const
{
- // connect to the parentChanged signal here rather than constructor because
- // until now there's no backend node to notify when parent changes
- connect(this, &QNode::parentChanged, this, &QEntity::onParentChanged);
-
auto creationChange = QNodeCreatedChangePtr<QEntityData>::create(this);
auto &data = creationChange->data;
@@ -294,6 +291,10 @@ QNodeCreatedChangeBasePtr QEntity::createNodeCreationChange() const
void QEntity::onParentChanged(QObject *)
{
+ Q_D(QEntity);
+ if (!d->m_hasBackendNode)
+ return;
+
const auto parentID = parentEntity() ? parentEntity()->id() : Qt3DCore::QNodeId();
auto parentChange = Qt3DCore::QPropertyUpdatedChangePtr::create(id());
parentChange->setPropertyName("parentEntityUpdated");
diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp
index 45d58bd8c..5f9468124 100644
--- a/src/core/nodes/qnode.cpp
+++ b/src/core/nodes/qnode.cpp
@@ -39,6 +39,7 @@
#include "qnode.h"
#include "qnode_p.h"
+#include "qscene_p.h"
#include <Qt3DCore/QComponent>
#include <Qt3DCore/qaspectengine.h>
@@ -55,10 +56,11 @@
#include <Qt3DCore/private/corelogging_p.h>
#include <Qt3DCore/private/qdestructionidandtypecollector_p.h>
-#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
#include <Qt3DCore/private/qnodevisitor_p.h>
#include <Qt3DCore/private/qpostman_p.h>
#include <Qt3DCore/private/qscene_p.h>
+#include <Qt3DCore/private/qaspectengine_p.h>
+#include <Qt3DCore/private/qaspectmanager_p.h>
#include <QtCore/private/qmetaobject_p.h>
QT_BEGIN_NAMESPACE
@@ -110,17 +112,15 @@ void QNodePrivate::init(QNode *parent)
*
* Sends QNodeCreatedChange events to the aspects.
*/
-void QNodePrivate::notifyCreationChange()
+void QNodePrivate::createBackendNode()
{
- Q_Q(QNode);
// Do nothing if we already have already sent a node creation change
// and not a subsequent node destroyed change.
- if (m_hasBackendNode || !m_scene)
+ if (m_hasBackendNode || !m_scene || !m_scene->engine())
return;
- QNodeCreatedChangeGenerator generator(q);
- const auto creationChanges = generator.creationChanges();
- for (const auto &change : creationChanges)
- notifyObservers(change);
+
+ Q_Q(QNode);
+ QAspectEnginePrivate::get(m_scene->engine())->addNode(q);
}
/*!
@@ -189,7 +189,7 @@ void QNodePrivate::_q_postConstructorInit()
return;
// Set the scene on this node and all children it references so that all
- // children have a scene set since notifyCreationChanges will set
+ // children have a scene set since createBackendNode will set
// m_hasBackendNode to true for all children, which would prevent them from
// ever having their scene set
if (m_scene) {
@@ -198,7 +198,7 @@ void QNodePrivate::_q_postConstructorInit()
}
// Let the backend know we have been added to the scene
- notifyCreationChange();
+ createBackendNode();
// Let the backend parent know that they have a new child
Q_ASSERT(parentNode);
@@ -247,7 +247,7 @@ void QNodePrivate::_q_addChild(QNode *childNode)
}
// Update the scene
- // TODO: Fold this into the QNodeCreatedChangeGenerator so we don't have to
+ // TODO: Fold this into the QAspectEnginePrivate::addNode so we don't have to
// traverse the sub tree three times!
QNodeVisitor visitor;
visitor.traverse(childNode, this, &QNodePrivate::addEntityComponentToScene);
@@ -340,13 +340,13 @@ void QNodePrivate::_q_setParentHelper(QNode *parent)
// child->setParent(subTreeRoot)
// We need to take into account that subTreeRoot needs to be
// created in the backend before the child.
- // Therefore we only call notifyCreationChanges if the parent
+ // Therefore we only call createBackendNode if the parent
// hasn't been created yet as we know that when the parent will be
// fully created, it will also send the changes for all of its
// children
if (newParentPrivate->m_hasBackendNode)
- notifyCreationChange();
+ createBackendNode();
// If we have a valid new parent, we let him know that we are its child
QNodePrivate::get(parent)->_q_addChild(q);
diff --git a/src/core/nodes/qnode.h b/src/core/nodes/qnode.h
index d4e4ff088..9ca817fb6 100644
--- a/src/core/nodes/qnode.h
+++ b/src/core/nodes/qnode.h
@@ -134,6 +134,7 @@ private:
friend class QAspectEngine;
friend class QAspectEnginePrivate;
+ friend class QAbstractAspectPrivate;
friend class QNodeCreatedChangeGenerator;
friend class QPostman;
friend class QScene;
diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h
index 990c2caeb..491059ff9 100644
--- a/src/core/nodes/qnode_p.h
+++ b/src/core/nodes/qnode_p.h
@@ -166,7 +166,7 @@ public:
void _q_ensureBackendNodeCreated();
private:
- void notifyCreationChange();
+ void createBackendNode();
void notifyDestructionChangesAndRemoveFromScene();
void _q_addChild(QNode *childNode);
void _q_removeChild(QNode *childNode);