summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2019-10-07 17:00:50 +0100
committerMike Krus <mike.krus@kdab.com>2019-10-09 09:58:56 +0100
commit5eff77db3ade7f407de62952ed0a79371f328096 (patch)
tree5fabf3c187eb3a026e7ef5ed8c70e6361afe9bfa
parentd174057b01cbe8887b25880697ae33428c88cc6c (diff)
Update UpdateAxisActionJob to use direct sync
Change-Id: I227e1a5005a9001ac49d8b29daeb23be25fda53b Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/input/backend/action.cpp11
-rw-r--r--src/input/backend/axis.cpp11
-rw-r--r--src/input/backend/updateaxisactionjob.cpp63
-rw-r--r--src/input/backend/updateaxisactionjob_p.h3
-rw-r--r--src/input/frontend/qaction.cpp10
-rw-r--r--src/input/frontend/qaction.h3
-rw-r--r--src/input/frontend/qaxis.cpp10
-rw-r--r--src/input/frontend/qaxis.h3
-rw-r--r--tests/auto/input/action/tst_action.cpp32
-rw-r--r--tests/auto/input/axis/tst_axis.cpp31
-rw-r--r--tests/auto/input/qaction/tst_qaction.cpp16
-rw-r--r--tests/auto/input/qaxis/tst_qaxis.cpp21
12 files changed, 64 insertions, 150 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);
diff --git a/src/input/frontend/qaction.cpp b/src/input/frontend/qaction.cpp
index 4dc0493b0..8eccec9e4 100644
--- a/src/input/frontend/qaction.cpp
+++ b/src/input/frontend/qaction.cpp
@@ -149,16 +149,6 @@ QVector<QAbstractActionInput *> QAction::inputs() const
return d->m_inputs;
}
-/*! \internal */
-void QAction::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change)
-{
- Q_D(QAction);
- Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change);
- if (e->type() == Qt3DCore::PropertyUpdated && e->propertyName() == QByteArrayLiteral("active")) {
- d->setActive(e->value().toBool());
- }
-}
-
Qt3DCore::QNodeCreatedChangeBasePtr QAction::createNodeCreationChange() const
{
auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QActionData>::create(this);
diff --git a/src/input/frontend/qaction.h b/src/input/frontend/qaction.h
index f15159f68..8175bab8e 100644
--- a/src/input/frontend/qaction.h
+++ b/src/input/frontend/qaction.h
@@ -67,9 +67,6 @@ public:
Q_SIGNALS:
void activeChanged(bool isActive);
-protected:
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override;
-
private:
Q_DECLARE_PRIVATE(QAction)
Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const override;
diff --git a/src/input/frontend/qaxis.cpp b/src/input/frontend/qaxis.cpp
index c60c4bbe9..7c9998776 100644
--- a/src/input/frontend/qaxis.cpp
+++ b/src/input/frontend/qaxis.cpp
@@ -168,16 +168,6 @@ float QAxis::value() const
return d->m_value;
}
-/*! \internal */
-void QAxis::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change)
-{
- Q_D(QAxis);
- Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change);
- if (e->type() == Qt3DCore::PropertyUpdated && e->propertyName() == QByteArrayLiteral("value")) {
- d->setValue(e->value().toFloat());
- }
-}
-
Qt3DCore::QNodeCreatedChangeBasePtr QAxis::createNodeCreationChange() const
{
auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QAxisData>::create(this);
diff --git a/src/input/frontend/qaxis.h b/src/input/frontend/qaxis.h
index a4f7ea7d4..1a542cf22 100644
--- a/src/input/frontend/qaxis.h
+++ b/src/input/frontend/qaxis.h
@@ -66,9 +66,6 @@ public:
Q_SIGNALS:
void valueChanged(float value);
-protected:
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override;
-
private:
Q_DECLARE_PRIVATE(QAxis)
Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const override;
diff --git a/tests/auto/input/action/tst_action.cpp b/tests/auto/input/action/tst_action.cpp
index 8a6cb902f..6b8b11b80 100644
--- a/tests/auto/input/action/tst_action.cpp
+++ b/tests/auto/input/action/tst_action.cpp
@@ -138,38 +138,6 @@ private Q_SLOTS:
QCOMPARE(backendAction.inputs().size(), 0);
}
- void checkActivePropertyBackendNotification()
- {
- // GIVEN
- TestArbiter arbiter;
- Qt3DInput::Input::Action backendAction;
- backendAction.setEnabled(true);
- Qt3DCore::QBackendNodePrivate::get(&backendAction)->setArbiter(&arbiter);
- const bool currentActionTriggeredValue = backendAction.actionTriggered();
-
- // WHEN
- backendAction.setActionTriggered(true);
-
- // THEN
- QVERIFY(currentActionTriggeredValue != backendAction.actionTriggered());
- QCOMPARE(arbiter.events.count(), 1);
- Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
- QCOMPARE(change->propertyName(), "active");
- QCOMPARE(change->value().toBool(), backendAction.actionTriggered());
-
-
- arbiter.events.clear();
-
- // WHEN
- backendAction.setActionTriggered(true);
-
- // THEN
- QVERIFY(currentActionTriggeredValue != backendAction.actionTriggered());
- QCOMPARE(arbiter.events.count(), 0);
-
- arbiter.events.clear();
- }
-
void shouldNotActivateWhenDisabled()
{
// GIVEN
diff --git a/tests/auto/input/axis/tst_axis.cpp b/tests/auto/input/axis/tst_axis.cpp
index 8ad8098af..de9d5c553 100644
--- a/tests/auto/input/axis/tst_axis.cpp
+++ b/tests/auto/input/axis/tst_axis.cpp
@@ -139,37 +139,6 @@ private Q_SLOTS:
QCOMPARE(backendAxis.inputs().size(), 0);
}
- void checkValuePropertyBackendNotification()
- {
- // GIVEN
- TestArbiter arbiter;
- Qt3DInput::Input::Axis backendAxis;
- backendAxis.setEnabled(true);
- Qt3DCore::QBackendNodePrivate::get(&backendAxis)->setArbiter(&arbiter);
-
- // WHEN
- backendAxis.setAxisValue(454.0f);
-
- // THEN
- QCOMPARE(backendAxis.axisValue(), 454.0f);
- QCOMPARE(arbiter.events.count(), 1);
- Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
- QCOMPARE(change->propertyName(), "value");
- QCOMPARE(change->value().toFloat(), backendAxis.axisValue());
-
- arbiter.events.clear();
-
- // WHEN
- backendAxis.setAxisValue(454.0f);
-
- // THEN
- QCOMPARE(backendAxis.axisValue(), 454.0f);
- QCOMPARE(arbiter.events.count(), 0);
-
- arbiter.events.clear();
-
- }
-
void shouldNotChangeValueWhenDisabled()
{
// GIVEN
diff --git a/tests/auto/input/qaction/tst_qaction.cpp b/tests/auto/input/qaction/tst_qaction.cpp
index 71b6911fe..8d097978f 100644
--- a/tests/auto/input/qaction/tst_qaction.cpp
+++ b/tests/auto/input/qaction/tst_qaction.cpp
@@ -131,22 +131,6 @@ private Q_SLOTS:
arbiter.events.clear();
}
- void checkActivePropertyChanged()
- {
- // GIVEN
- QCOMPARE(isActive(), false);
-
- // Note: simulate backend change to frontend
- // WHEN
- Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
- valueChange->setPropertyName("active");
- valueChange->setValue(true);
- sceneChangeEvent(valueChange);
-
- // THEN
- QCOMPARE(isActive(), true);
- }
-
void checkActionInputBookkeeping()
{
// GIVEN
diff --git a/tests/auto/input/qaxis/tst_qaxis.cpp b/tests/auto/input/qaxis/tst_qaxis.cpp
index ae4d6861e..36d434c6a 100644
--- a/tests/auto/input/qaxis/tst_qaxis.cpp
+++ b/tests/auto/input/qaxis/tst_qaxis.cpp
@@ -38,10 +38,7 @@
#include "testpostmanarbiter.h"
-// We need to call QNode::clone which is protected
-// We need to call QAxis::sceneChangeEvent which is protected
-// So we sublcass QAxis instead of QObject
-class tst_QAxis: public Qt3DInput::QAxis
+class tst_QAxis: public QObject
{
Q_OBJECT
public:
@@ -128,22 +125,6 @@ private Q_SLOTS:
arbiter.events.clear();
}
- void checkValuePropertyChanged()
- {
- // GIVEN
- QCOMPARE(value(), 0.0f);
-
- // Note: simulate backend change to frontend
- // WHEN
- Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
- valueChange->setPropertyName("value");
- valueChange->setValue(383.0f);
- sceneChangeEvent(valueChange);
-
- // THEN
- QCOMPARE(value(), 383.0f);
- }
-
void checkAxisInputBookkeeping()
{
// GIVEN