summaryrefslogtreecommitdiffstats
path: root/src/input/backend/updateaxisactionjob.cpp
diff options
context:
space:
mode:
authorKevin Ottens <kevin.ottens@kdab.com>2016-10-06 20:41:53 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-10-29 11:31:21 +0000
commit7e4dc51ddbc99f3d8be5b921f49603de4f42ee60 (patch)
treefeb878e2867e4cbb88e4a675dcc0a6becc4146fd /src/input/backend/updateaxisactionjob.cpp
parentf87ff1b6c41b9edabba72942998a06cbdd81ee74 (diff)
Move all axis input logic in the relevant classes
This allows to align how we do things with a similar approach than the one we use for the action inputs. All the processing for axis inputs which was happening in UpdateAxisActionJob now happens in AnalogAxisInput and ButtonAxisInput respectively. Makes the whole thing more testable in return. Change-Id: Ib24442b9983ae1736c287cd98c99ff2c04c1f807 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input/backend/updateaxisactionjob.cpp')
-rw-r--r--src/input/backend/updateaxisactionjob.cpp71
1 files changed, 12 insertions, 59 deletions
diff --git a/src/input/backend/updateaxisactionjob.cpp b/src/input/backend/updateaxisactionjob.cpp
index bbd36228e..4e990ff0e 100644
--- a/src/input/backend/updateaxisactionjob.cpp
+++ b/src/input/backend/updateaxisactionjob.cpp
@@ -40,8 +40,6 @@
#include "updateaxisactionjob_p.h"
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
-#include <Qt3DInput/private/qabstractphysicaldevicebackendnode_p.h>
-#include <Qt3DInput/private/qinputdeviceintegration_p.h>
#include <Qt3DInput/private/job_common_p.h>
QT_BEGIN_NAMESPACE
@@ -50,22 +48,6 @@ namespace Qt3DInput {
namespace Input {
-namespace {
-
-bool anyOfRequiredButtonsPressed(const QVector<int> &buttons, QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend)
-{
- bool validButtonWasPressed = false;
- for (int button : buttons) {
- if (physicalDeviceBackend->isButtonPressed(button)) {
- validButtonWasPressed = true;
- break;
- }
- }
- return validButtonWasPressed;
-}
-
-} // anonymous
-
UpdateAxisActionJob::UpdateAxisActionJob(qint64 currentTime, InputHandler *handler, HLogicalDevice handle)
: Qt3DCore::QAspectJob()
, m_currentTime(currentTime)
@@ -118,39 +100,8 @@ void UpdateAxisActionJob::updateAxis(LogicalDevice *device)
float axisValue = 0.0f;
const auto axisInputIds = axis->inputs();
- for (const Qt3DCore::QNodeId axisInputId : axisInputIds) {
- AnalogAxisInput *analogInput = m_handler->analogAxisInputManager()->lookupResource(axisInputId);
- if (analogInput) {
- QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = findAxisInputPhysicalDevice(analogInput);
- if (physicalDeviceBackend && analogInput->axis() != -1) {
- // Update the value
- axisValue += physicalDeviceBackend->processedAxisValue(analogInput->axis());
- }
- continue;
- }
-
- ButtonAxisInput *buttonInput = m_handler->buttonAxisInputManager()->lookupResource(axisInputId);
- if (buttonInput) {
- QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = findAxisInputPhysicalDevice(buttonInput);
- if (physicalDeviceBackend != nullptr) {
- // Update the value
- const QVector<int> buttons = buttonInput ? buttonInput->buttons() : QVector<int>();
- if (!buttons.isEmpty()) {
- // TO DO: Linear Curver for the progression of the scale value
- if (anyOfRequiredButtonsPressed(buttons, physicalDeviceBackend))
- buttonInput->updateSpeedRatio(m_currentTime, ButtonAxisInput::Accelerate);
- else if (buttonInput->speedRatio() != 0.0f)
- buttonInput->updateSpeedRatio(m_currentTime, ButtonAxisInput::Decelerate);
-
- axisValue += buttonInput->speedRatio() * buttonInput->scale();
- }
- }
-
- continue;
- }
-
- Q_UNREACHABLE();
- }
+ for (const Qt3DCore::QNodeId axisInputId : axisInputIds)
+ axisValue += processAxisInput(axisInputId);
// Clamp the axisValue -1/1
axisValue = qMin(1.0f, qMax(axisValue, -1.0f));
@@ -158,16 +109,18 @@ void UpdateAxisActionJob::updateAxis(LogicalDevice *device)
}
}
-QAbstractPhysicalDeviceBackendNode *UpdateAxisActionJob::findAxisInputPhysicalDevice(AbstractAxisInput *axisInput)
+float UpdateAxisActionJob::processAxisInput(const Qt3DCore::QNodeId axisInputId)
{
- const auto integrations = m_handler->inputDeviceIntegrations();
- for (QInputDeviceIntegration *integration : integrations) {
- QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = integration->physicalDevice(axisInput->sourceDevice());
- if (physicalDeviceBackend)
- return physicalDeviceBackend;
- }
+ AnalogAxisInput *analogInput = m_handler->analogAxisInputManager()->lookupResource(axisInputId);
+ if (analogInput)
+ return analogInput->process(m_handler, m_currentTime);
+
+ ButtonAxisInput *buttonInput = m_handler->buttonAxisInputManager()->lookupResource(axisInputId);
+ if (buttonInput)
+ return buttonInput->process(m_handler, m_currentTime);
- return nullptr;
+ Q_UNREACHABLE();
+ return 0.0f;
}
} // Input