diff options
author | Paul Lemire <paul.lemire350@gmail.com> | 2016-05-13 22:11:07 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2016-06-27 10:52:15 +0000 |
commit | 17f72a7c1982a024291c571842741e3d00784bb7 (patch) | |
tree | d1a58a2f6f26ef9df77f5d63b079aab376006e17 | |
parent | 6c9fdd02150e356931e049ebb1fa6de93edb1838 (diff) |
Entity: add simple method to check for components
Change-Id: I560089e499aa8e98415b00b3131a5e9923c1a551
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/render/backend/entity.cpp | 1 | ||||
-rw-r--r-- | src/render/backend/entity_p.h | 13 | ||||
-rw-r--r-- | tests/auto/render/entity/tst_entity.cpp | 8 |
3 files changed, 20 insertions, 2 deletions
diff --git a/src/render/backend/entity.cpp b/src/render/backend/entity.cpp index 1eec44f7b..7091d493f 100644 --- a/src/render/backend/entity.cpp +++ b/src/render/backend/entity.cpp @@ -166,6 +166,7 @@ void Entity::initializeFromPeer(const QNodeCreatedChangeBasePtr &change) m_geometryRendererComponent = QNodeId(); m_objectPickerComponent = QNodeId(); m_boundingVolumeDebugComponent = QNodeId(); + m_computeComponent = QNodeId(); m_layerComponents.clear(); m_shaderDataComponents.clear(); m_lightComponents.clear(); diff --git a/src/render/backend/entity_p.h b/src/render/backend/entity_p.h index 49f5f4106..cf6c0117b 100644 --- a/src/render/backend/entity_p.h +++ b/src/render/backend/entity_p.h @@ -153,6 +153,19 @@ public: return QVector<Qt3DCore::QNodeId>(); } + template<typename T> + bool containsComponentsOfType() + { + return !componentUuid<T>().isNull(); + } + + template<typename T, typename Ts, typename ... Ts2> + bool containsComponentsOfType() + { + return containsComponentsOfType<T>() && containsComponentsOfType<Ts, Ts2...>(); + } + + private: void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; diff --git a/tests/auto/render/entity/tst_entity.cpp b/tests/auto/render/entity/tst_entity.cpp index fad49fd99..627891375 100644 --- a/tests/auto/render/entity/tst_entity.cpp +++ b/tests/auto/render/entity/tst_entity.cpp @@ -121,11 +121,13 @@ private slots: QVERIFY(!entity.componentUuid<Material>().isNull()); QVERIFY(!entity.componentUuid<GeometryRenderer>().isNull()); QVERIFY(!entity.componentUuid<ObjectPicker>().isNull()); - QVERIFY(!entity.componentsUuid<Layer>().isEmpty()); + QVERIFY(!entity.componentUuid<ComputeCommand>().isNull()); QVERIFY(!entity.componentsUuid<Layer>().isEmpty()); QVERIFY(!entity.componentsUuid<ShaderData>().isEmpty()); QVERIFY(entity.isBoundingVolumeDirty()); QVERIFY(renderer.dirtyBits() != 0); + bool containsAll = entity.containsComponentsOfType<Transform, CameraLens, Material, GeometryRenderer, ObjectPicker, ComputeCommand>(); + QVERIFY(containsAll); // WHEN entity.cleanup(); @@ -136,10 +138,12 @@ private slots: QVERIFY(entity.componentUuid<Material>().isNull()); QVERIFY(entity.componentUuid<GeometryRenderer>().isNull()); QVERIFY(entity.componentUuid<ObjectPicker>().isNull()); - QVERIFY(entity.componentsUuid<Layer>().isEmpty()); + QVERIFY(entity.componentUuid<QComputeCommand>().isNull()); QVERIFY(entity.componentsUuid<Layer>().isEmpty()); QVERIFY(entity.componentsUuid<ShaderData>().isEmpty()); QVERIFY(!entity.isBoundingVolumeDirty()); + containsAll = entity.containsComponentsOfType<Transform, CameraLens, Material, GeometryRenderer, ObjectPicker, ComputeCommand>(); + QVERIFY(!containsAll); } void shouldHandleSingleComponentEvents_data() |