diff options
author | Jim Albamont <jim.albamont@kdab.com> | 2019-03-13 13:23:21 -0500 |
---|---|---|
committer | James Turner <james.turner@kdab.com> | 2019-04-04 09:15:50 +0000 |
commit | bf2c2e9bb2dd0b13cb2cb6728de0c2421fbafbb7 (patch) | |
tree | 27ac13c4706c134ae476071a6b8b9646ac97ee35 /src/render/jobs | |
parent | f0f5a2de1da2e05e3587d2a6486687ebbe649339 (diff) |
Fix Entity parenting hierarchy
When the initial Entity backend node hierarchy is created it skips over
any non-entity nodes to ensure that Entities are only parented to
other Entities. Calling QNode::setParent breaks this when reparenting
Entities to non-entity nodes.
Fix by sending a new "parentEntityUpdated" property update that backend
Entity nodes listen for. They keep the id of their new parent and flag
the need to rebuild the entity hierarchy. This triggers a new job to
clear the children and parents of every backend Entity, then rebuilds
the hierarchy using the stored parent ID in each Entity. This is much
more forgiving of creation/parenting ordering issues and shouldn't be
less performant because any Entity reparent was previously marking
everything dirty anyway.
Add a new test from QTBUG-73905 that creates 4 cylinders and manipulates
the parents in different ways.
Add a new test to tst_nodes to reparent a QEntity to a QNode and ensure
the entity finds it's correct QEntity parent.
Add a new test to tst_entity to ensure backend nodes correctly handle
the new parenting events.
Task-number: QTBUG-73905
Change-Id: Iab0203947d89bbed2868b3629fbde879675fe568
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/jobs')
-rw-r--r-- | src/render/jobs/job_common_p.h | 1 | ||||
-rw-r--r-- | src/render/jobs/jobs.pri | 2 | ||||
-rw-r--r-- | src/render/jobs/updateentityhierarchyjob.cpp | 80 | ||||
-rw-r--r-- | src/render/jobs/updateentityhierarchyjob_p.h | 91 | ||||
-rw-r--r-- | src/render/jobs/updateentitylayersjob_p.h | 2 |
5 files changed, 175 insertions, 1 deletions
diff --git a/src/render/jobs/job_common_p.h b/src/render/jobs/job_common_p.h index 2ae7d81ff..8f8242ec8 100644 --- a/src/render/jobs/job_common_p.h +++ b/src/render/jobs/job_common_p.h @@ -107,6 +107,7 @@ namespace JobTypes { SyncFilterEntityByLayer, SyncMaterialGatherer, UpdateLayerEntity, + UpdateEntityHierarchy, SendTextureChangesToFrontend }; diff --git a/src/render/jobs/jobs.pri b/src/render/jobs/jobs.pri index 472531681..0c326c0b5 100644 --- a/src/render/jobs/jobs.pri +++ b/src/render/jobs/jobs.pri @@ -31,6 +31,7 @@ HEADERS += \ $$PWD/filterproximitydistancejob_p.h \ $$PWD/abstractpickingjob_p.h \ $$PWD/raycastingjob_p.h \ + $$PWD/updateentityhierarchyjob_p.h \ $$PWD/updateentitylayersjob_p.h SOURCES += \ @@ -61,5 +62,6 @@ SOURCES += \ $$PWD/filterproximitydistancejob.cpp \ $$PWD/abstractpickingjob.cpp \ $$PWD/raycastingjob.cpp \ + $$PWD/updateentityhierarchyjob.cpp \ $$PWD/updateentitylayersjob.cpp diff --git a/src/render/jobs/updateentityhierarchyjob.cpp b/src/render/jobs/updateentityhierarchyjob.cpp new file mode 100644 index 000000000..7c18514bb --- /dev/null +++ b/src/render/jobs/updateentityhierarchyjob.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "updateentityhierarchyjob_p.h" +#include <Qt3DRender/private/managers_p.h> +#include <Qt3DRender/private/nodemanagers_p.h> +#include <Qt3DRender/private/entity_p.h> +#include <Qt3DRender/private/job_common_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace Render { + +UpdateEntityHierarchyJob::UpdateEntityHierarchyJob() + : m_manager(nullptr) +{ + SET_JOB_RUN_STAT_TYPE(this, JobTypes::UpdateEntityHierarchy, 0); +} + +void UpdateEntityHierarchyJob::run() +{ + Q_ASSERT(m_manager); + EntityManager *entityManager = m_manager->renderNodesManager(); + + const QVector<HEntity> handles = entityManager->activeHandles(); + + // Clear the parents and children + for (const HEntity &handle : handles) { + Entity *entity = entityManager->data(handle); + entity->clearEntityHierarchy(); + } + for (const HEntity &handle : handles) { + Entity *entity = entityManager->data(handle); + entity->rebuildEntityHierarchy(); + } +} + +} // Render + +} // Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/jobs/updateentityhierarchyjob_p.h b/src/render/jobs/updateentityhierarchyjob_p.h new file mode 100644 index 000000000..f6ba2d584 --- /dev/null +++ b/src/render/jobs/updateentityhierarchyjob_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QT3DRENDER_RENDER_UPDATEENTITYHIERARCHYJOB_P_H +#define QT3DRENDER_RENDER_UPDATEENTITYHIERARCHYJOB_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DRender/private/qt3drender_global_p.h> +#include <Qt3DCore/qaspectjob.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace Render { + +class Entity; +class NodeManagers; + +class QT3DRENDERSHARED_PRIVATE_EXPORT UpdateEntityHierarchyJob: public Qt3DCore::QAspectJob +{ +public: + UpdateEntityHierarchyJob(); + + inline void setManager(NodeManagers *manager) { m_manager = manager; } + inline NodeManagers *manager() const { return m_manager; } + + // QAspectJob interface + void run() final; + +private: + NodeManagers *m_manager; +}; + + +using UpdateEntityHierarchyJobPtr = QSharedPointer<UpdateEntityHierarchyJob>; + +} // Render + +} // Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_UPDATEENTITYHIERARCHYJOB_P_H diff --git a/src/render/jobs/updateentitylayersjob_p.h b/src/render/jobs/updateentitylayersjob_p.h index 8c73899d9..f2e63e32d 100644 --- a/src/render/jobs/updateentitylayersjob_p.h +++ b/src/render/jobs/updateentitylayersjob_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt3D module of the Qt Toolkit. |