summaryrefslogtreecommitdiffstats
path: root/src/input/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/input/backend')
-rw-r--r--src/input/backend/abstractactioninput.cpp2
-rw-r--r--src/input/backend/abstractactioninput_p.h4
-rw-r--r--src/input/backend/abstractaxisinput.cpp25
-rw-r--r--src/input/backend/abstractaxisinput_p.h7
-rw-r--r--src/input/backend/action.cpp47
-rw-r--r--src/input/backend/action_p.h8
-rw-r--r--src/input/backend/actioninput.cpp30
-rw-r--r--src/input/backend/actioninput_p.h4
-rw-r--r--src/input/backend/analogaxisinput.cpp24
-rw-r--r--src/input/backend/analogaxisinput_p.h4
-rw-r--r--src/input/backend/assignkeyboardfocusjob.cpp38
-rw-r--r--src/input/backend/assignkeyboardfocusjob_p.h3
-rw-r--r--src/input/backend/axis.cpp11
-rw-r--r--src/input/backend/axisaccumulator.cpp63
-rw-r--r--src/input/backend/axisaccumulator_p.h7
-rw-r--r--src/input/backend/axisaccumulatorjob.cpp39
-rw-r--r--src/input/backend/axisaccumulatorjob_p.h3
-rw-r--r--src/input/backend/axissetting.cpp33
-rw-r--r--src/input/backend/axissetting_p.h8
-rw-r--r--src/input/backend/buttonaxisinput.cpp36
-rw-r--r--src/input/backend/buttonaxisinput_p.h3
-rw-r--r--src/input/backend/genericdevicebackendnode.cpp28
-rw-r--r--src/input/backend/genericdevicebackendnode_p.h2
-rw-r--r--src/input/backend/inputchord.cpp50
-rw-r--r--src/input/backend/inputchord_p.h4
-rw-r--r--src/input/backend/inputsequence.cpp57
-rw-r--r--src/input/backend/inputsequence_p.h4
-rw-r--r--src/input/backend/inputsettings.cpp22
-rw-r--r--src/input/backend/inputsettings_p.h9
-rw-r--r--src/input/backend/keyboarddevice.cpp5
-rw-r--r--src/input/backend/keyboarddevice_p.h3
-rw-r--r--src/input/backend/keyboardhandler.cpp57
-rw-r--r--src/input/backend/keyboardhandler_p.h9
-rw-r--r--src/input/backend/keyeventdispatcherjob.cpp47
-rw-r--r--src/input/backend/keyeventdispatcherjob_p.h5
-rw-r--r--src/input/backend/loadproxydevicejob.cpp43
-rw-r--r--src/input/backend/loadproxydevicejob_p.h3
-rw-r--r--src/input/backend/logicaldevice.cpp45
-rw-r--r--src/input/backend/logicaldevice_p.h8
-rw-r--r--src/input/backend/mousedevice.cpp22
-rw-r--r--src/input/backend/mousedevice_p.h4
-rw-r--r--src/input/backend/mouseeventdispatcherjob.cpp57
-rw-r--r--src/input/backend/mouseeventdispatcherjob_p.h8
-rw-r--r--src/input/backend/mousehandler.cpp49
-rw-r--r--src/input/backend/mousehandler_p.h12
-rw-r--r--src/input/backend/physicaldeviceproxy.cpp28
-rw-r--r--src/input/backend/physicaldeviceproxy_p.h8
-rw-r--r--src/input/backend/qabstractphysicaldevicebackendnode.cpp93
-rw-r--r--src/input/backend/qabstractphysicaldevicebackendnode_p.h8
-rw-r--r--src/input/backend/qabstractphysicaldevicebackendnode_p_p.h5
-rw-r--r--src/input/backend/updateaxisactionjob.cpp63
-rw-r--r--src/input/backend/updateaxisactionjob_p.h3
52 files changed, 502 insertions, 658 deletions
diff --git a/src/input/backend/abstractactioninput.cpp b/src/input/backend/abstractactioninput.cpp
index 1d4366554..ec469204e 100644
--- a/src/input/backend/abstractactioninput.cpp
+++ b/src/input/backend/abstractactioninput.cpp
@@ -46,7 +46,7 @@ namespace Qt3DInput {
namespace Input {
AbstractActionInput::AbstractActionInput()
- : Qt3DCore::QBackendNode()
+ : BackendNode()
{
}
diff --git a/src/input/backend/abstractactioninput_p.h b/src/input/backend/abstractactioninput_p.h
index 267d276c7..e200990e7 100644
--- a/src/input/backend/abstractactioninput_p.h
+++ b/src/input/backend/abstractactioninput_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
#include <Qt3DCore/qnodeid.h>
QT_BEGIN_NAMESPACE
@@ -62,7 +62,7 @@ namespace Input {
class InputHandler;
-class Q_AUTOTEST_EXPORT AbstractActionInput : public Qt3DCore::QBackendNode
+class Q_AUTOTEST_EXPORT AbstractActionInput : public BackendNode
{
public:
AbstractActionInput();
diff --git a/src/input/backend/abstractaxisinput.cpp b/src/input/backend/abstractaxisinput.cpp
index aae165a7e..f69c046b3 100644
--- a/src/input/backend/abstractaxisinput.cpp
+++ b/src/input/backend/abstractaxisinput.cpp
@@ -41,7 +41,6 @@
#include "qabstractaxisinput_p.h"
#include <Qt3DInput/qabstractphysicaldevice.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DInput/private/abstractaxisinput_p.h>
#include <Qt3DInput/private/inputhandler_p.h>
@@ -54,32 +53,24 @@ namespace Qt3DInput {
namespace Input {
AbstractAxisInput::AbstractAxisInput()
- : Qt3DCore::QBackendNode()
+ : BackendNode()
{
}
-void AbstractAxisInput::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAbstractAxisInputData>>(change);
- const auto &data = typedChange->data;
- m_sourceDevice = data.sourceDeviceId;
-}
-
void AbstractAxisInput::cleanup()
{
QBackendNode::setEnabled(false);
m_sourceDevice = Qt3DCore::QNodeId();
}
-void AbstractAxisInput::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void AbstractAxisInput::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- if (e->type() == Qt3DCore::PropertyUpdated) {
- Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("sourceDevice")) {
- m_sourceDevice = propertyChange->value().value<Qt3DCore::QNodeId>();
- }
- }
- QBackendNode::sceneChangeEvent(e);
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const QAbstractAxisInput *node = qobject_cast<const QAbstractAxisInput *>(frontEnd);
+ if (!node)
+ return;
+
+ m_sourceDevice = Qt3DCore::qIdForNode(node->sourceDevice());
}
} // Input
diff --git a/src/input/backend/abstractaxisinput_p.h b/src/input/backend/abstractaxisinput_p.h
index 765e2214f..07a063908 100644
--- a/src/input/backend/abstractaxisinput_p.h
+++ b/src/input/backend/abstractaxisinput_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
#include <Qt3DCore/qnodeid.h>
QT_BEGIN_NAMESPACE
@@ -64,19 +64,18 @@ namespace Input {
class InputHandler;
-class Q_AUTOTEST_EXPORT AbstractAxisInput : public Qt3DCore::QBackendNode
+class Q_AUTOTEST_EXPORT AbstractAxisInput : public BackendNode
{
public:
virtual void cleanup();
inline Qt3DCore::QNodeId sourceDevice() const { return m_sourceDevice; }
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
virtual float process(InputHandler *inputHandler, qint64 currentTime) = 0;
protected:
AbstractAxisInput();
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) override;
Qt3DCore::QNodeId m_sourceDevice;
};
diff --git a/src/input/backend/action.cpp b/src/input/backend/action.cpp
index 601961dd9..a34ff164f 100644
--- a/src/input/backend/action.cpp
+++ b/src/input/backend/action.cpp
@@ -41,9 +41,6 @@
#include <Qt3DInput/qaction.h>
#include <Qt3DInput/qabstractactioninput.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
-#include <Qt3DCore/qpropertynodeaddedchange.h>
-#include <Qt3DCore/qpropertynoderemovedchange.h>
#include <Qt3DInput/private/qaction_p.h>
@@ -54,18 +51,11 @@ namespace Qt3DInput {
namespace Input {
Action::Action()
- : Qt3DCore::QBackendNode(ReadWrite)
+ : BackendNode(ReadWrite)
, m_actionTriggered(false)
{
}
-void Action::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QActionData>>(change);
- const auto &data = typedChange->data;
- m_inputs = data.inputIds;
-}
-
void Action::cleanup()
{
QBackendNode::setEnabled(false);
@@ -75,38 +65,19 @@ 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::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void Action::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- switch (e->type()) {
- case Qt3DCore::PropertyValueAdded: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("input"))
- m_inputs.push_back(change->addedNodeId());
- break;
- }
-
- case Qt3DCore::PropertyValueRemoved: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("input"))
- m_inputs.removeOne(change->removedNodeId());
- }
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const Qt3DInput::QAction *node = qobject_cast<const Qt3DInput::QAction *>(frontEnd);
+ if (!node)
+ return;
- default:
- break;
- }
- QBackendNode::sceneChangeEvent(e);
+ auto ids = Qt3DCore::qIdsForNodes(node->inputs());
+ m_inputs = ids;
}
} // Input
diff --git a/src/input/backend/action_p.h b/src/input/backend/action_p.h
index 8fe2759fd..7036f04b9 100644
--- a/src/input/backend/action_p.h
+++ b/src/input/backend/action_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
#include <Qt3DCore/qnodeid.h>
QT_BEGIN_NAMESPACE
@@ -60,7 +60,7 @@ namespace Qt3DInput {
namespace Input {
-class Q_AUTOTEST_EXPORT Action : public Qt3DCore::QBackendNode
+class Q_AUTOTEST_EXPORT Action : public BackendNode
{
public:
Action();
@@ -68,11 +68,9 @@ public:
inline QVector<Qt3DCore::QNodeId> inputs() const { return m_inputs; }
inline bool actionTriggered() const { return m_actionTriggered; }
void setActionTriggered(bool actionTriggered);
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
QVector<Qt3DCore::QNodeId> m_inputs;
bool m_actionTriggered;
};
diff --git a/src/input/backend/actioninput.cpp b/src/input/backend/actioninput.cpp
index 46dc7f584..b02da0a4d 100644
--- a/src/input/backend/actioninput.cpp
+++ b/src/input/backend/actioninput.cpp
@@ -40,8 +40,7 @@
#include "actioninput_p.h"
#include <Qt3DInput/qactioninput.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
-
+#include <Qt3DInput/qabstractphysicaldevice.h>
#include <Qt3DInput/private/qactioninput_p.h>
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/utils_p.h>
@@ -58,14 +57,6 @@ ActionInput::ActionInput()
{
}
-void ActionInput::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QActionInputData>>(change);
- const auto &data = typedChange->data;
- m_buttons = data.buttons;
- m_sourceDevice = data.sourceDeviceId;
-}
-
void ActionInput::cleanup()
{
setEnabled(false);
@@ -73,21 +64,20 @@ void ActionInput::cleanup()
m_buttons.clear();
}
-void ActionInput::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void ActionInput::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- if (e->type() == Qt3DCore::PropertyUpdated) {
- Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("sourceDevice"))
- m_sourceDevice = propertyChange->value().value<Qt3DCore::QNodeId>();
- else if (propertyChange->propertyName() == QByteArrayLiteral("buttons"))
- m_buttons = propertyChange->value().value<QVector<int>>();
- }
- AbstractActionInput::sceneChangeEvent(e);
+ AbstractActionInput::syncFromFrontEnd(frontEnd, firstTime);
+ const QActionInput *node = qobject_cast<const QActionInput *>(frontEnd);
+ if (!node)
+ return;
+
+ m_sourceDevice = Qt3DCore::qIdForNode(node->sourceDevice());
+ m_buttons = node->buttons();
}
bool ActionInput::process(InputHandler *inputHandler, qint64 currentTime)
{
- Q_UNUSED(currentTime);
+ Q_UNUSED(currentTime)
if (!isEnabled())
return false;
diff --git a/src/input/backend/actioninput_p.h b/src/input/backend/actioninput_p.h
index 00fb0475c..eecf1d10e 100644
--- a/src/input/backend/actioninput_p.h
+++ b/src/input/backend/actioninput_p.h
@@ -69,13 +69,11 @@ public:
inline QVector<int> buttons() const { return m_buttons; }
inline Qt3DCore::QNodeId sourceDevice() const { return m_sourceDevice; }
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
bool process(InputHandler *inputHandler, qint64 currentTime) override;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
QVector<int> m_buttons;
Qt3DCore::QNodeId m_sourceDevice;
};
diff --git a/src/input/backend/analogaxisinput.cpp b/src/input/backend/analogaxisinput.cpp
index 4a801baec..9dece6b9b 100644
--- a/src/input/backend/analogaxisinput.cpp
+++ b/src/input/backend/analogaxisinput.cpp
@@ -41,7 +41,6 @@
#include <Qt3DInput/qanalogaxisinput.h>
#include <Qt3DInput/qabstractphysicaldevice.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DInput/private/qabstractphysicaldevicebackendnode_p.h>
#include <Qt3DInput/private/qanalogaxisinput_p.h>
@@ -59,29 +58,20 @@ AnalogAxisInput::AnalogAxisInput()
{
}
-void AnalogAxisInput::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAnalogAxisInputData>>(change);
- const auto &data = typedChange->data;
- m_axis = data.axis;
- AbstractAxisInput::initializeFromPeer(change);
-}
-
void AnalogAxisInput::cleanup()
{
m_axis = 0;
AbstractAxisInput::cleanup();
}
-void AnalogAxisInput::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void AnalogAxisInput::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- if (e->type() == Qt3DCore::PropertyUpdated) {
- Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("axis")) {
- m_axis = propertyChange->value().toInt();
- }
- }
- AbstractAxisInput::sceneChangeEvent(e);
+ AbstractAxisInput::syncFromFrontEnd(frontEnd, firstTime);
+ const QAnalogAxisInput *node = qobject_cast<const QAnalogAxisInput *>(frontEnd);
+ if (!node)
+ return;
+
+ m_axis = node->axis();
}
float AnalogAxisInput::process(InputHandler *inputHandler, qint64 currentTime)
diff --git a/src/input/backend/analogaxisinput_p.h b/src/input/backend/analogaxisinput_p.h
index cd43e7d23..f13a2a2e1 100644
--- a/src/input/backend/analogaxisinput_p.h
+++ b/src/input/backend/analogaxisinput_p.h
@@ -66,13 +66,11 @@ public:
void cleanup() final;
inline int axis() const { return m_axis; }
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) final;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) final;
float process(InputHandler *inputHandler, qint64 currentTime) override;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
int m_axis;
};
diff --git a/src/input/backend/assignkeyboardfocusjob.cpp b/src/input/backend/assignkeyboardfocusjob.cpp
index 385074812..5fe329004 100644
--- a/src/input/backend/assignkeyboardfocusjob.cpp
+++ b/src/input/backend/assignkeyboardfocusjob.cpp
@@ -38,7 +38,8 @@
****************************************************************************/
#include "assignkeyboardfocusjob_p.h"
-
+#include <Qt3DCore/private/qaspectmanager_p.h>
+#include <Qt3DInput/qkeyboardhandler.h>
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/job_common_p.h>
@@ -50,12 +51,23 @@ QT_BEGIN_NAMESPACE
namespace Qt3DInput {
namespace Input {
+class AssignKeyboardFocusJobPrivate : public Qt3DCore::QAspectJobPrivate
+{
+public:
+ AssignKeyboardFocusJobPrivate() { }
+ ~AssignKeyboardFocusJobPrivate() override { }
+
+ void postFrame(Qt3DCore::QAspectManager *manager) override;
+
+ QVector<QPair<Qt3DCore::QNodeId, bool>> updates;
+};
+
AssignKeyboardFocusJob::AssignKeyboardFocusJob(Qt3DCore::QNodeId keyboardDevice)
- : QAspectJob()
+ : QAspectJob(*new AssignKeyboardFocusJobPrivate())
, m_inputHandler(nullptr)
, m_keyboardDevice(keyboardDevice)
{
- SET_JOB_RUN_STAT_TYPE(this, JobTypes::AssignKeyboardFocus, 0);
+ SET_JOB_RUN_STAT_TYPE(this, JobTypes::AssignKeyboardFocus, 0)
}
void AssignKeyboardFocusJob::setInputHandler(InputHandler *handler)
@@ -65,20 +77,40 @@ void AssignKeyboardFocusJob::setInputHandler(InputHandler *handler)
void AssignKeyboardFocusJob::run()
{
+ Q_D(AssignKeyboardFocusJob);
+
KeyboardDevice *keyboardDevice = m_inputHandler->keyboardDeviceManager()->lookupResource(m_keyboardDevice);
const auto handles = m_inputHandler->keyboardInputManager()->activeHandles();
+ d->updates.reserve(handles.size());
+
for (const HKeyboardHandler &handle : handles) {
KeyboardHandler *input = m_inputHandler->keyboardInputManager()->data(handle);
Q_ASSERT(input);
if (input->keyboardDevice() == m_keyboardDevice) {
bool hasFocus = input->peerId() == keyboardDevice->lastKeyboardInputRequester();
input->setFocus(hasFocus);
+ d->updates.push_back({input->peerId(), hasFocus});
if (hasFocus)
keyboardDevice->setCurrentFocusItem(input->peerId());
}
}
}
+void AssignKeyboardFocusJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
+{
+ for (const auto &data: qAsConst(updates)) {
+ QKeyboardHandler *node = qobject_cast<QKeyboardHandler *>(manager->lookupNode(data.first));
+ if (!node)
+ continue;
+
+ const bool b = node->blockNotifications(true);
+ node->setFocus(data.second);
+ node->blockNotifications(b);
+ }
+
+ updates.clear();
+}
+
} // namespace Input
} // namespace Qt3DInput
diff --git a/src/input/backend/assignkeyboardfocusjob_p.h b/src/input/backend/assignkeyboardfocusjob_p.h
index 8a74de85f..200fd72f1 100644
--- a/src/input/backend/assignkeyboardfocusjob_p.h
+++ b/src/input/backend/assignkeyboardfocusjob_p.h
@@ -60,6 +60,7 @@ namespace Qt3DInput {
namespace Input {
class InputHandler;
+class AssignKeyboardFocusJobPrivate;
class AssignKeyboardFocusJob : public Qt3DCore::QAspectJob
{
@@ -69,6 +70,8 @@ public:
void run() override;
private:
+ Q_DECLARE_PRIVATE(AssignKeyboardFocusJob)
+
InputHandler *m_inputHandler;
const Qt3DCore::QNodeId m_keyboardDevice;
};
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/axisaccumulator.cpp b/src/input/backend/axisaccumulator.cpp
index edc282bec..8e93c120e 100644
--- a/src/input/backend/axisaccumulator.cpp
+++ b/src/input/backend/axisaccumulator.cpp
@@ -39,8 +39,7 @@
#include "axisaccumulator_p.h"
-#include <Qt3DCore/qpropertyupdatedchange.h>
-
+#include <Qt3DInput/qaxis.h>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/qaxisaccumulator_p.h>
@@ -50,7 +49,7 @@ namespace Qt3DInput {
namespace Input {
AxisAccumulator::AxisAccumulator()
- : Qt3DCore::QBackendNode(ReadWrite)
+ : BackendNode(ReadWrite)
, m_sourceAxisId()
, m_sourceAxisType(QAxisAccumulator::Velocity)
, m_scale(1.0f)
@@ -59,17 +58,6 @@ AxisAccumulator::AxisAccumulator()
{
}
-void AxisAccumulator::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAxisAccumulatorData>>(change);
- const auto &data = typedChange->data;
- m_sourceAxisId = data.sourceAxisId;
- m_sourceAxisType = data.sourceAxisType;
- m_scale = data.scale;
- m_value = 0.0f;
- m_velocity = 0.0f;
-}
-
void AxisAccumulator::cleanup()
{
QBackendNode::setEnabled(false);
@@ -81,50 +69,31 @@ void AxisAccumulator::cleanup()
void AxisAccumulator::setValue(float value)
{
- if (isEnabled() && value != m_value) {
+ if (isEnabled() && value != m_value)
m_value = value;
-
- // Send a change to the frontend
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
- e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
- e->setPropertyName("value");
- e->setValue(m_value);
- notifyObservers(e);
- }
}
void AxisAccumulator::setVelocity(float velocity)
{
- if (isEnabled() && velocity != m_velocity) {
+ if (isEnabled() && velocity != m_velocity)
m_velocity = velocity;
-
- // Send a change to the frontend
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
- e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
- e->setPropertyName("velocity");
- e->setValue(m_velocity);
- notifyObservers(e);
- }
}
-void AxisAccumulator::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void AxisAccumulator::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- switch (e->type()) {
- case Qt3DCore::PropertyUpdated: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("sourceAxis"))
- m_sourceAxisId = change->value().value<Qt3DCore::QNodeId>();
- else if (change->propertyName() == QByteArrayLiteral("sourceAxisType"))
- m_sourceAxisType = change->value().value<QAxisAccumulator::SourceAxisType>();
- else if (change->propertyName() == QByteArrayLiteral("scale"))
- m_scale = change->value().toFloat();
- break;
- }
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const QAxisAccumulator *node = qobject_cast<const QAxisAccumulator *>(frontEnd);
+ if (!node)
+ return;
- default:
- break;
+ m_sourceAxisId = Qt3DCore::qIdForNode(node->sourceAxis());
+ m_sourceAxisType = node->sourceAxisType();
+ m_scale = node->scale();
+
+ if (firstTime) {
+ m_value = 0.f;
+ m_velocity = 0.f;
}
- QBackendNode::sceneChangeEvent(e);
}
void AxisAccumulator::stepIntegration(AxisManager *axisManager, float dt)
diff --git a/src/input/backend/axisaccumulator_p.h b/src/input/backend/axisaccumulator_p.h
index bb1a35812..2f5a7de63 100644
--- a/src/input/backend/axisaccumulator_p.h
+++ b/src/input/backend/axisaccumulator_p.h
@@ -52,6 +52,7 @@
//
#include <Qt3DInput/qaxisaccumulator.h>
+#include <Qt3DInput/private/backendnode_p.h>
#include <Qt3DCore/qbackendnode.h>
#include <Qt3DCore/qnodeid.h>
@@ -62,7 +63,7 @@ namespace Input {
class AxisManager;
-class Q_AUTOTEST_EXPORT AxisAccumulator : public Qt3DCore::QBackendNode
+class Q_AUTOTEST_EXPORT AxisAccumulator : public BackendNode
{
public:
AxisAccumulator();
@@ -78,13 +79,11 @@ public:
float velocity() const Q_DECL_NOTHROW { return m_velocity; }
void setVelocity(float velocity);
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
void stepIntegration(AxisManager *axisManager, float dt);
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
Qt3DCore::QNodeId m_sourceAxisId;
QAxisAccumulator::SourceAxisType m_sourceAxisType;
float m_scale;
diff --git a/src/input/backend/axisaccumulatorjob.cpp b/src/input/backend/axisaccumulatorjob.cpp
index cda8a5e26..16a68349e 100644
--- a/src/input/backend/axisaccumulatorjob.cpp
+++ b/src/input/backend/axisaccumulatorjob.cpp
@@ -38,7 +38,9 @@
****************************************************************************/
#include "axisaccumulatorjob_p.h"
-
+#include <Qt3DCore/private/qaspectmanager_p.h>
+#include <Qt3DInput/qaxisaccumulator.h>
+#include <Qt3DInput/private/qaxisaccumulator_p.h>
#include <Qt3DInput/private/axisaccumulator_p.h>
#include <Qt3DInput/private/job_common_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
@@ -48,24 +50,53 @@ QT_BEGIN_NAMESPACE
namespace Qt3DInput {
namespace Input {
+class AxisAccumulatorJobPrivate : public Qt3DCore::QAspectJobPrivate
+{
+public:
+ AxisAccumulatorJobPrivate() { }
+ ~AxisAccumulatorJobPrivate() override { }
+
+ void postFrame(Qt3DCore::QAspectManager *manager) override;
+
+ QVector<AxisAccumulator *> updates;
+};
+
AxisAccumulatorJob::AxisAccumulatorJob(AxisAccumulatorManager *axisAccumulatormanager,
AxisManager *axisManager)
- : Qt3DCore::QAspectJob()
+ : Qt3DCore::QAspectJob(*new AxisAccumulatorJobPrivate)
, m_axisAccumulatorManager(axisAccumulatormanager)
, m_axisManager(axisManager)
, m_dt(0.0f)
{
- SET_JOB_RUN_STAT_TYPE(this, JobTypes::AxisAccumulatorIntegration, 0);
+ SET_JOB_RUN_STAT_TYPE(this, JobTypes::AxisAccumulatorIntegration, 0)
}
void AxisAccumulatorJob::run()
{
+ Q_D(AxisAccumulatorJob);
// Iterate over the accumulators and ask each to step the integrations
const auto activeHandles = m_axisAccumulatorManager->activeHandles();
+ d->updates.reserve(activeHandles.size());
+
for (const auto &accumulatorHandle : activeHandles) {
AxisAccumulator *accumulator = m_axisAccumulatorManager->data(accumulatorHandle);
- if (accumulator->isEnabled())
+ if (accumulator->isEnabled()) {
accumulator->stepIntegration(m_axisManager, m_dt);
+ d->updates.push_back(accumulator);
+ }
+ }
+}
+
+void AxisAccumulatorJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
+{
+ for (auto backend: qAsConst(updates)) {
+ QAxisAccumulator *node = qobject_cast<QAxisAccumulator *>(manager->lookupNode(backend->peerId()));
+ if (!node)
+ continue;
+
+ QAxisAccumulatorPrivate *dnode = static_cast<QAxisAccumulatorPrivate *>(QAxisAccumulatorPrivate::get(node));
+ dnode->setValue(backend->value());
+ dnode->setVelocity(backend->velocity());
}
}
diff --git a/src/input/backend/axisaccumulatorjob_p.h b/src/input/backend/axisaccumulatorjob_p.h
index 4d38fd70f..702004dd2 100644
--- a/src/input/backend/axisaccumulatorjob_p.h
+++ b/src/input/backend/axisaccumulatorjob_p.h
@@ -62,6 +62,7 @@ namespace Input {
class AxisAccumulatorManager;
class AxisManager;
+class AxisAccumulatorJobPrivate;
class Q_AUTOTEST_EXPORT AxisAccumulatorJob : public Qt3DCore::QAspectJob
{
@@ -74,6 +75,8 @@ public:
void run() override;
private:
+ Q_DECLARE_PRIVATE(AxisAccumulatorJob)
+
AxisAccumulatorManager *m_axisAccumulatorManager;
AxisManager *m_axisManager;
float m_dt;
diff --git a/src/input/backend/axissetting.cpp b/src/input/backend/axissetting.cpp
index b3c81f84d..53e645c4d 100644
--- a/src/input/backend/axissetting.cpp
+++ b/src/input/backend/axissetting.cpp
@@ -40,7 +40,6 @@
#include "axissetting_p.h"
#include <Qt3DInput/qaxissetting.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DInput/private/qaxissetting_p.h>
@@ -50,22 +49,13 @@ namespace Qt3DInput {
namespace Input {
AxisSetting::AxisSetting()
- : Qt3DCore::QBackendNode()
+ : BackendNode()
, m_deadZoneRadius(0.0f)
, m_axes(0)
, m_smooth(false)
{
}
-void AxisSetting::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAxisSettingData>>(change);
- const auto &data = typedChange->data;
- m_deadZoneRadius = data.deadZoneRadius;
- m_axes = data.axes;
- m_smooth = data.smooth;
-}
-
void AxisSetting::cleanup()
{
QBackendNode::setEnabled(false);
@@ -74,19 +64,16 @@ void AxisSetting::cleanup()
m_smooth = false;
}
-void AxisSetting::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void AxisSetting::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- if (e->type() == Qt3DCore::PropertyUpdated) {
- Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("deadZoneRadius")) {
- m_deadZoneRadius = propertyChange->value().toFloat();
- } else if (propertyChange->propertyName() == QByteArrayLiteral("axes")) {
- m_axes = propertyChange->value().value<QVector<int>>();
- } else if (propertyChange->propertyName() == QByteArrayLiteral("smooth")) {
- m_smooth = propertyChange->value().toBool();
- }
- }
- QBackendNode::sceneChangeEvent(e);
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const QAxisSetting *node = qobject_cast<const QAxisSetting *>(frontEnd);
+ if (!node)
+ return;
+
+ m_deadZoneRadius = node->deadZoneRadius();
+ m_axes = node->axes();
+ m_smooth = node->isSmoothEnabled();
}
} // namespace Input
diff --git a/src/input/backend/axissetting_p.h b/src/input/backend/axissetting_p.h
index 42e1010d5..7d1e6ed4c 100644
--- a/src/input/backend/axissetting_p.h
+++ b/src/input/backend/axissetting_p.h
@@ -51,14 +51,14 @@
// We mean it.
//
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
QT_BEGIN_NAMESPACE
namespace Qt3DInput {
namespace Input {
-class Q_AUTOTEST_EXPORT AxisSetting : public Qt3DCore::QBackendNode
+class Q_AUTOTEST_EXPORT AxisSetting : public BackendNode
{
public:
AxisSetting();
@@ -68,11 +68,9 @@ public:
inline QVector<int> axes() const { return m_axes; }
inline bool isSmoothEnabled() const { return m_smooth; }
-protected:
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
float m_deadZoneRadius;
QVector<int> m_axes;
diff --git a/src/input/backend/buttonaxisinput.cpp b/src/input/backend/buttonaxisinput.cpp
index fef8f6d41..011d7df56 100644
--- a/src/input/backend/buttonaxisinput.cpp
+++ b/src/input/backend/buttonaxisinput.cpp
@@ -41,7 +41,6 @@
#include <Qt3DInput/qbuttonaxisinput.h>
#include <Qt3DInput/qabstractphysicaldevice.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DInput/private/qabstractphysicaldevicebackendnode_p.h>
#include <Qt3DInput/private/qbuttonaxisinput_p.h>
@@ -63,17 +62,6 @@ ButtonAxisInput::ButtonAxisInput()
{
}
-void ButtonAxisInput::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QButtonAxisInputData>>(change);
- const auto &data = typedChange->data;
- m_buttons = data.buttons;
- m_scale = data.scale;
- m_acceleration = data.acceleration;
- m_deceleration = data.deceleration;
- AbstractAxisInput::initializeFromPeer(change);
-}
-
void ButtonAxisInput::cleanup()
{
m_scale = 0.0f;
@@ -101,21 +89,17 @@ void ButtonAxisInput::updateSpeedRatio(qint64 currentTime, ButtonAxisInput::Upda
m_lastUpdateTime = currentTime;
}
-void ButtonAxisInput::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void ButtonAxisInput::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- if (e->type() == Qt3DCore::PropertyUpdated) {
- Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("scale")) {
- m_scale = propertyChange->value().toFloat();
- } else if (propertyChange->propertyName() == QByteArrayLiteral("buttons")) {
- m_buttons = propertyChange->value().value<QVector<int>>();
- } else if (propertyChange->propertyName() == QByteArrayLiteral("acceleration")) {
- m_acceleration = propertyChange->value().toFloat();
- } else if (propertyChange->propertyName() == QByteArrayLiteral("deceleration")) {
- m_deceleration = propertyChange->value().toFloat();
- }
- }
- AbstractAxisInput::sceneChangeEvent(e);
+ AbstractAxisInput::syncFromFrontEnd(frontEnd, firstTime);
+ const QButtonAxisInput *node = qobject_cast<const QButtonAxisInput *>(frontEnd);
+ if (!node)
+ return;
+
+ m_scale = node->scale();
+ m_buttons = node->buttons();
+ m_acceleration = node->acceleration();
+ m_deceleration = node->deceleration();
}
namespace {
diff --git a/src/input/backend/buttonaxisinput_p.h b/src/input/backend/buttonaxisinput_p.h
index f47a9b5cc..761b9e92a 100644
--- a/src/input/backend/buttonaxisinput_p.h
+++ b/src/input/backend/buttonaxisinput_p.h
@@ -78,13 +78,12 @@ public:
inline float speedRatio() const { return m_speedRatio; }
inline qint64 lastUpdateTime() const { return m_lastUpdateTime; }
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) final;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) final;
float process(InputHandler *inputHandler, qint64 currentTime) override;
private:
void updateSpeedRatio(qint64 currentTime, UpdateType type);
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
QVector<int> m_buttons;
float m_scale;
diff --git a/src/input/backend/genericdevicebackendnode.cpp b/src/input/backend/genericdevicebackendnode.cpp
index 40202b4a5..d56a674fc 100644
--- a/src/input/backend/genericdevicebackendnode.cpp
+++ b/src/input/backend/genericdevicebackendnode.cpp
@@ -40,10 +40,11 @@
#include "genericdevicebackendnode_p.h"
#include <Qt3DInput/qabstractphysicaldevice.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
+#include <Qt3DInput/private/qgenericinputdevice_p.h>
+#include <Qt3DInput/private/qabstractphysicaldevice_p.h>
QT_BEGIN_NAMESPACE
@@ -60,19 +61,24 @@ GenericDeviceBackendNode::~GenericDeviceBackendNode()
{
}
-void GenericDeviceBackendNode::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void GenericDeviceBackendNode::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (e->type() == Qt3DCore::PropertyUpdated) {
- if (propertyChange->propertyName() == QByteArrayLiteral("axisEvent")) {
- QPair<int, qreal> val = propertyChange->value().value<QPair<int, qreal>>();
- const QMutexLocker lock(&m_mutex);
+ QAbstractPhysicalDeviceBackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const Qt3DInput::QGenericInputDevice *node = qobject_cast<const Qt3DInput::QGenericInputDevice *>(frontEnd);
+ if (!node)
+ return;
+
+ auto *d = static_cast<Qt3DInput::QAbstractPhysicalDevicePrivate *>( Qt3DCore::QNodePrivate::get(const_cast<Qt3DCore::QNode *>(frontEnd)) );
+
+ {
+ const QMutexLocker lock(&m_mutex);
+ for (const auto &val: qAsConst(d->m_pendingAxisEvents))
m_axesValues[val.first] = val.second;
- } else if (propertyChange->propertyName() == QByteArrayLiteral("buttonEvent")) {
- QPair<int, qreal> val = propertyChange->value().value<QPair<int, qreal>>();
- const QMutexLocker lock(&m_mutex);
+ for (const auto &val: qAsConst(d->m_pendingButtonsEvents))
m_buttonsValues[val.first] = val.second;
- }
+
+ d->m_pendingAxisEvents.clear();
+ d->m_pendingButtonsEvents.clear();
}
}
diff --git a/src/input/backend/genericdevicebackendnode_p.h b/src/input/backend/genericdevicebackendnode_p.h
index c3ee1e467..3ae712115 100644
--- a/src/input/backend/genericdevicebackendnode_p.h
+++ b/src/input/backend/genericdevicebackendnode_p.h
@@ -73,7 +73,7 @@ public:
void updateEvents();
// QAbstractPhysicalDeviceBackendNode interface
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
void cleanup() override;
float axisValue(int axisIdentifier) const override;
bool isButtonPressed(int buttonIdentifier) const override;
diff --git a/src/input/backend/inputchord.cpp b/src/input/backend/inputchord.cpp
index 731fd91e3..fa8112e6d 100644
--- a/src/input/backend/inputchord.cpp
+++ b/src/input/backend/inputchord.cpp
@@ -40,9 +40,6 @@
#include "inputchord_p.h"
#include <Qt3DInput/qinputchord.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
-#include <Qt3DCore/qpropertynodeaddedchange.h>
-#include <Qt3DCore/qpropertynoderemovedchange.h>
#include <Qt3DInput/private/qinputchord_p.h>
#include <Qt3DInput/private/inputhandler_p.h>
@@ -62,15 +59,6 @@ InputChord::InputChord()
{
}
-void InputChord::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QInputChordData>>(change);
- const QInputChordData &data = typedChange->data;
- m_chords = data.chordIds;
- m_timeout = milliToNano(data.timeout);
- m_inputsToTrigger = m_chords;
-}
-
void InputChord::cleanup()
{
setEnabled(false);
@@ -102,38 +90,16 @@ void InputChord::setStartTime(qint64 time)
m_startTime = time;
}
-void InputChord::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void InputChord::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- switch (e->type()) {
- case Qt3DCore::PropertyUpdated: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("timeout"))
- m_timeout = milliToNano(change->value().toInt());
- break;
- }
+ AbstractActionInput::syncFromFrontEnd(frontEnd, firstTime);
+ const QInputChord *node = qobject_cast<const QInputChord *>(frontEnd);
+ if (!node)
+ return;
- case Qt3DCore::PropertyValueAdded: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("chord")) {
- m_chords.push_back(change->addedNodeId());
- m_inputsToTrigger.push_back(change->addedNodeId());
- }
- break;
- }
-
- case Qt3DCore::PropertyValueRemoved: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("chord")) {
- m_chords.removeOne(change->removedNodeId());
- m_inputsToTrigger.removeOne(change->removedNodeId());
- }
- break;
- }
-
- default:
- break;
- }
- AbstractActionInput::sceneChangeEvent(e);
+ m_timeout = milliToNano(node->timeout());
+ m_chords = Qt3DCore::qIdsForNodes(node->chords());
+ m_inputsToTrigger = m_chords;
}
bool InputChord::process(InputHandler *inputHandler, qint64 currentTime)
diff --git a/src/input/backend/inputchord_p.h b/src/input/backend/inputchord_p.h
index efad2c4af..0a654aa87 100644
--- a/src/input/backend/inputchord_p.h
+++ b/src/input/backend/inputchord_p.h
@@ -73,13 +73,11 @@ public:
void setStartTime(qint64 time);
void reset();
bool actionTriggered(Qt3DCore::QNodeId input);
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
bool process(InputHandler *inputHandler, qint64 currentTime) override;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
QVector<Qt3DCore::QNodeId> m_chords;
QVector<Qt3DCore::QNodeId> m_inputsToTrigger;
qint64 m_timeout;
diff --git a/src/input/backend/inputsequence.cpp b/src/input/backend/inputsequence.cpp
index e45fae364..690a7f0d1 100644
--- a/src/input/backend/inputsequence.cpp
+++ b/src/input/backend/inputsequence.cpp
@@ -41,9 +41,6 @@
#include <Qt3DInput/qabstractphysicaldevice.h>
#include <Qt3DInput/qinputsequence.h>
-#include <Qt3DCore/qpropertynodeaddedchange.h>
-#include <Qt3DCore/qpropertynoderemovedchange.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <QtCore/QDateTime>
#include <Qt3DInput/private/inputhandler_p.h>
@@ -66,16 +63,6 @@ InputSequence::InputSequence()
{
}
-void InputSequence::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QInputSequenceData>>(change);
- const QInputSequenceData &data = typedChange->data;
- m_sequences = data.sequenceIds;
- m_timeout = milliToNano(data.timeout);
- m_buttonInterval = milliToNano(data.buttonInterval);
- m_inputsToTrigger = m_sequences;
-}
-
void InputSequence::cleanup()
{
setEnabled(false);
@@ -127,41 +114,17 @@ bool InputSequence::actionTriggered(Qt3DCore::QNodeId input, const qint64 curren
return false;
}
-void InputSequence::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void InputSequence::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- switch (e->type()) {
- case Qt3DCore::PropertyUpdated: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("timeout")) {
- m_timeout = milliToNano(change->value().toInt());
- } else if (change->propertyName() == QByteArrayLiteral("buttonInterval")) {
- m_buttonInterval = milliToNano(change->value().toInt());
- }
- break;
- }
-
- case Qt3DCore::PropertyValueAdded: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("sequence")) {
- m_sequences.push_back(change->addedNodeId());
- m_inputsToTrigger.push_back(change->addedNodeId());
- }
- break;
- }
-
- case Qt3DCore::PropertyValueRemoved: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("sequence")) {
- m_sequences.removeOne(change->removedNodeId());
- m_inputsToTrigger.removeOne(change->removedNodeId());
- }
- break;
- }
-
- default:
- break;
- }
- AbstractActionInput::sceneChangeEvent(e);
+ AbstractActionInput::syncFromFrontEnd(frontEnd, firstTime);
+ const QInputSequence *node = qobject_cast<const QInputSequence *>(frontEnd);
+ if (!node)
+ return;
+
+ m_timeout = milliToNano(node->timeout());
+ m_buttonInterval = milliToNano(node->buttonInterval());
+ m_sequences = Qt3DCore::qIdsForNodes(node->sequences());
+ m_inputsToTrigger = m_sequences;
}
bool InputSequence::process(InputHandler *inputHandler, qint64 currentTime)
diff --git a/src/input/backend/inputsequence_p.h b/src/input/backend/inputsequence_p.h
index 395021035..53407bd1d 100644
--- a/src/input/backend/inputsequence_p.h
+++ b/src/input/backend/inputsequence_p.h
@@ -75,13 +75,11 @@ public:
bool sequenceTriggered() const;
void reset();
bool actionTriggered(Qt3DCore::QNodeId input, const qint64 currentTime);
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
bool process(InputHandler *inputHandler, qint64 currentTime) override;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
QVector<Qt3DCore::QNodeId> m_sequences;
QVector<Qt3DCore::QNodeId> m_inputsToTrigger;
qint64 m_timeout;
diff --git a/src/input/backend/inputsettings.cpp b/src/input/backend/inputsettings.cpp
index b695ed600..4fdd61a1b 100644
--- a/src/input/backend/inputsettings.cpp
+++ b/src/input/backend/inputsettings.cpp
@@ -40,7 +40,6 @@
#include "inputsettings_p.h"
#include <Qt3DInput/qinputsettings.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/qinputsettings_p.h>
@@ -52,26 +51,19 @@ namespace Qt3DInput {
namespace Input {
InputSettings::InputSettings()
- : QBackendNode(QBackendNode::ReadOnly)
+ : BackendNode(QBackendNode::ReadOnly)
, m_eventSource(nullptr)
{
}
-void InputSettings::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
+void InputSettings::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QInputSettingsData>>(change);
- const auto &data = typedChange->data;
- m_eventSource = data.eventSource;
-}
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const QInputSettings *node = qobject_cast<const QInputSettings *>(frontEnd);
+ if (!node)
+ return;
-void InputSettings::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
-{
- if (e->type() == Qt3DCore::PropertyUpdated) {
- Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("eventSource"))
- m_eventSource = propertyChange->value().value<QObject *>();
- }
- QBackendNode::sceneChangeEvent(e);
+ m_eventSource = node->eventSource();
}
InputSettingsFunctor::InputSettingsFunctor(InputHandler *handler)
diff --git a/src/input/backend/inputsettings_p.h b/src/input/backend/inputsettings_p.h
index 87cb4debf..33f56cc0b 100644
--- a/src/input/backend/inputsettings_p.h
+++ b/src/input/backend/inputsettings_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
#include <QtCore/QPointer>
QT_BEGIN_NAMESPACE
@@ -62,18 +62,15 @@ namespace Input {
class InputHandler;
-class InputSettings : public Qt3DCore::QBackendNode
+class InputSettings : public BackendNode
{
public:
InputSettings();
inline QObject *eventSource() const { return m_eventSource; }
-protected:
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
QPointer<QObject> m_eventSource;
};
diff --git a/src/input/backend/keyboarddevice.cpp b/src/input/backend/keyboarddevice.cpp
index 33578bdad..0e45d1c84 100644
--- a/src/input/backend/keyboarddevice.cpp
+++ b/src/input/backend/keyboarddevice.cpp
@@ -427,11 +427,6 @@ void KeyboardDevice::updateKeyEvents(const QList<QT_PREPEND_NAMESPACE(QKeyEvent)
setButtonValue(e.key(), e.type() == QT_PREPEND_NAMESPACE(QKeyEvent)::KeyPress ? true : false);
}
-
-void KeyboardDevice::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &)
-{
-}
-
KeyboardDeviceFunctor::KeyboardDeviceFunctor(QInputAspect *inputaspect, InputHandler *handler)
: m_inputAspect(inputaspect)
, m_handler(handler)
diff --git a/src/input/backend/keyboarddevice_p.h b/src/input/backend/keyboarddevice_p.h
index 781e8ead5..2df5eb64d 100644
--- a/src/input/backend/keyboarddevice_p.h
+++ b/src/input/backend/keyboarddevice_p.h
@@ -86,9 +86,6 @@ public:
inline Qt3DCore::QNodeId currentFocusItem() const { return m_currentFocusItem; }
inline Qt3DCore::QNodeId lastKeyboardInputRequester() const { return m_lastRequester; }
-protected:
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &) override;
-
private:
void setButtonValue(int key, bool value);
diff --git a/src/input/backend/keyboardhandler.cpp b/src/input/backend/keyboardhandler.cpp
index ae1e6d03c..66af527c9 100644
--- a/src/input/backend/keyboardhandler.cpp
+++ b/src/input/backend/keyboardhandler.cpp
@@ -56,22 +56,12 @@ namespace Qt3DInput {
namespace Input {
KeyboardHandler::KeyboardHandler()
- : QBackendNode(QBackendNode::ReadWrite)
+ : BackendNode(QBackendNode::ReadWrite)
, m_inputHandler(nullptr)
, m_focus(false)
{
}
-void KeyboardHandler::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QKeyboardHandlerData>>(change);
- const auto &data = typedChange->data;
- setSourcerDevice(data.keyboardDeviceId);
- m_focus = false;
- if (data.focus)
- requestFocus();
-}
-
Qt3DCore::QNodeId KeyboardHandler::keyboardDevice() const
{
return m_keyboardDevice;
@@ -86,43 +76,32 @@ void KeyboardHandler::setInputHandler(InputHandler *handler)
// Sends a change notification so that the frontend can update itself
void KeyboardHandler::setFocus(bool focus)
{
- if (focus != m_focus) {
+ if (focus != m_focus)
m_focus = focus;
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
- e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
- e->setPropertyName("focus");
- e->setValue(m_focus);
- notifyObservers(e);
- }
}
-void KeyboardHandler::keyEvent(const QKeyEventPtr &event)
+void KeyboardHandler::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
- e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
- e->setPropertyName("event");
- e->setValue(QVariant::fromValue(event));
- notifyObservers(e);
-}
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const Qt3DInput::QKeyboardHandler *node = qobject_cast<const Qt3DInput::QKeyboardHandler *>(frontEnd);
+ if (!node)
+ return;
+
+ if (firstTime)
+ m_focus = false;
-void KeyboardHandler::sceneChangeEvent(const QSceneChangePtr &e)
-{
bool focusRequest = false;
- if (e->type() == PropertyUpdated) {
- QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<QPropertyUpdatedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("sourceDevice")) {
- const QNodeId newId = propertyChange->value().value<QNodeId>();
- if (m_keyboardDevice != newId) {
- setSourcerDevice(newId);
- focusRequest = m_focus;
- }
- } else if (propertyChange->propertyName() == QByteArrayLiteral("focus")) {
- focusRequest = propertyChange->value().toBool();
- }
+ auto id = Qt3DCore::qIdForNode(node->sourceDevice());
+ if (m_keyboardDevice != id) {
+ setSourcerDevice(id);
+ focusRequest = m_focus;
}
+
+ if (m_focus != node->focus())
+ focusRequest = node->focus();
+
if (focusRequest)
requestFocus();
- QBackendNode::sceneChangeEvent(e);
}
void KeyboardHandler::requestFocus()
diff --git a/src/input/backend/keyboardhandler_p.h b/src/input/backend/keyboardhandler_p.h
index 317c33792..a5c13efbf 100644
--- a/src/input/backend/keyboardhandler_p.h
+++ b/src/input/backend/keyboardhandler_p.h
@@ -52,7 +52,7 @@
//
#include <Qt3DInput/qkeyevent.h>
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
#include <Qt3DCore/qnodeid.h>
QT_BEGIN_NAMESPACE
@@ -63,7 +63,7 @@ namespace Input {
class InputHandler;
-class Q_AUTOTEST_EXPORT KeyboardHandler : public Qt3DCore::QBackendNode
+class Q_AUTOTEST_EXPORT KeyboardHandler : public BackendNode
{
public:
KeyboardHandler();
@@ -71,19 +71,16 @@ public:
Qt3DCore::QNodeId keyboardDevice() const;
void setInputHandler(InputHandler *handler);
void setFocus(bool focus);
- void keyEvent(const QKeyEventPtr &event);
inline bool focus() const { return m_focus; }
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
protected:
void requestFocus();
void setSourcerDevice(Qt3DCore::QNodeId device);
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
InputHandler *m_inputHandler;
Qt3DCore::QNodeId m_keyboardDevice;
bool m_focus;
diff --git a/src/input/backend/keyeventdispatcherjob.cpp b/src/input/backend/keyeventdispatcherjob.cpp
index 6201453fc..26a35e885 100644
--- a/src/input/backend/keyeventdispatcherjob.cpp
+++ b/src/input/backend/keyeventdispatcherjob.cpp
@@ -38,7 +38,9 @@
****************************************************************************/
#include "keyeventdispatcherjob_p.h"
-
+#include <Qt3DCore/private/qaspectmanager_p.h>
+#include <Qt3DInput/qkeyboardhandler.h>
+#include <Qt3DInput/private/qkeyboardhandler_p.h>
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/job_common_p.h>
@@ -49,13 +51,26 @@ QT_BEGIN_NAMESPACE
namespace Qt3DInput {
namespace Input {
+class KeyEventDispatcherJobPrivate : public Qt3DCore::QAspectJobPrivate
+{
+public:
+ KeyEventDispatcherJobPrivate() { }
+ ~KeyEventDispatcherJobPrivate() override { }
+
+ void postFrame(Qt3DCore::QAspectManager *manager) override;
+
+ Qt3DCore::QNodeId m_keyboardHandler;
+ QList<QT_PREPEND_NAMESPACE(QKeyEvent)> m_events;
+};
+
KeyEventDispatcherJob::KeyEventDispatcherJob(Qt3DCore::QNodeId input, const QList<QT_PREPEND_NAMESPACE(QKeyEvent)> &events)
- : QAspectJob()
+ : QAspectJob(*new KeyEventDispatcherJobPrivate)
, m_inputHandler(nullptr)
- , m_keyboardHandler(input)
- , m_events(events)
{
- SET_JOB_RUN_STAT_TYPE(this, JobTypes::KeyEventDispatcher, 0);
+ Q_D(KeyEventDispatcherJob);
+ d->m_keyboardHandler = input;
+ d->m_events = events;
+ SET_JOB_RUN_STAT_TYPE(this, JobTypes::KeyEventDispatcher, 0)
}
void KeyEventDispatcherJob::setInputHandler(InputHandler *handler)
@@ -65,12 +80,22 @@ void KeyEventDispatcherJob::setInputHandler(InputHandler *handler)
void KeyEventDispatcherJob::run()
{
- KeyboardHandler *input = m_inputHandler->keyboardInputManager()->lookupResource(m_keyboardHandler);
- if (input)
- for (const QT_PREPEND_NAMESPACE(QKeyEvent) &e : qAsConst(m_events)) {
- // Send events to frontend
- input->keyEvent(QKeyEventPtr::create(e));
- }
+ // NOP
+}
+
+void KeyEventDispatcherJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
+{
+ QKeyboardHandler *node = qobject_cast<QKeyboardHandler *>(manager->lookupNode(m_keyboardHandler));
+ if (!node)
+ return;
+
+ QKeyboardHandlerPrivate *dnode = static_cast<QKeyboardHandlerPrivate *>(QKeyboardHandlerPrivate::get(node));
+ for (const auto &e: qAsConst(m_events)) {
+ QKeyEvent ke(e);
+ dnode->keyEvent(&ke);
+ }
+
+ m_events.clear();
}
} // namespace Input
diff --git a/src/input/backend/keyeventdispatcherjob_p.h b/src/input/backend/keyeventdispatcherjob_p.h
index be2364ac9..bd0c770d4 100644
--- a/src/input/backend/keyeventdispatcherjob_p.h
+++ b/src/input/backend/keyeventdispatcherjob_p.h
@@ -61,6 +61,7 @@ namespace Qt3DInput {
namespace Input {
class InputHandler;
+class KeyEventDispatcherJobPrivate;
class KeyEventDispatcherJob : public Qt3DCore::QAspectJob
{
@@ -70,9 +71,9 @@ public:
void run() override;
private:
+ Q_DECLARE_PRIVATE(KeyEventDispatcherJob)
+
InputHandler *m_inputHandler;
- const Qt3DCore::QNodeId m_keyboardHandler;
- const QList<QT_PREPEND_NAMESPACE(QKeyEvent)> m_events;
};
} // namespace Input
diff --git a/src/input/backend/loadproxydevicejob.cpp b/src/input/backend/loadproxydevicejob.cpp
index 2ea29b4a9..69f14beae 100644
--- a/src/input/backend/loadproxydevicejob.cpp
+++ b/src/input/backend/loadproxydevicejob.cpp
@@ -38,7 +38,9 @@
****************************************************************************/
#include "loadproxydevicejob_p.h"
-
+#include <Qt3DCore/private/qaspectmanager_p.h>
+#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p.h>
+#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p_p.h>
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/job_common_p.h>
@@ -48,12 +50,22 @@ QT_BEGIN_NAMESPACE
namespace Qt3DInput {
namespace Input {
+class LoadProxyDeviceJobPrivate : public Qt3DCore::QAspectJobPrivate
+{
+public:
+ LoadProxyDeviceJobPrivate() { }
+ ~LoadProxyDeviceJobPrivate() override { }
+
+ void postFrame(Qt3DCore::QAspectManager *manager) override;
+
+ QVector<QPair<Qt3DCore::QNodeId, QAbstractPhysicalDevice *>> updates;
+};
+
LoadProxyDeviceJob::LoadProxyDeviceJob()
- : Qt3DCore::QAspectJob()
+ : Qt3DCore::QAspectJob(*new LoadProxyDeviceJobPrivate)
, m_inputHandler(nullptr)
{
- SET_JOB_RUN_STAT_TYPE(this, JobTypes::DeviceProxyLoading, 0);
-
+ SET_JOB_RUN_STAT_TYPE(this, JobTypes::DeviceProxyLoading, 0)
}
LoadProxyDeviceJob::~LoadProxyDeviceJob()
@@ -82,6 +94,9 @@ QVector<Qt3DCore::QNodeId> LoadProxyDeviceJob::proxies() const
void LoadProxyDeviceJob::run()
{
+ Q_D(LoadProxyDeviceJob);
+ d->updates.reserve(m_proxies.size());
+
Q_ASSERT(m_inputHandler);
for (const Qt3DCore::QNodeId id : qAsConst(m_proxies)) {
PhysicalDeviceProxy *proxy = m_inputHandler->physicalDeviceProxyManager()->lookupResource(id);
@@ -89,9 +104,27 @@ void LoadProxyDeviceJob::run()
if (device != nullptr)
proxy->setDevice(device);
}
- m_proxies.clear();
}
+void LoadProxyDeviceJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
+{
+ for (const auto &res : qAsConst(updates)) {
+ QAbstractPhysicalDeviceProxy *node = qobject_cast<QAbstractPhysicalDeviceProxy *>(manager->lookupNode(res.first));
+ if (!node)
+ continue;
+
+ auto *device = res.second;
+ QAbstractPhysicalDeviceProxyPrivate *dnode = static_cast<QAbstractPhysicalDeviceProxyPrivate *>(QAbstractPhysicalDeviceProxyPrivate::get(node));
+ QAbstractPhysicalDevice *oldDevice = dnode->m_device;
+ dnode->setDevice(device);
+ // Delete the old device if it existed
+ delete oldDevice;
+ }
+
+ updates.clear();
+}
+
+
} // namespace Input
} // namespace Qt3DInput
diff --git a/src/input/backend/loadproxydevicejob_p.h b/src/input/backend/loadproxydevicejob_p.h
index f9b343b2e..0848c8529 100644
--- a/src/input/backend/loadproxydevicejob_p.h
+++ b/src/input/backend/loadproxydevicejob_p.h
@@ -60,6 +60,7 @@ namespace Qt3DInput {
namespace Input {
class InputHandler;
+class LoadProxyDeviceJobPrivate;
class Q_AUTOTEST_EXPORT LoadProxyDeviceJob : public Qt3DCore::QAspectJob
{
@@ -75,6 +76,8 @@ public:
void run() final;
private:
+ Q_DECLARE_PRIVATE(LoadProxyDeviceJob)
+
InputHandler *m_inputHandler;
QVector<Qt3DCore::QNodeId> m_proxies;
};
diff --git a/src/input/backend/logicaldevice.cpp b/src/input/backend/logicaldevice.cpp
index 5fcfb07bb..17426922f 100644
--- a/src/input/backend/logicaldevice.cpp
+++ b/src/input/backend/logicaldevice.cpp
@@ -42,9 +42,6 @@
#include <Qt3DInput/qaction.h>
#include <Qt3DInput/qaxis.h>
#include <Qt3DInput/qlogicaldevice.h>
-#include <Qt3DCore/qpropertynodeaddedchange.h>
-#include <Qt3DCore/qpropertynoderemovedchange.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/qlogicaldevice_p.h>
@@ -56,18 +53,10 @@ namespace Qt3DInput {
namespace Input {
LogicalDevice::LogicalDevice()
- : QBackendNode()
+ : BackendNode()
{
}
-void LogicalDevice::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QLogicalDeviceData>>(change);
- const auto &data = typedChange->data;
- m_actions = data.actionIds;
- m_axes = data.axisIds;
-}
-
void LogicalDevice::cleanup()
{
QBackendNode::setEnabled(false);
@@ -75,31 +64,15 @@ void LogicalDevice::cleanup()
m_axes.clear();
}
-void LogicalDevice::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void LogicalDevice::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- switch (e->type()) {
- case Qt3DCore::PropertyValueAdded: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("axis"))
- m_axes.push_back(change->addedNodeId());
- else if (change->propertyName() == QByteArrayLiteral("action"))
- m_actions.push_back(change->addedNodeId());
- break;
- }
-
- case Qt3DCore::PropertyValueRemoved: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("axis"))
- m_axes.removeOne(change->removedNodeId());
- else if (change->propertyName() == QByteArrayLiteral("action"))
- m_actions.removeOne(change->removedNodeId());
- break;
- }
-
- default:
- break;
- }
- QBackendNode::sceneChangeEvent(e);
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const QLogicalDevice *node = qobject_cast<const QLogicalDevice *>(frontEnd);
+ if (!node)
+ return;
+
+ m_actions = Qt3DCore::qIdsForNodes(node->actions());
+ m_axes = Qt3DCore::qIdsForNodes(node->axes());
}
LogicalDeviceNodeFunctor::LogicalDeviceNodeFunctor(LogicalDeviceManager *manager)
diff --git a/src/input/backend/logicaldevice_p.h b/src/input/backend/logicaldevice_p.h
index 138a54777..292f2a5c3 100644
--- a/src/input/backend/logicaldevice_p.h
+++ b/src/input/backend/logicaldevice_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
#include <Qt3DCore/qnodeid.h>
QT_BEGIN_NAMESPACE
@@ -62,7 +62,7 @@ namespace Input {
class LogicalDeviceManager;
-class Q_AUTOTEST_EXPORT LogicalDevice : public Qt3DCore::QBackendNode
+class Q_AUTOTEST_EXPORT LogicalDevice : public BackendNode
{
public:
LogicalDevice();
@@ -71,11 +71,9 @@ public:
inline QVector<Qt3DCore::QNodeId> axes() const { return m_axes; }
inline QVector<Qt3DCore::QNodeId> actions() const { return m_actions; }
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
QVector<Qt3DCore::QNodeId> m_axes;
QVector<Qt3DCore::QNodeId> m_actions;
};
diff --git a/src/input/backend/mousedevice.cpp b/src/input/backend/mousedevice.cpp
index e285783b7..47045a1a1 100644
--- a/src/input/backend/mousedevice.cpp
+++ b/src/input/backend/mousedevice.cpp
@@ -42,7 +42,6 @@
#include <Qt3DInput/qmousedevice.h>
#include <Qt3DCore/qentity.h>
#include <Qt3DCore/qnode.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/inputhandler_p.h>
@@ -65,14 +64,6 @@ MouseDevice::~MouseDevice()
{
}
-void MouseDevice::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QMouseDeviceData>>(change);
- const auto &data = typedChange->data;
- m_sensitivity = data.sensitivity;
- QAbstractPhysicalDeviceBackendNode::initializeFromPeer(change);
-}
-
void MouseDevice::setInputHandler(InputHandler *handler)
{
m_inputHandler = handler;
@@ -173,13 +164,14 @@ void MouseDevice::updateMouseEvents(const QList<QT_PREPEND_NAMESPACE(QMouseEvent
}
}
-void MouseDevice::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void MouseDevice::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- if (e->type() == Qt3DCore::PropertyUpdated) {
- Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("sensitivity"))
- m_sensitivity = propertyChange->value().toFloat();
- }
+ QAbstractPhysicalDeviceBackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const Qt3DInput::QMouseDevice *node = qobject_cast<const Qt3DInput::QMouseDevice *>(frontEnd);
+ if (!node)
+ return;
+
+ m_sensitivity = node->sensitivity();
}
MouseDeviceFunctor::MouseDeviceFunctor(QInputAspect *inputAspect, InputHandler *handler)
diff --git a/src/input/backend/mousedevice_p.h b/src/input/backend/mousedevice_p.h
index d49ea2502..283eeaeaf 100644
--- a/src/input/backend/mousedevice_p.h
+++ b/src/input/backend/mousedevice_p.h
@@ -108,11 +108,9 @@ public:
bool wasPressed() const;
float sensitivity() const;
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
InputHandler *m_inputHandler;
MouseState m_mouseState;
diff --git a/src/input/backend/mouseeventdispatcherjob.cpp b/src/input/backend/mouseeventdispatcherjob.cpp
index 4bd3e93c3..0ee6862fb 100644
--- a/src/input/backend/mouseeventdispatcherjob.cpp
+++ b/src/input/backend/mouseeventdispatcherjob.cpp
@@ -38,7 +38,9 @@
****************************************************************************/
#include "mouseeventdispatcherjob_p.h"
-
+#include <Qt3DCore/private/qaspectmanager_p.h>
+#include <Qt3DInput/qmousehandler.h>
+#include <Qt3DInput/private/qmousehandler_p.h>
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/job_common_p.h>
@@ -49,21 +51,37 @@ QT_BEGIN_NAMESPACE
namespace Qt3DInput {
namespace Input {
+class MouseEventDispatcherJobPrivate : public Qt3DCore::QAspectJobPrivate
+{
+public:
+ MouseEventDispatcherJobPrivate() { }
+ ~MouseEventDispatcherJobPrivate() override { }
+
+ void postFrame(Qt3DCore::QAspectManager *manager) override;
+
+ Qt3DCore::QNodeId m_mouseInput;
+ QList<QT_PREPEND_NAMESPACE(QMouseEvent)> m_mouseEvents;
+#if QT_CONFIG(wheelevent)
+ QList<QT_PREPEND_NAMESPACE(QWheelEvent)> m_wheelEvents;
+#endif
+};
+
MouseEventDispatcherJob::MouseEventDispatcherJob(Qt3DCore::QNodeId input,
const QList<QT_PREPEND_NAMESPACE (QMouseEvent)> &mouseEvents
#if QT_CONFIG(wheelevent)
, const QList<QT_PREPEND_NAMESPACE (QWheelEvent)> &wheelEvents
#endif
)
- : QAspectJob()
+ : QAspectJob(*new MouseEventDispatcherJobPrivate)
, m_inputHandler(nullptr)
- , m_mouseInput(input)
- , m_mouseEvents(mouseEvents)
+{
+ Q_D(MouseEventDispatcherJob);
+ d->m_mouseInput = input;
+ d->m_mouseEvents = mouseEvents;
#if QT_CONFIG(wheelevent)
- , m_wheelEvents(wheelEvents)
+ d->m_wheelEvents = wheelEvents;
#endif
-{
- SET_JOB_RUN_STAT_TYPE(this, JobTypes::MouseEventDispatcher, 0);
+ SET_JOB_RUN_STAT_TYPE(this, JobTypes::MouseEventDispatcher, 0)
}
void MouseEventDispatcherJob::setInputHandler(InputHandler *handler)
@@ -73,16 +91,25 @@ void MouseEventDispatcherJob::setInputHandler(InputHandler *handler)
void MouseEventDispatcherJob::run()
{
- MouseHandler *input = m_inputHandler->mouseInputManager()->lookupResource(m_mouseInput);
- if (input) {
- // Send mouse and wheel events to frontend
- for (const QT_PREPEND_NAMESPACE(QMouseEvent) &e : m_mouseEvents)
- input->mouseEvent(QMouseEventPtr::create(e));
+ // NOP
+}
+
+void MouseEventDispatcherJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
+{
+ QMouseHandler *node = qobject_cast<QMouseHandler *>(manager->lookupNode(m_mouseInput));
+ if (!node)
+ return;
+
+ QMouseHandlerPrivate *dnode = static_cast<QMouseHandlerPrivate *>(QMouseHandlerPrivate::get(node));
+
+ for (const QT_PREPEND_NAMESPACE(QMouseEvent) &e : m_mouseEvents)
+ dnode->mouseEvent(QMouseEventPtr::create(e));
#if QT_CONFIG(wheelevent)
- for (const QT_PREPEND_NAMESPACE(QWheelEvent) &e : m_wheelEvents)
- input->wheelEvent(QWheelEventPtr::create(e));
-#endif
+ for (const QT_PREPEND_NAMESPACE(QWheelEvent) &e : m_wheelEvents) {
+ QWheelEvent we(e);
+ emit node->wheel(&we);
}
+#endif
}
} // namespace Input
diff --git a/src/input/backend/mouseeventdispatcherjob_p.h b/src/input/backend/mouseeventdispatcherjob_p.h
index 8abeccfb4..696d60da4 100644
--- a/src/input/backend/mouseeventdispatcherjob_p.h
+++ b/src/input/backend/mouseeventdispatcherjob_p.h
@@ -61,6 +61,7 @@ namespace Qt3DInput {
namespace Input {
class InputHandler;
+class MouseEventDispatcherJobPrivate;
class MouseEventDispatcherJob : public Qt3DCore::QAspectJob
{
@@ -75,12 +76,9 @@ public:
void run() final;
private:
+ Q_DECLARE_PRIVATE(MouseEventDispatcherJob)
+
InputHandler *m_inputHandler;
- const Qt3DCore::QNodeId m_mouseInput;
- const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> m_mouseEvents;
-#if QT_CONFIG(wheelevent)
- const QList<QT_PREPEND_NAMESPACE(QWheelEvent)> m_wheelEvents;
-#endif
};
} // namespace Input
diff --git a/src/input/backend/mousehandler.cpp b/src/input/backend/mousehandler.cpp
index c492dcf28..46bd273d6 100644
--- a/src/input/backend/mousehandler.cpp
+++ b/src/input/backend/mousehandler.cpp
@@ -56,7 +56,7 @@ namespace Qt3DInput {
namespace Input {
MouseHandler::MouseHandler()
- : QBackendNode(ReadWrite)
+ : BackendNode(ReadWrite)
, m_inputHandler(nullptr)
{
}
@@ -65,13 +65,6 @@ MouseHandler::~MouseHandler()
{
}
-void MouseHandler::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QMouseHandlerData>>(change);
- const auto &data = typedChange->data;
- setDevice(data.mouseDeviceId);
-}
-
Qt3DCore::QNodeId MouseHandler::mouseDevice() const
{
return m_mouseDevice;
@@ -82,38 +75,16 @@ void MouseHandler::setInputHandler(InputHandler *handler)
m_inputHandler = handler;
}
-void MouseHandler::mouseEvent(const QMouseEventPtr &event)
-{
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
- e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
- e->setPropertyName("mouse");
- e->setValue(QVariant::fromValue(event));
- notifyObservers(e);
-}
-
-#if QT_CONFIG(wheelevent)
-void MouseHandler::wheelEvent(const QWheelEventPtr &event)
-{
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
- e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
- e->setPropertyName("wheel");
- e->setValue(QVariant::fromValue(event));
- notifyObservers(e);
-}
-#endif
-
-void MouseHandler::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void MouseHandler::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- if (e->type() == PropertyUpdated) {
- QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<QPropertyUpdatedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("device")) {
- const QNodeId newId = propertyChange->value().value<QNodeId>();
- if (m_mouseDevice != newId) {
- setDevice(newId);
- }
- }
- }
- QBackendNode::sceneChangeEvent(e);
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const Qt3DInput::QMouseHandler *node = qobject_cast<const Qt3DInput::QMouseHandler *>(frontEnd);
+ if (!node)
+ return;
+
+ const auto newId = Qt3DCore::qIdForNode(node->sourceDevice());
+ if (m_mouseDevice != newId)
+ setDevice(newId);
}
void MouseHandler::setDevice(Qt3DCore::QNodeId device)
diff --git a/src/input/backend/mousehandler_p.h b/src/input/backend/mousehandler_p.h
index 6d748c068..693c42471 100644
--- a/src/input/backend/mousehandler_p.h
+++ b/src/input/backend/mousehandler_p.h
@@ -52,7 +52,7 @@
//
#include <Qt3DInput/qmouseevent.h>
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
QT_BEGIN_NAMESPACE
@@ -61,7 +61,7 @@ namespace Input {
class InputHandler;
-class MouseHandler : public Qt3DCore::QBackendNode
+class MouseHandler : public BackendNode
{
public:
MouseHandler();
@@ -69,18 +69,12 @@ public:
Qt3DCore::QNodeId mouseDevice() const;
void setInputHandler(InputHandler *handler);
- void mouseEvent(const QMouseEventPtr &event);
-#if QT_CONFIG(wheelevent)
- void wheelEvent(const QWheelEventPtr &event);
-#endif
protected:
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
void setDevice(Qt3DCore::QNodeId device);
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
Qt3DCore::QNodeId m_mouseDevice;
InputHandler *m_inputHandler;
};
diff --git a/src/input/backend/physicaldeviceproxy.cpp b/src/input/backend/physicaldeviceproxy.cpp
index 9512296b8..390b525eb 100644
--- a/src/input/backend/physicaldeviceproxy.cpp
+++ b/src/input/backend/physicaldeviceproxy.cpp
@@ -40,10 +40,10 @@
#include "physicaldeviceproxy_p.h"
#include <Qt3DInput/qabstractphysicaldevice.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <QtCore/QCoreApplication>
#include <Qt3DInput/private/inputmanagers_p.h>
+#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p.h>
#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p_p.h>
QT_BEGIN_NAMESPACE
@@ -53,7 +53,7 @@ namespace Qt3DInput {
namespace Input {
PhysicalDeviceProxy::PhysicalDeviceProxy()
- : QBackendNode(QBackendNode::ReadWrite)
+ : BackendNode(QBackendNode::ReadWrite)
, m_manager(nullptr)
{
}
@@ -89,12 +89,6 @@ void PhysicalDeviceProxy::setDevice(QAbstractPhysicalDevice *device)
m_physicalDeviceId = device->id();
device->moveToThread(QCoreApplication::instance()->thread());
}
-
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
- e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
- e->setPropertyName("device");
- e->setValue(QVariant::fromValue(device));
- notifyObservers(e);
}
Qt3DCore::QNodeId PhysicalDeviceProxy::physicalDeviceId() const
@@ -102,14 +96,20 @@ Qt3DCore::QNodeId PhysicalDeviceProxy::physicalDeviceId() const
return m_physicalDeviceId;
}
-void PhysicalDeviceProxy::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
+void PhysicalDeviceProxy::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAbstractPhysicalDeviceProxyData>>(change);
- const QAbstractPhysicalDeviceProxyData &data = typedChange->data;
- m_deviceName = data.deviceName;
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+
+ if (firstTime) {
+ const QAbstractPhysicalDeviceProxy *node = qobject_cast<const QAbstractPhysicalDeviceProxy *>(frontEnd);
+ if (!node)
+ return;
- // Request to load the actual device
- m_manager->addPendingProxyToLoad(peerId());
+ m_deviceName = node->deviceName();
+
+ // Request to load the actual device
+ m_manager->addPendingProxyToLoad(peerId());
+ }
}
PhysicalDeviceProxyNodeFunctor::PhysicalDeviceProxyNodeFunctor(PhysicalDeviceProxyManager *manager)
diff --git a/src/input/backend/physicaldeviceproxy_p.h b/src/input/backend/physicaldeviceproxy_p.h
index 9500a4adb..6dd2a54be 100644
--- a/src/input/backend/physicaldeviceproxy_p.h
+++ b/src/input/backend/physicaldeviceproxy_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
#include <Qt3DCore/qnodeid.h>
QT_BEGIN_NAMESPACE
@@ -64,7 +64,7 @@ namespace Input {
class PhysicalDeviceProxyManager;
-class Q_AUTOTEST_EXPORT PhysicalDeviceProxy : public Qt3DCore::QBackendNode
+class Q_AUTOTEST_EXPORT PhysicalDeviceProxy : public BackendNode
{
public:
PhysicalDeviceProxy();
@@ -79,9 +79,9 @@ public:
void setDevice(QAbstractPhysicalDevice *device);
Qt3DCore::QNodeId physicalDeviceId() const;
-private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
+private:
QString m_deviceName;
PhysicalDeviceProxyManager *m_manager;
Qt3DCore::QNodeId m_physicalDeviceId;
diff --git a/src/input/backend/qabstractphysicaldevicebackendnode.cpp b/src/input/backend/qabstractphysicaldevicebackendnode.cpp
index 5006d702a..6e6899e32 100644
--- a/src/input/backend/qabstractphysicaldevicebackendnode.cpp
+++ b/src/input/backend/qabstractphysicaldevicebackendnode.cpp
@@ -44,11 +44,9 @@
#include <Qt3DInput/qaxissetting.h>
#include <Qt3DInput/qinputaspect.h>
#include <Qt3DInput/qphysicaldevicecreatedchange.h>
-#include <Qt3DCore/qpropertynodeaddedchange.h>
-#include <Qt3DCore/qpropertynoderemovedchange.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <cmath>
+#include <algorithm>
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
@@ -132,51 +130,14 @@ Input::AxisSetting *QAbstractPhysicalDeviceBackendNodePrivate::getAxisSetting(Qt
return axisSetting;
}
-QVector<Input::AxisIdSetting> QAbstractPhysicalDeviceBackendNodePrivate::convertToAxisIdSettingVector(Qt3DCore::QNodeId axisSettingId) const
-{
- const auto axisSetting = getAxisSetting(axisSettingId);
- const auto axisIds = axisSetting->axes();
-
- auto result = QVector<Input::AxisIdSetting>();
- result.reserve(axisIds.size());
- std::transform(axisIds.constBegin(), axisIds.constEnd(),
- std::back_inserter(result),
- [axisSettingId] (int axisId) {
- return Input::AxisIdSetting{ axisId, axisSettingId };
- });
- return result;
-}
-
-void QAbstractPhysicalDeviceBackendNodePrivate::updatePendingAxisSettings()
-{
- if (m_pendingAxisSettingIds.isEmpty())
- return;
-
- m_axisSettings = std::accumulate(
- m_pendingAxisSettingIds.constBegin(), m_pendingAxisSettingIds.constEnd(),
- QVector<Input::AxisIdSetting>(),
- [this] (const QVector<Input::AxisIdSetting> &current, Qt3DCore::QNodeId axisSettingId) {
- return current + convertToAxisIdSettingVector(axisSettingId);
- });
- m_pendingAxisSettingIds.clear();
-}
-
QAbstractPhysicalDeviceBackendNode::QAbstractPhysicalDeviceBackendNode(QBackendNode::Mode mode)
- : Qt3DCore::QBackendNode(*new QAbstractPhysicalDeviceBackendNodePrivate(mode))
+ : Input::BackendNode(*new QAbstractPhysicalDeviceBackendNodePrivate(mode))
{
}
QAbstractPhysicalDeviceBackendNode::QAbstractPhysicalDeviceBackendNode(QAbstractPhysicalDeviceBackendNodePrivate &dd)
- : Qt3DCore::QBackendNode(dd)
-{
-}
-
-void QAbstractPhysicalDeviceBackendNode::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
+ : Input::BackendNode(dd)
{
- const auto deviceChange = qSharedPointerCast<QPhysicalDeviceCreatedChangeBase>(change);
- Q_D(QAbstractPhysicalDeviceBackendNode);
- // Store the axis setting Ids. We will update the settings themselves when needed
- d->m_pendingAxisSettingIds = deviceChange->axisSettingIds();
}
void QAbstractPhysicalDeviceBackendNode::cleanup()
@@ -188,33 +149,34 @@ void QAbstractPhysicalDeviceBackendNode::cleanup()
d->m_inputAspect = nullptr;
}
-void QAbstractPhysicalDeviceBackendNode::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void QAbstractPhysicalDeviceBackendNode::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
Q_D(QAbstractPhysicalDeviceBackendNode);
- switch (e->type()) {
- case Qt3DCore::PropertyValueAdded: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("axisSettings")) {
- const auto axisSettingId = change->addedNodeId();
- Input::AxisSetting *axisSetting = d->getAxisSetting(axisSettingId);
- const auto axisIds = axisSetting->axes();
- for (int axisId : axisIds)
- d->addAxisSetting(axisId, axisSettingId);
- }
- break;
- }
-
- case Qt3DCore::PropertyValueRemoved: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("axisSettings"))
- d->removeAxisSetting(change->removedNodeId());
- break;
- }
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const Qt3DInput::QAbstractPhysicalDevice *node = qobject_cast<const Qt3DInput::QAbstractPhysicalDevice *>(frontEnd);
+ if (!node)
+ return;
- default:
- break;
+ auto settings = Qt3DCore::qIdsForNodes(node->axisSettings());
+ std::sort(std::begin(settings), std::end(settings));
+ Qt3DCore::QNodeIdVector addedSettings;
+ Qt3DCore::QNodeIdVector removedSettings;
+ std::set_difference(std::begin(settings), std::end(settings),
+ std::begin(d->m_currentAxisSettingIds), std::end(d->m_currentAxisSettingIds),
+ std::inserter(addedSettings, addedSettings.end()));
+ std::set_difference(std::begin(d->m_currentAxisSettingIds), std::end(d->m_currentAxisSettingIds),
+ std::begin(settings), std::end(settings),
+ std::inserter(removedSettings, removedSettings.end()));
+ d->m_currentAxisSettingIds = settings;
+
+ for (const auto &axisSettingId: qAsConst(addedSettings)) {
+ Input::AxisSetting *axisSetting = d->getAxisSetting(axisSettingId);
+ const auto axisIds = axisSetting->axes();
+ for (int axisId : axisIds)
+ d->addAxisSetting(axisId, axisSettingId);
}
- QBackendNode::sceneChangeEvent(e);
+ for (const auto &axisSettingId: qAsConst(removedSettings))
+ d->removeAxisSetting(axisSettingId);
}
void QAbstractPhysicalDeviceBackendNode::setInputAspect(QInputAspect *aspect)
@@ -232,7 +194,6 @@ QInputAspect *QAbstractPhysicalDeviceBackendNode::inputAspect() const
float QAbstractPhysicalDeviceBackendNode::processedAxisValue(int axisIdentifier)
{
Q_D(QAbstractPhysicalDeviceBackendNode);
- d->updatePendingAxisSettings();
// Find axis settings for this axis (if any)
Qt3DCore::QNodeId axisSettingId;
diff --git a/src/input/backend/qabstractphysicaldevicebackendnode_p.h b/src/input/backend/qabstractphysicaldevicebackendnode_p.h
index e8e397883..ff46cf814 100644
--- a/src/input/backend/qabstractphysicaldevicebackendnode_p.h
+++ b/src/input/backend/qabstractphysicaldevicebackendnode_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/private/backendnode_p.h>
#include <Qt3DInput/private/qt3dinput_global_p.h>
@@ -66,12 +66,12 @@ namespace Qt3DInput {
class QInputAspect;
class QAbstractPhysicalDeviceBackendNodePrivate;
-class Q_3DINPUTSHARED_PRIVATE_EXPORT QAbstractPhysicalDeviceBackendNode : public Qt3DCore::QBackendNode
+class Q_3DINPUTSHARED_PRIVATE_EXPORT QAbstractPhysicalDeviceBackendNode : public Input::BackendNode
{
public:
explicit QAbstractPhysicalDeviceBackendNode(QBackendNode::Mode mode);
virtual void cleanup();
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
void setInputAspect(QInputAspect *aspect);
QInputAspect *inputAspect() const;
@@ -83,8 +83,6 @@ public:
protected:
QAbstractPhysicalDeviceBackendNode(QAbstractPhysicalDeviceBackendNodePrivate &dd);
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) override;
-
Q_DECLARE_PRIVATE(QAbstractPhysicalDeviceBackendNode)
};
diff --git a/src/input/backend/qabstractphysicaldevicebackendnode_p_p.h b/src/input/backend/qabstractphysicaldevicebackendnode_p_p.h
index 4b0c47b36..9156fc64d 100644
--- a/src/input/backend/qabstractphysicaldevicebackendnode_p_p.h
+++ b/src/input/backend/qabstractphysicaldevicebackendnode_p_p.h
@@ -97,10 +97,7 @@ public:
Input::AxisSetting *getAxisSetting(Qt3DCore::QNodeId axisSettingId) const;
- QVector<Input::AxisIdSetting> convertToAxisIdSettingVector(Qt3DCore::QNodeId axisSettingId) const;
- void updatePendingAxisSettings();
-
- Qt3DCore::QNodeIdVector m_pendingAxisSettingIds;
+ Qt3DCore::QNodeIdVector m_currentAxisSettingIds;
QVector<Input::AxisIdSetting> m_axisSettings;
QVector<Input::AxisIdFilter> m_axisFilters;
QInputAspect *m_inputAspect;
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);