diff options
author | Mike Krus <mike.krus@kdab.com> | 2019-10-07 17:00:50 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2019-10-09 09:58:56 +0100 |
commit | 5eff77db3ade7f407de62952ed0a79371f328096 (patch) | |
tree | 5fabf3c187eb3a026e7ef5ed8c70e6361afe9bfa /src/input/backend | |
parent | d174057b01cbe8887b25880697ae33428c88cc6c (diff) |
Update UpdateAxisActionJob to use direct sync
Change-Id: I227e1a5005a9001ac49d8b29daeb23be25fda53b
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/input/backend')
-rw-r--r-- | src/input/backend/action.cpp | 11 | ||||
-rw-r--r-- | src/input/backend/axis.cpp | 11 | ||||
-rw-r--r-- | src/input/backend/updateaxisactionjob.cpp | 63 | ||||
-rw-r--r-- | src/input/backend/updateaxisactionjob_p.h | 3 |
4 files changed, 63 insertions, 25 deletions
diff --git a/src/input/backend/action.cpp b/src/input/backend/action.cpp index cb7e93a0c..a34ff164f 100644 --- a/src/input/backend/action.cpp +++ b/src/input/backend/action.cpp @@ -41,7 +41,6 @@ #include <Qt3DInput/qaction.h> #include <Qt3DInput/qabstractactioninput.h> -#include <Qt3DCore/qpropertyupdatedchange.h> #include <Qt3DInput/private/qaction_p.h> @@ -66,16 +65,8 @@ void Action::cleanup() void Action::setActionTriggered(bool actionTriggered) { - if (isEnabled() && (actionTriggered != m_actionTriggered)) { + if (isEnabled() && (actionTriggered != m_actionTriggered)) m_actionTriggered = actionTriggered; - - // Send change to the frontend - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId()); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("active"); - e->setValue(m_actionTriggered); - notifyObservers(e); - } } void Action::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) diff --git a/src/input/backend/axis.cpp b/src/input/backend/axis.cpp index 20c05a49f..6c04d8fac 100644 --- a/src/input/backend/axis.cpp +++ b/src/input/backend/axis.cpp @@ -41,7 +41,6 @@ #include <Qt3DInput/qaxis.h> #include <Qt3DInput/qabstractaxisinput.h> -#include <Qt3DCore/qpropertyupdatedchange.h> #include <Qt3DInput/private/qaxis_p.h> #include <algorithm> @@ -67,16 +66,8 @@ void Axis::cleanup() void Axis::setAxisValue(float axisValue) { - if (isEnabled() && (!qFuzzyCompare(axisValue, m_axisValue))) { + if (isEnabled() && (!qFuzzyCompare(axisValue, m_axisValue))) m_axisValue = axisValue; - - // Send a change to the frontend - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId()); // TODOSYNC replace with direct access - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("value"); - e->setValue(m_axisValue); - notifyObservers(e); - } } void Axis::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) diff --git a/src/input/backend/updateaxisactionjob.cpp b/src/input/backend/updateaxisactionjob.cpp index 03690479a..58ed36639 100644 --- a/src/input/backend/updateaxisactionjob.cpp +++ b/src/input/backend/updateaxisactionjob.cpp @@ -38,7 +38,11 @@ ****************************************************************************/ #include "updateaxisactionjob_p.h" - +#include <Qt3DCore/private/qaspectmanager_p.h> +#include <Qt3DInput/qaction.h> +#include <Qt3DInput/qaxis.h> +#include <Qt3DInput/private/qaction_p.h> +#include <Qt3DInput/private/qaxis_p.h> #include <Qt3DInput/private/inputhandler_p.h> #include <Qt3DInput/private/inputmanagers_p.h> #include <Qt3DInput/private/job_common_p.h> @@ -49,13 +53,25 @@ namespace Qt3DInput { namespace Input { +class UpdateAxisActionJobPrivate : public Qt3DCore::QAspectJobPrivate +{ +public: + UpdateAxisActionJobPrivate() { } + ~UpdateAxisActionJobPrivate() override { } + + void postFrame(Qt3DCore::QAspectManager *manager) override; + + QVector<QPair<Qt3DCore::QNodeId, bool>> m_triggeredActions; + QVector<QPair<Qt3DCore::QNodeId, float>> m_triggeredAxis; +}; + UpdateAxisActionJob::UpdateAxisActionJob(qint64 currentTime, InputHandler *handler, HLogicalDevice handle) - : Qt3DCore::QAspectJob() + : Qt3DCore::QAspectJob(*new UpdateAxisActionJobPrivate()) , m_currentTime(currentTime) , m_handler(handler) , m_handle(handle) { - SET_JOB_RUN_STAT_TYPE(this, JobTypes::UpdateAxisAction, 0); + SET_JOB_RUN_STAT_TYPE(this, JobTypes::UpdateAxisAction, 0) } void UpdateAxisActionJob::run() @@ -73,7 +89,10 @@ void UpdateAxisActionJob::run() void UpdateAxisActionJob::updateAction(LogicalDevice *device) { + Q_D(UpdateAxisActionJob); const auto actionIds = device->actions(); + d->m_triggeredActions.reserve(actionIds.size()); + for (const Qt3DCore::QNodeId actionId : actionIds) { bool actionTriggered = false; Action *action = m_handler->actionManager()->lookupResource(actionId); @@ -82,7 +101,10 @@ void UpdateAxisActionJob::updateAction(LogicalDevice *device) for (const Qt3DCore::QNodeId actionInputId : actionInputIds) actionTriggered |= processActionInput(actionInputId); - action->setActionTriggered(actionTriggered); + if (action->isEnabled() && (action->actionTriggered() != actionTriggered)) { + action->setActionTriggered(actionTriggered); + d->m_triggeredActions.push_back({actionId, actionTriggered}); + } } } @@ -95,7 +117,10 @@ bool UpdateAxisActionJob::processActionInput(const Qt3DCore::QNodeId actionInput void UpdateAxisActionJob::updateAxis(LogicalDevice *device) { + Q_D(UpdateAxisActionJob); const auto axisIds = device->axes(); + d->m_triggeredAxis.reserve(axisIds.size()); + for (const Qt3DCore::QNodeId axisId : axisIds) { Axis *axis = m_handler->axisManager()->lookupResource(axisId); float axisValue = 0.0f; @@ -106,7 +131,11 @@ void UpdateAxisActionJob::updateAxis(LogicalDevice *device) // Clamp the axisValue -1/1 axisValue = qMin(1.0f, qMax(axisValue, -1.0f)); - axis->setAxisValue(axisValue); + + if (axis->isEnabled() && !qFuzzyCompare(axisValue, axis->axisValue())) { + axis->setAxisValue(axisValue); + d->m_triggeredAxis.push_back({axisId, axisValue}); + } } } @@ -124,6 +153,30 @@ float UpdateAxisActionJob::processAxisInput(const Qt3DCore::QNodeId axisInputId) return 0.0f; } +void UpdateAxisActionJobPrivate::postFrame(Qt3DCore::QAspectManager *manager) +{ + for (const auto &data: qAsConst(m_triggeredActions)) { + Qt3DInput::QAction *action = qobject_cast<Qt3DInput::QAction *>(manager->lookupNode(data.first)); + if (!action) + continue; + + Qt3DInput::QActionPrivate *daction = static_cast<Qt3DInput::QActionPrivate *>(Qt3DCore::QNodePrivate::get(action)); + daction->setActive(data.second); + } + + for (const auto &data: qAsConst(m_triggeredAxis)) { + Qt3DInput::QAxis *axis = qobject_cast<Qt3DInput::QAxis *>(manager->lookupNode(data.first)); + if (!axis) + continue; + + Qt3DInput::QAxisPrivate *daxis = static_cast<Qt3DInput::QAxisPrivate *>(Qt3DCore::QNodePrivate::get(axis)); + daxis->setValue(data.second); + } + + m_triggeredActions.clear(); + m_triggeredAxis.clear(); +} + } // Input } // Qt3DInput diff --git a/src/input/backend/updateaxisactionjob_p.h b/src/input/backend/updateaxisactionjob_p.h index 719923a50..040ed9775 100644 --- a/src/input/backend/updateaxisactionjob_p.h +++ b/src/input/backend/updateaxisactionjob_p.h @@ -67,6 +67,7 @@ namespace Input { class AbstractAxisInput; class ButtonAxisInput; class InputHandler; +class UpdateAxisActionJobPrivate; class UpdateAxisActionJob : public Qt3DCore::QAspectJob { @@ -75,6 +76,8 @@ public: void run() final; private: + Q_DECLARE_PRIVATE(UpdateAxisActionJob) + void updateAction(LogicalDevice *device); bool processActionInput(const Qt3DCore::QNodeId actionInputId); void updateAxis(LogicalDevice *device); |