summaryrefslogtreecommitdiffstats
path: root/src/logic
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2015-07-30 16:22:04 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-08-06 13:43:27 +0000
commitce69c98f6954ef2c8806bc44a457a58e4202d751 (patch)
treeed1e4e6f3b4782299457b9e8ce92bd8a25b51477 /src/logic
parent9b6ca58d5d49acdff284e5e4853b338bb60572e8 (diff)
Add a new Logic aspect to allow synchronous operations
The QLogicComponent allows users to have code execute synchronously with the Qt3D engine each frame. Very useful for implementing some pieces of applicaton logic or for prototyping functionality that can later be folded back into Qt3D in a declarative manner. Change-Id: Ia7d69b77d782e67ace0a64a7c59188786fb731fd Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/logic')
-rw-r--r--src/logic/doc/qt3dlogic.qdocconf62
-rw-r--r--src/logic/handle_types_p.h59
-rw-r--r--src/logic/logic.pri22
-rw-r--r--src/logic/logic.pro20
-rw-r--r--src/logic/logiccallbackjob.cpp67
-rw-r--r--src/logic/logiccallbackjob_p.h68
-rw-r--r--src/logic/logicexecutor.cpp104
-rw-r--r--src/logic/logicexecutor_p.h91
-rw-r--r--src/logic/logichandler.cpp92
-rw-r--r--src/logic/logichandler_p.h89
-rw-r--r--src/logic/logicmanager.cpp106
-rw-r--r--src/logic/logicmanager_p.h89
-rw-r--r--src/logic/logicmanagers_p.h68
-rw-r--r--src/logic/qlogicaspect.cpp166
-rw-r--r--src/logic/qlogicaspect.h81
-rw-r--r--src/logic/qlogicaspect_p.h71
-rw-r--r--src/logic/qlogiccomponent.cpp111
-rw-r--r--src/logic/qlogiccomponent.h81
-rw-r--r--src/logic/qlogiccomponent_p.h60
-rw-r--r--src/logic/qt3dlogic_global.h56
20 files changed, 1563 insertions, 0 deletions
diff --git a/src/logic/doc/qt3dlogic.qdocconf b/src/logic/doc/qt3dlogic.qdocconf
new file mode 100644
index 000000000..3bdfc8b59
--- /dev/null
+++ b/src/logic/doc/qt3dlogic.qdocconf
@@ -0,0 +1,62 @@
+include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf)
+
+project = Qt3DLogic
+description = Qt3D Logic Reference Documentation
+version = $QT_VERSION
+
+examplesinstallpath = qt3d
+
+qhp.projects = Qt3DLogic
+
+qhp.Qt3DLogic.file = qt3dlogic.qhp
+qhp.Qt3DLogic.namespace = org.qt-project.qt3dlogic.$QT_VERSION_TAG
+qhp.Qt3DLogic.virtualFolder = qt3dlogic
+qhp.Qt3DLogic.indexTitle = Qt3D Module
+qhp.Qt3DLogic.indexRoot =
+
+qhp.Qt3DLogic.filterAttributes = qt3dlogic $QT_VERSION qtrefdoc
+qhp.Qt3DLogic.customFilters.Qt.name = Qt3DLogic $QT_VERSION
+qhp.Qt3DLogic.customFilters.Qt.filterAttributes = qt3dlogic $QT_VERSION
+
+qhp.Qt3DLogic.subprojects = classes qmltypes
+
+qhp.Qt3DLogic.subprojects.classes.title = C++ Classes
+qhp.Qt3DLogic.subprojects.classes.indexTitle = Qt3D Logic C++ Classes
+qhp.Qt3DLogic.subprojects.classes.selectors = class fake:headerfile
+qhp.Qt3DLogic.subprojects.classes.sortPages = true
+
+qhp.Qt3DLogic.subprojects.qmltypes.title = QML Types
+qhp.Qt3DLogic.subprojects.qmltypes.indexTitle = Qt3D Logic QML Types
+qhp.Qt3DLogic.subprojects.qmltypes.selectors = qmlclass
+qhp.Qt3DLogic.subprojects.qmltypes.sortPages = true
+
+tagfile = ../../../doc/qt3dlogic/qt3dlogic.tags
+
+depends += qtcore qtqml qtquick qtdoc qt3drenderer
+
+headerdirs += .. \
+ ../../plugins \
+ ../../quick3d/quick3d \
+ ../../input
+
+sourcedirs += .. \
+ ../../plugins \
+ ../../quick3d/quick3d \
+ ../../input
+
+exampledirs += src/snippets
+
+#excludedirs +=
+
+imagedirs += images \
+ ../../../examples/qt3d/shadow-map-qml/doc/images
+
+Cpp.ignoretokens += QT3DLOGIC_PRIVATE_EXPORT \
+ QT3DINPUTSHARED_EXPORT \
+ QT3DLOGICSHARED_EXPORT
+
+Cpp.ignoredirectives += Q_DECLARE_LOGGING_CATEGORY
+
+navigation.landingpage = "Qt3D Module"
+navigation.cppclassespage = "Qt3D Logic C++ Classes"
+navigation.qmltypespage = "Qt3D Logic QML Types"
diff --git a/src/logic/handle_types_p.h b/src/logic/handle_types_p.h
new file mode 100644
index 000000000..dd5732201
--- /dev/null
+++ b/src/logic/handle_types_p.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_LOGIC_HANDLE_TYPES_P_H
+#define QT3D_LOGIC_HANDLE_TYPES_P_H
+
+#include <Qt3DCore/qhandle.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Logic {
+
+class LogicHandler;
+
+typedef QHandle<LogicHandler, 16> HLogicHandler;
+
+} // Logic
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_LOGIC_HANDLE_TYPES_P_H
+
diff --git a/src/logic/logic.pri b/src/logic/logic.pri
new file mode 100644
index 000000000..3d2e4aeeb
--- /dev/null
+++ b/src/logic/logic.pri
@@ -0,0 +1,22 @@
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/qt3dlogic_global.h \
+ $$PWD/qlogicaspect.h \
+ $$PWD/qlogicaspect_p.h \
+ $$PWD/qlogiccomponent.h \
+ $$PWD/handle_types_p.h \
+ $$PWD/logicmanagers_p.h \
+ $$PWD/logichandler_p.h \
+ $$PWD/logicmanager_p.h \
+ $$PWD/qlogiccomponent_p.h \
+ $$PWD/logiccallbackjob_p.h \
+ $$PWD/logicexecutor_p.h
+
+SOURCES += \
+ $$PWD/qlogicaspect.cpp \
+ $$PWD/qlogiccomponent.cpp \
+ $$PWD/logichandler.cpp \
+ $$PWD/logicmanager.cpp \
+ $$PWD/logiccallbackjob.cpp \
+ $$PWD/logicexecutor.cpp
diff --git a/src/logic/logic.pro b/src/logic/logic.pro
new file mode 100644
index 000000000..0c140793b
--- /dev/null
+++ b/src/logic/logic.pro
@@ -0,0 +1,20 @@
+TARGET = Qt3DLogic
+MODULE = 3dlogic
+QT = core-private gui-private 3dcore 3dcore-private
+
+load(qt_module)
+
+DEFINES += QT3DLOGIC_LIBRARY
+
+QMAKE_DOCS = $$PWD/doc/qt3dlogic.qdocconf
+
+gcov {
+ CONFIG += static
+ QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage
+ QMAKE_LFLAGS += -fprofile-arcs -ftest-coverage
+}
+
+# otherwise mingw headers do not declare common functions like ::strcasecmp
+win32-g++*:QMAKE_CXXFLAGS_CXX11 = -std=gnu++0x
+
+include(logic.pri)
diff --git a/src/logic/logiccallbackjob.cpp b/src/logic/logiccallbackjob.cpp
new file mode 100644
index 000000000..ef16f2a8d
--- /dev/null
+++ b/src/logic/logiccallbackjob.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "logiccallbackjob_p.h"
+#include "logicmanager_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Logic {
+
+LogicCallbackJob::LogicCallbackJob()
+ : QAspectJob()
+ , m_logicManager(Q_NULLPTR)
+{
+}
+
+void LogicCallbackJob::setLogicManager(LogicManager *manager)
+{
+ m_logicManager = manager;
+}
+
+void LogicCallbackJob::run()
+{
+ Q_ASSERT(m_logicManager);
+ m_logicManager->triggerLogicFrameUpdates();
+}
+
+} // Logic
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/logic/logiccallbackjob_p.h b/src/logic/logiccallbackjob_p.h
new file mode 100644
index 000000000..7c6a38fe4
--- /dev/null
+++ b/src/logic/logiccallbackjob_p.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_LOGIC_LOGICCALLBACKJOB_P_H
+#define QT3D_LOGIC_LOGICCALLBACKJOB_P_H
+
+#include <Qt3DCore/qaspectjob.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Logic {
+
+class LogicManager;
+
+class LogicCallbackJob : public QAspectJob
+{
+public:
+ LogicCallbackJob();
+ void setLogicManager(LogicManager *manager);
+
+ void run() Q_DECL_OVERRIDE;
+
+private:
+ LogicManager *m_logicManager;
+};
+
+} // Logic
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_LOGIC_LOGICCALLBACKJOB_P_H
diff --git a/src/logic/logicexecutor.cpp b/src/logic/logicexecutor.cpp
new file mode 100644
index 000000000..d3a821f32
--- /dev/null
+++ b/src/logic/logicexecutor.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "logicexecutor_p.h"
+#include <Qt3DLogic/qlogiccomponent.h>
+#include <Qt3DCore/qnode.h>
+#include <Qt3DCore/private/qscene_p.h>
+#include <QtCore/qsemaphore.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Logic {
+
+LogicExecutor::LogicExecutor(QObject *parent)
+ : QObject(parent)
+ , m_scene(Q_NULLPTR)
+{
+}
+
+void LogicExecutor::clearQueueAndProceed()
+{
+ // Clear the queue of nodes to process frame updates for (throw the work away).
+ // If the semaphore is acquired, release it to allow the logic job and hence the
+ // manager and frame to complete and shutdown to continue.
+ m_nodeIds.clear();
+ if (m_semaphore->available() == 0)
+ m_semaphore->release();
+}
+
+void LogicExecutor::enqueueLogicFrameUpdates(const QVector<QNodeId> &nodeIds)
+{
+ m_nodeIds = nodeIds;
+}
+
+bool LogicExecutor::event(QEvent *e)
+{
+ if (e->type() == QEvent::User) {
+ processLogicFrameUpdates();
+ e->setAccepted(true);
+ return true;
+ }
+ return false;
+}
+
+/*!
+ \internal
+
+ Called from context of main thread
+*/
+void LogicExecutor::processLogicFrameUpdates()
+{
+ Q_ASSERT(m_scene);
+ Q_ASSERT(m_semaphore);
+ QVector<QNode *> nodes = m_scene->lookupNodes(m_nodeIds);
+ foreach (QNode *node, nodes) {
+ QLogicComponent *logicComponent = qobject_cast<QLogicComponent *>(node);
+ if (logicComponent)
+ logicComponent->onFrameUpdate();
+ }
+
+ // Release the semaphore so the calling LogicManager can continue
+ m_semaphore->release();
+}
+
+} // Logic
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/logic/logicexecutor_p.h b/src/logic/logicexecutor_p.h
new file mode 100644
index 000000000..83eb1d7bc
--- /dev/null
+++ b/src/logic/logicexecutor_p.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_LOGIC_LOGICEXECUTOR_P_H
+#define QT3D_LOGIC_LOGICEXECUTOR_P_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qcoreevent.h>
+#include <Qt3DCore/qnodeid.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSemaphore;
+
+namespace Qt3D {
+
+class QScene;
+
+namespace Logic {
+
+class FrameUpdateEvent : public QEvent
+{
+public:
+ FrameUpdateEvent()
+ : QEvent(QEvent::User)
+ {}
+};
+
+class LogicExecutor : public QObject
+{
+ Q_OBJECT
+public:
+ explicit LogicExecutor(QObject *parent = 0);
+
+ void setScene(QScene *scene) { m_scene = scene; }
+ void setSemephore(QSemaphore *semaphore) { m_semaphore = semaphore; }
+ void clearQueueAndProceed();
+
+public Q_SLOTS:
+ void enqueueLogicFrameUpdates(const QVector<QNodeId> &nodeIds);
+
+protected:
+ bool event(QEvent *e);
+ void processLogicFrameUpdates();
+
+private:
+ QVector<QNodeId> m_nodeIds;
+ QScene *m_scene;
+ QSemaphore *m_semaphore;
+};
+
+} // Logic
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_LOGIC_LOGICEXECUTOR_P_H
diff --git a/src/logic/logichandler.cpp b/src/logic/logichandler.cpp
new file mode 100644
index 000000000..f10f52578
--- /dev/null
+++ b/src/logic/logichandler.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "logichandler_p.h"
+#include "logicmanager_p.h"
+#include "logicmanagers_p.h"
+#include <Qt3DCore/qnode.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Logic {
+
+LogicHandler::LogicHandler()
+ : m_logicManager(Q_NULLPTR)
+{
+}
+
+void LogicHandler::updateFromPeer(QNode *peer)
+{
+ Q_UNUSED(peer);
+}
+
+void LogicHandler::sceneChangeEvent(const QSceneChangePtr &e)
+{
+ Q_UNUSED(e);
+}
+
+LogicHandlerFunctor::LogicHandlerFunctor(LogicManager *manager)
+ : m_manager(manager)
+{
+}
+
+QBackendNode *LogicHandlerFunctor::create(QNode *frontend, const QBackendNodeFactory *factory) const
+{
+ LogicHandler *handler = m_manager->logicHandlerManager()->getOrCreateResource(frontend->id());
+ handler->setFactory(factory);
+ handler->setLogicManager(m_manager);
+ handler->setPeer(frontend);
+ m_manager->appendLogicHandler(handler);
+ return handler;
+}
+
+QBackendNode *LogicHandlerFunctor::get(const QNodeId &id) const
+{
+ return m_manager->logicHandlerManager()->lookupResource(id);
+}
+
+void LogicHandlerFunctor::destroy(const QNodeId &id) const
+{
+ m_manager->removeLogicHandler(id);
+}
+
+} // Logic
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/logic/logichandler_p.h b/src/logic/logichandler_p.h
new file mode 100644
index 000000000..831be20d6
--- /dev/null
+++ b/src/logic/logichandler_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_LOGICHANDLER_H
+#define QT3D_LOGICHANDLER_H
+
+#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DCore/qnodeid.h>
+#include <Qt3DCore/qaspectjob.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Logic {
+
+class LogicManager;
+
+class LogicHandler : public QBackendNode
+{
+public:
+ LogicHandler();
+
+ void updateFromPeer(QNode *peer) Q_DECL_OVERRIDE;
+
+ void setLogicManager(LogicManager *manager) { m_logicManager = manager; }
+ LogicManager *logicManager() const { return m_logicManager; }
+
+protected:
+ void sceneChangeEvent(const QSceneChangePtr &e) Q_DECL_OVERRIDE;
+
+private:
+ LogicManager *m_logicManager;
+};
+
+
+class LogicHandlerFunctor : public QBackendNodeFunctor
+{
+public:
+ explicit LogicHandlerFunctor(LogicManager *handler);
+
+ QBackendNode *create(QNode *frontend, const QBackendNodeFactory *factory) const Q_DECL_OVERRIDE;
+ QBackendNode *get(const QNodeId &id) const Q_DECL_OVERRIDE;
+ void destroy(const QNodeId &id) const Q_DECL_OVERRIDE;
+
+private:
+ LogicManager *m_manager;
+};
+
+} // Logic
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_LOGICHANDLER_H
diff --git a/src/logic/logicmanager.cpp b/src/logic/logicmanager.cpp
new file mode 100644
index 000000000..eb34b33a8
--- /dev/null
+++ b/src/logic/logicmanager.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "logicmanager_p.h"
+#include "qlogicaspect.h"
+#include <Qt3DLogic/private/logicexecutor_p.h>
+#include <Qt3DLogic/private/logicmanagers_p.h>
+#include <QtCore/qcoreapplication.h>
+
+#include <QDebug>
+#include <QThread>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Logic {
+
+LogicManager::LogicManager()
+ : m_logicHandlerManager(new LogicHandlerManager)
+ , m_semaphore(1)
+{
+ m_semaphore.acquire();
+}
+
+LogicManager::~LogicManager()
+{
+}
+
+void LogicManager::setExecutor(LogicExecutor *executor)
+{
+ m_executor = executor;
+ if (m_executor)
+ m_executor->setSemephore(&m_semaphore);
+}
+
+void LogicManager::appendLogicHandler(LogicHandler *handler)
+{
+ HLogicHandler handle = m_logicHandlerManager->lookupHandle(handler->peerUuid());
+ m_logicHandlers.append(handle);
+ m_logicComponentIds.append(handler->peerUuid());
+}
+
+void LogicManager::removeLogicHandler(const QNodeId &id)
+{
+ HLogicHandler handle = m_logicHandlerManager->lookupHandle(id);
+ m_logicComponentIds.removeAll(id);
+ m_logicHandlers.removeAll(handle);
+ m_logicHandlerManager->releaseResource(id);
+}
+
+void LogicManager::triggerLogicFrameUpdates()
+{
+ Q_ASSERT(m_executor);
+
+ // Don't use blocking queued connections to main thread if it is already
+ // in the process of shutting down as that will deadlock.
+ if (m_logicAspect->isShuttingDown())
+ return;
+
+ // Trigger the main thread to process logic frame updates for each
+ // logic component and then wait until done. The LogicExecutor will
+ // release the semaphore when it has completed its work.
+ m_executor->enqueueLogicFrameUpdates(m_logicComponentIds);
+ qApp->postEvent(m_executor, new FrameUpdateEvent);
+ m_semaphore.acquire();
+}
+
+} // Logic
+
+} // namespace Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/logic/logicmanager_p.h b/src/logic/logicmanager_p.h
new file mode 100644
index 000000000..332b36903
--- /dev/null
+++ b/src/logic/logicmanager_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_LOGIC_LOGICMANAGER_H
+#define QT3D_LOGIC_LOGICMANAGER_H
+
+#include <Qt3DLogic/qt3dlogic_global.h>
+#include <Qt3DLogic/private/handle_types_p.h>
+#include <Qt3DCore/qnodeid.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qscopedpointer.h>
+#include <QtCore/qsemaphore.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QLogicAspect;
+
+namespace Logic {
+
+class LogicExecutor;
+class LogicHandlerManager;
+
+class LogicManager
+{
+public:
+ LogicManager();
+ ~LogicManager();
+
+ void setLogicAspect(QLogicAspect *logicAspect) { m_logicAspect = logicAspect; }
+ void setExecutor(LogicExecutor *executor);
+
+ LogicHandlerManager *logicHandlerManager() const { return m_logicHandlerManager.data(); }
+
+ void appendLogicHandler(LogicHandler *handler);
+ void removeLogicHandler(const QNodeId &id);
+
+ void triggerLogicFrameUpdates();
+
+private:
+ QScopedPointer<LogicHandlerManager> m_logicHandlerManager;
+ QVector<HLogicHandler> m_logicHandlers;
+ QVector<QNodeId> m_logicComponentIds;
+ QLogicAspect *m_logicAspect;
+ LogicExecutor *m_executor;
+ QSemaphore m_semaphore;
+};
+
+} // Logic
+
+} // namespace Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_LOGIC_LOGICMANAGER_H
diff --git a/src/logic/logicmanagers_p.h b/src/logic/logicmanagers_p.h
new file mode 100644
index 000000000..d3cb2e10d
--- /dev/null
+++ b/src/logic/logicmanagers_p.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_LOGIC_LOGICMANAGERS_P_H
+#define QT3D_LOGIC_LOGICMANAGERS_P_H
+
+#include <QtGlobal>
+#include <Qt3DLogic/private/handle_types_p.h>
+#include <Qt3DLogic/private/logichandler_p.h>
+#include <Qt3DCore/private/qresourcemanager_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Logic {
+
+class LogicHandlerManager : public QResourceManager<
+ LogicHandler,
+ QNodeId,
+ 16,
+ Qt3D::ArrayAllocatingPolicy>
+{
+public:
+ LogicHandlerManager() {}
+};
+
+} // Logic
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_LOGIC_LOGICMANAGERS_P_H
+
diff --git a/src/logic/qlogicaspect.cpp b/src/logic/qlogicaspect.cpp
new file mode 100644
index 000000000..709380319
--- /dev/null
+++ b/src/logic/qlogicaspect.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlogicaspect.h"
+#include "qlogicaspect_p.h"
+#include "logicexecutor_p.h"
+#include "logichandler_p.h"
+#include "logicmanager_p.h"
+#include "qlogiccomponent.h"
+
+#include <Qt3DCore/qnodevisitor.h>
+#include <Qt3DCore/qscenepropertychange.h>
+
+#include <Qt3DCore/qnode.h>
+#include <Qt3DCore/private/qaspectmanager_p.h>
+#include <Qt3DCore/private/qchangearbiter_p.h>
+#include <Qt3DCore/private/qscene_p.h>
+#include <Qt3DCore/qaspectfactory.h>
+#include <Qt3DCore/qservicelocator.h>
+
+#include <QThread>
+#include <QWindow>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+/*!
+ \class Qt3D::QLogicAspectPrivate
+ \internal
+*/
+QLogicAspectPrivate::QLogicAspectPrivate()
+ : QAbstractAspectPrivate()
+ , m_time(0)
+ , m_initialized(false)
+ , m_manager(new Logic::LogicManager)
+ , m_executor(new Logic::LogicExecutor)
+ , m_callbackJob(new Logic::LogicCallbackJob)
+{
+ m_aspectType = QAbstractAspect::AspectOther;
+ m_callbackJob->setLogicManager(m_manager.data());
+ m_manager->setExecutor(m_executor.data());
+}
+
+QLogicAspect::QLogicAspect(QObject *parent)
+ : QAbstractAspect(*new QLogicAspectPrivate(), parent)
+{
+ registerBackendTypes();
+ d_func()->m_manager->setLogicAspect(this);
+}
+
+/*! \internal */
+QLogicAspect::QLogicAspect(QLogicAspectPrivate &dd, QObject *parent)
+ : QAbstractAspect(dd, parent)
+{
+ registerBackendTypes();
+ d_func()->m_manager->setLogicAspect(this);
+}
+
+void QLogicAspect::registerBackendTypes()
+{
+ registerBackendType<QLogicComponent>(QBackendNodeFunctorPtr(new Logic::LogicHandlerFunctor(d_func()->m_manager.data())));
+}
+
+QVector<QAspectJobPtr> QLogicAspect::jobsToExecute(qint64 time)
+{
+ Q_D(QLogicAspect);
+ d->m_time = time;
+ // TODO: Ensure arbiter and postman are setup prior to invoking QAspectManager::initialize()
+
+ // Create jobs that will get exectued by the threadpool
+ QVector<QAspectJobPtr> jobs;
+ jobs.append(d->m_callbackJob);
+ return jobs;
+}
+
+void QLogicAspect::sceneNodeAdded(QSceneChangePtr &e)
+{
+ QScenePropertyChangePtr propertyChange = e.staticCast<QScenePropertyChange>();
+ QNodePtr nodePtr = propertyChange->value().value<QNodePtr>();
+ QNode *n = nodePtr.data();
+ QNodeVisitor visitor;
+ visitor.traverse(n, this, &QLogicAspect::visitNode);
+}
+
+void QLogicAspect::sceneNodeRemoved(QSceneChangePtr &e)
+{
+ QScenePropertyChangePtr propertyChange = e.staticCast<QScenePropertyChange>();
+ QNodePtr nodePtr = propertyChange->value().value<QNodePtr>();
+ QNode *n = nodePtr.data();
+ QAbstractAspect::clearBackendNode(n);
+}
+
+void QLogicAspect::setRootEntity(QEntity *rootObject)
+{
+ QNodeVisitor visitor;
+ visitor.traverse(rootObject, this, &QLogicAspect::visitNode);
+}
+
+void QLogicAspect::onInitialize(const QVariantMap &data)
+{
+ Q_UNUSED(data);
+}
+
+void QLogicAspect::onCleanup()
+{
+}
+
+void QLogicAspect::onStartup()
+{
+ Q_D(QLogicAspect);
+ d->m_executor->setScene(d->m_arbiter->scene());
+}
+
+void QLogicAspect::onShutdown()
+{
+ Q_D(QLogicAspect);
+ // Throw away any pending work that may deadlock during the shutdown procedure
+ // when the main thread waits for any queued jobs to finish.
+ d->m_executor->clearQueueAndProceed();
+}
+
+void QLogicAspect::visitNode(QNode *node)
+{
+ QAbstractAspect::createBackendNode(node);
+}
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+QT3D_REGISTER_NAMESPACED_ASPECT("logic", QT_PREPEND_NAMESPACE(Qt3D), QLogicAspect)
+
diff --git a/src/logic/qlogicaspect.h b/src/logic/qlogicaspect.h
new file mode 100644
index 000000000..fdc52cd09
--- /dev/null
+++ b/src/logic/qlogicaspect.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_QLOGICASPECT_H
+#define QT3D_QLOGICASPECT_H
+
+#include <Qt3DLogic/qt3dlogic_global.h>
+#include <Qt3DCore/qabstractaspect.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QLogicAspectPrivate;
+
+class QT3DLOGICSHARED_EXPORT QLogicAspect : public QAbstractAspect
+{
+ Q_OBJECT
+public:
+ explicit QLogicAspect(QObject *parent = 0);
+
+ QVector<QAspectJobPtr> jobsToExecute(qint64 time) Q_DECL_OVERRIDE;
+
+ void sceneNodeAdded(QSceneChangePtr &e) Q_DECL_OVERRIDE;
+ void sceneNodeRemoved(QSceneChangePtr &e) Q_DECL_OVERRIDE;
+
+protected:
+ void registerBackendTypes();
+
+private:
+ void setRootEntity(QEntity *rootObject) Q_DECL_OVERRIDE;
+ void onInitialize(const QVariantMap &data) Q_DECL_OVERRIDE;
+ void onStartup() Q_DECL_OVERRIDE;
+ void onShutdown() Q_DECL_OVERRIDE;
+ void onCleanup() Q_DECL_OVERRIDE;
+
+ void visitNode(QNode *node);
+
+ Q_DECLARE_PRIVATE(QLogicAspect)
+ QLogicAspect(QLogicAspectPrivate &dd, QObject *parent);
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QLOGICASPECT_H
+
diff --git a/src/logic/qlogicaspect_p.h b/src/logic/qlogicaspect_p.h
new file mode 100644
index 000000000..67376f751
--- /dev/null
+++ b/src/logic/qlogicaspect_p.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_LOGIC_QLOGICASPECT_P_H
+#define QT3D_LOGIC_QLOGICASPECT_P_H
+
+#include <Qt3DCore/private/qabstractaspect_p.h>
+#include <Qt3DLogic/private/logiccallbackjob_p.h>
+#include <QtCore/qsharedpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Logic {
+class LogicExecutor;
+class LogicManager;
+}
+
+class QLogicAspectPrivate : public QAbstractAspectPrivate
+{
+ QLogicAspectPrivate();
+
+ Q_DECLARE_PUBLIC(QLogicAspect)
+
+ qint64 m_time;
+ bool m_initialized;
+ QScopedPointer<Logic::LogicManager> m_manager;
+ QScopedPointer<Logic::LogicExecutor> m_executor;
+ QSharedPointer<Logic::LogicCallbackJob> m_callbackJob;
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif // QT3D_LOGIC_QLOGICASPECT_P_H
+
diff --git a/src/logic/qlogiccomponent.cpp b/src/logic/qlogiccomponent.cpp
new file mode 100644
index 000000000..c2da1a7b0
--- /dev/null
+++ b/src/logic/qlogiccomponent.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlogiccomponent.h"
+#include "qlogiccomponent_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+/*!
+ \class Qt3D::QLogicComponentPrivate
+ \internal
+*/
+QLogicComponentPrivate::QLogicComponentPrivate()
+ : QComponentPrivate()
+{
+}
+
+/*!
+ \class Qt3D::QLogicComponent
+ \inmodule Qt3DLogic
+ \since 5.5
+ \brief Provides a way to have a synchronous function executed each frame.
+
+ The QLogicComponent provides a way to perform tasks each frame in
+ synchronized with the Qt3D backend. This is useful to implement some
+ aspects of application logic and to prototype functionality that can later
+ be folded into an additional Qt3D aspect.
+
+ For example, the QLogicComponent can be used to animate a property in sync
+ with the Qt3D engine where a Qt Quick animation element is not perfectly
+ synchronized and may lead to stutters in some cases.
+
+ To execute your own code each frame override the onFrameUpdate function.
+*/
+
+/*!
+ \qmltype LogicComponent
+ \inqmlmodule Qt3D.Logic
+ \instantiates Qt3D::QLogicComponent
+ \inherits Component3D
+ \since 5.5
+*/
+
+/*!
+ Constructs a new QLogicComponent instance with parent \a parent.
+ */
+QLogicComponent::QLogicComponent(QNode *parent)
+ : QComponent(*new QLogicComponentPrivate, parent)
+{
+}
+
+/*! \internal */
+QLogicComponent::QLogicComponent(QLogicComponentPrivate &dd, QNode *parent)
+ : QComponent(dd, parent)
+{
+}
+
+QLogicComponent::~QLogicComponent()
+{
+ QNode::cleanup();
+}
+
+/*!
+ This virtual function will be called in a synchronous manner once each frame by
+ the Logic aspect.
+*/
+void QLogicComponent::onFrameUpdate()
+{
+ // Emit signal so that QML instances get the onFrameUpdate() signal
+ // handler called
+ emit frameUpdate();
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/logic/qlogiccomponent.h b/src/logic/qlogiccomponent.h
new file mode 100644
index 000000000..417e12e40
--- /dev/null
+++ b/src/logic/qlogiccomponent.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_QLOGICCOMPONENT_H
+#define QT3D_QLOGICCOMPONENT_H
+
+#include <Qt3DCore/qcomponent.h>
+#include <Qt3DLogic/qt3dlogic_global.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QLogicAspect;
+class QLogicComponentPrivate;
+
+namespace Logic {
+class LogicExecutor;
+}
+
+class QT3DLOGICSHARED_EXPORT QLogicComponent : public QComponent
+{
+ Q_OBJECT
+
+public:
+ explicit QLogicComponent(QNode *parent = 0);
+ ~QLogicComponent();
+
+protected:
+ QLogicComponent(QLogicComponentPrivate &dd, QNode *parent = 0);
+
+Q_SIGNALS:
+ void frameUpdate();
+
+private:
+ Q_DECLARE_PRIVATE(QLogicComponent)
+ QT3D_CLONEABLE(QLogicComponent)
+
+ virtual void onFrameUpdate();
+
+ friend class Logic::LogicExecutor;
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QLOGICCOMPONENT_H
diff --git a/src/logic/qlogiccomponent_p.h b/src/logic/qlogiccomponent_p.h
new file mode 100644
index 000000000..4319af030
--- /dev/null
+++ b/src/logic/qlogiccomponent_p.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_LOGIC_QLOGICCOMPONENT_P_H
+#define QT3D_LOGIC_QLOGICCOMPONENT_P_H
+
+#include <private/qcomponent_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QLogicComponent;
+
+class QLogicComponentPrivate : public QComponentPrivate
+{
+public:
+ QLogicComponentPrivate();
+
+ Q_DECLARE_PUBLIC(QLogicComponent)
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_LOGIC_QLOGICCOMPONENT_P_H
diff --git a/src/logic/qt3dlogic_global.h b/src/logic/qt3dlogic_global.h
new file mode 100644
index 000000000..0b292e3b0
--- /dev/null
+++ b/src/logic/qt3dlogic_global.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DLOGIC_GLOBAL_H
+#define QT3DLOGIC_GLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+#if defined(QT_SHARED) || !defined(QT_STATIC)
+# if defined(QT3DLOGIC_LIBRARY)
+# define QT3DLOGICSHARED_EXPORT Q_DECL_EXPORT
+# else
+# define QT3DLOGICSHARED_EXPORT Q_DECL_IMPORT
+# endif
+#else
+# define QT3DLOGICSHARED_EXPORT
+#endif
+
+QT_END_NAMESPACE
+
+#endif // QT3DLOGIC_GLOBAL_H