summaryrefslogtreecommitdiffstats
path: root/core/input
diff options
context:
space:
mode:
authorMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2024-11-20 09:18:55 +0100
committerMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2024-11-20 09:18:55 +0100
commitbc5e2f9b96eff14e25514ebca072e3ffe75c2451 (patch)
tree77f0098f743aed591bdeadfe0320d7ba524a4638 /core/input
parenta0cd8f187a43935d756e49bf3778f39f0964f0ac (diff)
downloadredot-engine-bc5e2f9b96eff14e25514ebca072e3ffe75c2451.tar.gz
Revert "Fix InputEvent device id clash" and add a compatibility function
This reverts commit 916d480686e339746ac4fc89079c26fe72caad53. Revert "Fix InputEvent crash when opening project" This reverts commit abb9c0f171c7150a510ca2c2a744534f1746635d. Introduce a compatibility function for projects affected by the device id clash reversal Since the reverted PR introduced changes in the project.godot file, it seems prudent to introduce a compatibility function for such affected projects.
Diffstat (limited to 'core/input')
-rw-r--r--core/input/input_event.cpp3
-rw-r--r--core/input/input_event.h5
-rw-r--r--core/input/input_map.cpp4
-rw-r--r--core/input/input_map.h5
4 files changed, 13 insertions, 4 deletions
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 4733aaf220..045ac83cd8 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -35,6 +35,9 @@
#include "core/os/keyboard.h"
#include "core/os/os.h"
+const int InputEvent::DEVICE_ID_EMULATION = -1;
+const int InputEvent::DEVICE_ID_INTERNAL = -2;
+
void InputEvent::set_device(int p_device) {
device = p_device;
emit_changed();
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 80bca28fbf..19176f748e 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -62,9 +62,8 @@ protected:
static void _bind_methods();
public:
- inline static constexpr int DEVICE_ID_EMULATION = -1;
- inline static constexpr int DEVICE_ID_INTERNAL = -2;
- inline static constexpr int DEVICE_ID_ALL_DEVICES = -3; // Signify that a given Action can be triggered by any device.
+ static const int DEVICE_ID_EMULATION;
+ static const int DEVICE_ID_INTERNAL;
void set_device(int p_device);
int get_device() const;
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index 54f20a0bcc..abd2c80ce1 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -39,6 +39,8 @@
InputMap *InputMap::singleton = nullptr;
+int InputMap::ALL_DEVICES = -1;
+
void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
@@ -161,7 +163,7 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re
int i = 0;
for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) {
int device = E->get()->get_device();
- if (device == InputEvent::DEVICE_ID_ALL_DEVICES || device == p_event->get_device()) {
+ if (device == ALL_DEVICES || device == p_event->get_device()) {
if (E->get()->action_match(p_event, p_exact_match, p_action.deadzone, r_pressed, r_strength, r_raw_strength)) {
if (r_event_index) {
*r_event_index = i;
diff --git a/core/input/input_map.h b/core/input/input_map.h
index 2b2a025332..0479d45c57 100644
--- a/core/input/input_map.h
+++ b/core/input/input_map.h
@@ -43,6 +43,11 @@ class InputMap : public Object {
GDCLASS(InputMap, Object);
public:
+ /**
+ * A special value used to signify that a given Action can be triggered by any device
+ */
+ static int ALL_DEVICES;
+
struct Action {
int id;
float deadzone;