| 1 | // Copyright (C) 2015 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 "manager_p.h" |
| 5 | |
| 6 | #include <Qt3DLogic/qlogicaspect.h> |
| 7 | #include <QtCore/QDebug> |
| 8 | #include <QtCore/QThread> |
| 9 | #include <QtCore/qcoreapplication.h> |
| 10 | |
| 11 | #include <Qt3DCore/private/qabstractaspect_p.h> |
| 12 | #include <Qt3DCore/private/qaspectmanager_p.h> |
| 13 | #include <Qt3DLogic/private/executor_p.h> |
| 14 | #include <Qt3DLogic/private/managers_p.h> |
| 15 | |
| 16 | QT_BEGIN_NAMESPACE |
| 17 | |
| 18 | namespace Qt3DLogic { |
| 19 | namespace Logic { |
| 20 | |
| 21 | Manager::Manager() |
| 22 | : m_logicHandlerManager(new HandlerManager) |
| 23 | , m_logicAspect(nullptr) |
| 24 | , m_executor(nullptr) |
| 25 | , m_dt(0.0f) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | Manager::~Manager() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | void Manager::setExecutor(Executor *executor) |
| 34 | { |
| 35 | m_executor = executor; |
| 36 | } |
| 37 | |
| 38 | void Manager::appendHandler(Handler *handler) |
| 39 | { |
| 40 | HHandler handle = m_logicHandlerManager->lookupHandle(id: handler->peerId()); |
| 41 | if (!m_logicHandlers.contains(t: handle)) { |
| 42 | m_logicHandlers.append(t: handle); |
| 43 | m_logicComponentIds.append(t: handler->peerId()); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void Manager::removeHandler(Qt3DCore::QNodeId id) |
| 48 | { |
| 49 | HHandler handle = m_logicHandlerManager->lookupHandle(id); |
| 50 | m_logicComponentIds.removeAll(t: id); |
| 51 | m_logicHandlers.removeAll(t: handle); |
| 52 | m_logicHandlerManager->releaseResource(id); |
| 53 | } |
| 54 | |
| 55 | bool Manager::hasFrameActions() const |
| 56 | { |
| 57 | return m_logicHandlers.size() > 0; |
| 58 | } |
| 59 | |
| 60 | // Called from Job postFrame (main thread) |
| 61 | void Manager::triggerLogicFrameUpdates() |
| 62 | { |
| 63 | Q_ASSERT(m_executor); |
| 64 | |
| 65 | // Don't use blocking queued connections to main thread if it is already |
| 66 | // in the process of shutting down as that will deadlock. |
| 67 | if (Qt3DCore::QAbstractAspectPrivate::get(aspect: m_logicAspect)->m_aspectManager->isShuttingDown()) |
| 68 | return; |
| 69 | |
| 70 | m_executor->processLogicFrameUpdates(nodeIds: m_logicComponentIds, dt: m_dt); |
| 71 | } |
| 72 | |
| 73 | } // namespace Logic |
| 74 | } // namespace Qt3DLogic |
| 75 | |
| 76 | QT_END_NAMESPACE |
| 77 |
