1// Copyright (C) 2016 Paul Lemire
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DRENDER_RENDER_FILTERENTITYBYCOMPONENTJOB_H
5#define QT3DRENDER_RENDER_FILTERENTITYBYCOMPONENTJOB_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <Qt3DCore/qaspectjob.h>
19#include <Qt3DCore/qnodeid.h>
20#include <Qt3DRender/private/managers_p.h>
21#include <Qt3DRender/private/entity_p.h>
22#include <Qt3DRender/private/job_common_p.h>
23
24QT_BEGIN_NAMESPACE
25
26namespace Qt3DRender {
27
28namespace Render {
29
30class Entity;
31class EntityManager;
32
33template<typename T, typename ... Ts>
34class FilterEntityByComponentJob : public Qt3DCore::QAspectJob
35{
36public:
37 FilterEntityByComponentJob()
38 : Qt3DCore::QAspectJob()
39 , m_manager(nullptr)
40 {
41 SET_JOB_RUN_STAT_TYPE(this, JobTypes::EntityComponentTypeFiltering, 0)
42 }
43
44 inline void setManager(EntityManager *manager) noexcept { m_manager = manager; }
45 inline std::vector<Entity *> &filteredEntities() noexcept { return m_filteredEntities; }
46
47 void run() override
48 {
49 m_filteredEntities.clear();
50 const std::vector<HEntity> &handles = m_manager->activeHandles();
51 m_filteredEntities.reserve(n: handles.size());
52 for (const HEntity &handle : handles) {
53 Entity *e = m_manager->data(handle);
54 if (e->containsComponentsOfType<T, Ts...>())
55 m_filteredEntities.push_back(x: e);
56 }
57 }
58
59private:
60 EntityManager *m_manager;
61 std::vector<Entity *> m_filteredEntities;
62};
63
64template<typename T, typename ... Ts>
65using FilterEntityByComponentJobPtr = QSharedPointer<FilterEntityByComponentJob<T, Ts...>>;
66
67} // Render
68
69} // Qt3DRender
70
71QT_END_NAMESPACE
72#endif // QT3DRENDER_RENDER_FILTERENTITYBYCOMPONENTJOB_H
73

source code of qt3d/src/render/jobs/filterentitybycomponentjob_p.h