1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qchangearbiter_p.h"
5
6#include <Qt3DCore/qentity.h>
7#include <Qt3DCore/qcomponent.h>
8#include <QtCore/QMutexLocker>
9#include <QtCore/QReadLocker>
10#include <QtCore/QThread>
11#include <QtCore/QWriteLocker>
12
13#include <Qt3DCore/private/corelogging_p.h>
14#include <Qt3DCore/private/qabstractaspectjobmanager_p.h>
15#include <Qt3DCore/private/qscene_p.h>
16#include <Qt3DCore/private/vector_helper_p.h>
17
18#include <mutex>
19
20QT_BEGIN_NAMESPACE
21
22namespace Qt3DCore {
23
24QChangeArbiter::QChangeArbiter(QObject *parent)
25 : QObject(parent)
26 , m_scene(nullptr)
27{
28}
29
30QChangeArbiter::~QChangeArbiter()
31{
32}
33
34void QChangeArbiter::setScene(QScene *scene)
35{
36 m_scene = scene;
37}
38
39QScene *QChangeArbiter::scene() const
40{
41 return m_scene;
42}
43
44void QChangeArbiter::addDirtyFrontEndNode(QNode *node)
45{
46 if (!m_dirtyFrontEndNodes.contains(t: node)) {
47 m_dirtyFrontEndNodes += node;
48 emit receivedChange();
49 }
50}
51
52void QChangeArbiter::addDirtyEntityComponentNodes(QEntity *entity, QComponent *component,
53 ComponentRelationshipChange::RelationShip change)
54{
55 addDirtyFrontEndNode(node: entity);
56 m_dirtyEntityComponentNodeChanges.push_back(t: {.node: entity, .subNode: component, .change: change});
57}
58
59void QChangeArbiter::removeDirtyFrontEndNode(QNode *node)
60{
61 m_dirtyFrontEndNodes.removeOne(t: node);
62 m_dirtyEntityComponentNodeChanges.erase(abegin: std::remove_if(first: m_dirtyEntityComponentNodeChanges.begin(), last: m_dirtyEntityComponentNodeChanges.end(), pred: [node](const ComponentRelationshipChange &elt) {
63 return elt.node == node || elt.subNode == node;
64 }), aend: m_dirtyEntityComponentNodeChanges.end());
65}
66
67QList<QNode *> QChangeArbiter::takeDirtyFrontEndNodes()
68{
69 return Qt3DCore::moveAndClear(data&: m_dirtyFrontEndNodes);
70}
71
72QList<ComponentRelationshipChange> QChangeArbiter::takeDirtyEntityComponentNodes()
73{
74 return Qt3DCore::moveAndClear(data&: m_dirtyEntityComponentNodeChanges);
75}
76
77} // namespace Qt3DCore
78
79QT_END_NAMESPACE
80
81#include "moc_qchangearbiter_p.cpp"
82

source code of qt3d/src/core/qchangearbiter.cpp