diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-11-30 18:33:15 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2015-11-30 21:34:56 +0000 |
commit | aff48c883938ffbb321eff1fb5886955143ee312 (patch) | |
tree | 7e5564b25ced35d05ba58cbf1d038fe1cdb2b2dd /src/input | |
parent | e45f5f30ca0e70e9022003f9f04cb65f8bd7456c (diff) |
QInputAspect: launch an axis/action update frame
Change-Id: I78038ed7a559647db87be800a8fe2d080da3620c
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/backend/backend.pri | 6 | ||||
-rw-r--r-- | src/input/backend/inputhandler.cpp | 10 | ||||
-rw-r--r-- | src/input/backend/inputhandler_p.h | 7 | ||||
-rw-r--r-- | src/input/backend/updateaxisactionjob.cpp | 145 | ||||
-rw-r--r-- | src/input/backend/updateaxisactionjob_p.h | 84 | ||||
-rw-r--r-- | src/input/frontend/qinputaspect.cpp | 19 | ||||
-rw-r--r-- | src/input/frontend/qinputaspect_p.h | 2 |
7 files changed, 265 insertions, 8 deletions
diff --git a/src/input/backend/backend.pri b/src/input/backend/backend.pri index c942a911b..033754a33 100644 --- a/src/input/backend/backend.pri +++ b/src/input/backend/backend.pri @@ -21,7 +21,8 @@ HEADERS += \ $$PWD/qabstractphysicaldevicebackendnode.h \ $$PWD/movingaverage_p.h \ $$PWD/axissetting_p.h \ - $$PWD/qabstractphysicaldevicebackendnode_p.h + $$PWD/qabstractphysicaldevicebackendnode_p.h \ + $$PWD/updateaxisactionjob_p.h SOURCES += \ $$PWD/cameracontroller.cpp \ @@ -42,6 +43,7 @@ SOURCES += \ $$PWD/logicaldevice.cpp \ $$PWD/qabstractphysicaldevicebackendnode.cpp \ $$PWD/movingaverage.cpp \ - $$PWD/axissetting.cpp + $$PWD/axissetting.cpp \ + $$PWD/updateaxisactionjob.cpp INCLUDEPATH += $$PWD diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp index 32ce3af67..8797315b2 100644 --- a/src/input/backend/inputhandler.cpp +++ b/src/input/backend/inputhandler.cpp @@ -194,6 +194,16 @@ QVector<Qt3DCore::QAspectJobPtr> InputHandler::mouseJobs() return jobs; } +QVector<QInputDeviceIntegration *> InputHandler::inputDeviceIntegrations() const +{ + return m_inputDeviceIntegrations; +} + +void InputHandler::addInputDeviceIntegration(QInputDeviceIntegration *inputIntegration) +{ + m_inputDeviceIntegrations.push_back(inputIntegration); +} + } // namespace Input } // namespace Qt3DInput diff --git a/src/input/backend/inputhandler_p.h b/src/input/backend/inputhandler_p.h index 1c61bfce4..085597971 100644 --- a/src/input/backend/inputhandler_p.h +++ b/src/input/backend/inputhandler_p.h @@ -61,6 +61,9 @@ class QEventFilterService; } namespace Qt3DInput { + +class QInputDeviceIntegration; + namespace Input { class KeyboardInputManager; @@ -111,6 +114,9 @@ public: QVector<Qt3DCore::QAspectJobPtr> keyboardJobs(); QVector<Qt3DCore::QAspectJobPtr> mouseJobs(); + QVector<Qt3DInput::QInputDeviceIntegration *> inputDeviceIntegrations() const; + void addInputDeviceIntegration(QInputDeviceIntegration *inputIntegration); + private: KeyboardControllerManager *m_keyboardControllerManager; KeyboardInputManager *m_keyboardInputManager; @@ -131,6 +137,7 @@ private: AxisSettingManager *m_axisSettingManager; ActionInputManager *m_actionInputManager; LogicalDeviceManager *m_logicalDeviceManager; + QVector<Qt3DInput::QInputDeviceIntegration *> m_inputDeviceIntegrations; }; } // namespace Input diff --git a/src/input/backend/updateaxisactionjob.cpp b/src/input/backend/updateaxisactionjob.cpp new file mode 100644 index 000000000..9270a1df7 --- /dev/null +++ b/src/input/backend/updateaxisactionjob.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** 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 "updateaxisactionjob_p.h" +#include <Qt3DInput/private/inputhandler_p.h> +#include <Qt3DInput/private/inputmanagers_p.h> +#include <Qt3DInput/qabstractphysicaldevicebackendnode.h> +#include <Qt3DInput/qinputdeviceintegration.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DInput { + +namespace Input { + +namespace { + +bool anyOfRequiredKeysPressed(qint64 keys, QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend) +{ + bool validKeyWasPressed = false; + for (int i = 0; i < 64; ++i) { + const int individualBit = (1 << i); + if ((individualBit & keys) && physicalDeviceBackend->isButtonPressed(individualBit)) + validKeyWasPressed = true; + break; + } + return validKeyWasPressed; +} + +} // anonymous + +UpdateAxisActionJob::UpdateAxisActionJob(InputHandler *handler, HLogicalDevice handle) + : Qt3DCore::QAspectJob() + , m_handler(handler) + , m_handle(handle) +{ +} + +void UpdateAxisActionJob::run() +{ + // Note: we assume axis/action are not really shared: + // there's no benefit in sharing those when it comes to computing + LogicalDevice *device = m_handler->logicalDeviceManager()->data(m_handle); + updateAction(device); + updateAxis(device); +} + +void UpdateAxisActionJob::updateAction(LogicalDevice *device) +{ + Q_FOREACH (const Qt3DCore::QNodeId actionId, device->actions()) { + bool actionTriggered = false; + Action *action = m_handler->actionManager()->lookupResource(actionId); + + Q_FOREACH (const Qt3DCore::QNodeId actionInputId, action->inputs()) { + ActionInput *actionInput = m_handler->actionInputManager()->lookupResource(actionInputId); + QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = Q_NULLPTR; + + Q_FOREACH (QInputDeviceIntegration *integration, m_handler->inputDeviceIntegrations()) { + if ((physicalDeviceBackend = integration->physicalDevice(actionInput->sourceDevice())) != Q_NULLPTR) + break; + } + + if (physicalDeviceBackend != Q_NULLPTR) { + // Update the value + actionTriggered |= anyOfRequiredKeysPressed(actionInput->keys(), physicalDeviceBackend); + } + } + + action->setActionTriggered(actionTriggered); + } +} + +void UpdateAxisActionJob::updateAxis(LogicalDevice *device) +{ + Q_FOREACH (const Qt3DCore::QNodeId axisId, device->axes()) { + Axis *axis = m_handler->axisManager()->lookupResource(axisId); + float axisValue = 0.0f; + + Q_FOREACH (const Qt3DCore::QNodeId axisInputId, axis->inputs()) { + AxisInput *axisInput = m_handler->axisInputManager()->lookupResource(axisInputId); + QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = Q_NULLPTR; + + Q_FOREACH (QInputDeviceIntegration *integration, m_handler->inputDeviceIntegrations()) { + if ((physicalDeviceBackend = integration->physicalDevice(axisInput->sourceDevice())) != Q_NULLPTR) + break; + } + + if (physicalDeviceBackend != Q_NULLPTR) { + // Update the value + const qint64 keys = axisInput->keys(); + // Axis was specified -> we take this as the base value + if (axisInput->axis() != -1) + axisValue += physicalDeviceBackend->axisValue(axisInput->axis()); + else if (keys != 0) { + // TO DO: Linear Curver for the progression of the scale value + if (anyOfRequiredKeysPressed(keys, physicalDeviceBackend)) + axisValue += axisInput->scale(); + } + } + } + + // Clamp the axisValue -1/1 + axisValue = qMin(1.0f, qMax(axisValue, -1.0f)); + axis->setAxisValue(axisValue); + } +} + +} // Input + +} // Qt3DInput + +QT_END_NAMESPACE diff --git a/src/input/backend/updateaxisactionjob_p.h b/src/input/backend/updateaxisactionjob_p.h new file mode 100644 index 000000000..7d2aa5ec6 --- /dev/null +++ b/src/input/backend/updateaxisactionjob_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 QT3DINPUT_INPUT_UPDATEAXISACTIONJOB_H +#define QT3DINPUT_INPUT_UPDATEAXISACTIONJOB_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DCore/qaspectjob.h> +#include <Qt3DInput/private/handle_types_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DInput { + +namespace Input { + +class InputHandler; + +class UpdateAxisActionJob : public Qt3DCore::QAspectJob +{ +public: + explicit UpdateAxisActionJob(InputHandler *handler, HLogicalDevice handle); + void run() Q_DECL_FINAL; + +private: + void updateAction(LogicalDevice *device); + void updateAxis(LogicalDevice *device); + + InputHandler *m_handler; + HLogicalDevice m_handle; +}; + +typedef QScopedPointer<UpdateAxisActionJob> UpdateAxisActionJobPtr; + +} // Input + +} // Qt3DInput + +QT_END_NAMESPACE + +#endif // QT3DINPUT_INPUT_UPDATEAXISACTIONJOB_H diff --git a/src/input/frontend/qinputaspect.cpp b/src/input/frontend/qinputaspect.cpp index b9277774d..dd214c163 100644 --- a/src/input/frontend/qinputaspect.cpp +++ b/src/input/frontend/qinputaspect.cpp @@ -73,6 +73,7 @@ #include <Qt3DInput/private/logicaldevice_p.h> #include <Qt3DInput/private/inputbackendnodefunctor_p.h> #include <Qt3DInput/private/inputmanagers_p.h> +#include <Qt3DInput/private/updateaxisactionjob_p.h> QT_BEGIN_NAMESPACE @@ -121,7 +122,7 @@ void QInputAspect::loadInputDevicePlugins() Q_FOREACH (QString key, keys) { Qt3DInput::QInputDeviceIntegration *integration = QInputDeviceIntegrationFactory::create(key, QStringList()); if (integration != Q_NULLPTR) { - d->m_inputDeviceIntegrations.push_back(integration); + d->m_inputHandler->addInputDeviceIntegration(integration); // Initialize will allow the InputDeviceIntegration to // register their frontend / backend types, // create their managers @@ -142,7 +143,7 @@ QAbstractPhysicalDevice *QInputAspect::createPhysicalDevice(const QString &name) { Q_D(QInputAspect); QAbstractPhysicalDevice *device = Q_NULLPTR; - Q_FOREACH (Qt3DInput::QInputDeviceIntegration *integration, d->m_inputDeviceIntegrations) { + Q_FOREACH (Qt3DInput::QInputDeviceIntegration *integration, d->m_inputHandler->inputDeviceIntegrations()) { if ((device = integration->createPhysicalDevice(name)) != Q_NULLPTR) break; } @@ -164,11 +165,21 @@ QVector<QAspectJobPtr> QInputAspect::jobsToExecute(qint64 time) jobs.append(d->m_inputHandler->keyboardJobs()); jobs.append(d->m_inputHandler->mouseJobs()); - Q_FOREACH (QInputDeviceIntegration *integration, d->m_inputDeviceIntegrations) + Q_FOREACH (QInputDeviceIntegration *integration, d->m_inputHandler->inputDeviceIntegrations()) jobs += integration->jobsToExecute(time); + // Jobs that update Axis/Action (store combined axis/action value) + QVector<QAspectJobPtr> axisActionJobs; + Q_FOREACH (Input::HLogicalDevice devHandle, d->m_inputHandler->logicalDeviceManager()->activeDevices()) { + QAspectJobPtr updateAxisActionJob(new Input::UpdateAxisActionJob(d->m_inputHandler.data(), devHandle)); + Q_FOREACH (const QAspectJobPtr job, jobs) + updateAxisActionJob->addDependency(job); + axisActionJobs.push_back(updateAxisActionJob); + } + + jobs += axisActionJobs; + // TO DO: - // Have Jobs that update Axis/Action (store combined axis/action value) // Have Jobs that update the LogicalDevice // Have Jobs that update the AxisHandlers/ActionHandlers diff --git a/src/input/frontend/qinputaspect_p.h b/src/input/frontend/qinputaspect_p.h index 6b9636ad7..f1de52144 100644 --- a/src/input/frontend/qinputaspect_p.h +++ b/src/input/frontend/qinputaspect_p.h @@ -55,7 +55,6 @@ QT_BEGIN_NAMESPACE namespace Qt3DInput { class QInputAspect; -class QInputDeviceIntegration; namespace Input { class CameraController; @@ -70,7 +69,6 @@ public: Q_DECLARE_PUBLIC(QInputAspect) QScopedPointer<Input::InputHandler> m_inputHandler; QScopedPointer<Input::CameraController> m_cameraController; - QVector<Qt3DInput::QInputDeviceIntegration *> m_inputDeviceIntegrations; }; } // namespace Qt3DInput |