summaryrefslogtreecommitdiff
path: root/core/input
diff options
context:
space:
mode:
authorMarcel Admiraal <madmiraal@users.noreply.github.com>2021-12-25 09:29:08 +0000
committerMarcel Admiraal <madmiraal@users.noreply.github.com>2022-01-14 15:36:20 +0000
commitf41c72c5384ff9ce34f60380d4f27b9af0904298 (patch)
treeb7c218ab98ea31284e85edecc543986fbae94e06 /core/input
parent6689a9360c2dae0ca940e4e470c4d0a0e0a9bef4 (diff)
Fix Actions mapped to triggers not using the full range
Diffstat (limited to 'core/input')
-rw-r--r--core/input/input.cpp34
-rw-r--r--core/input/input.h7
2 files changed, 13 insertions, 28 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 26df16792d..fa2f00bf8d 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -916,40 +916,25 @@ void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) {
// no event?
}
-void Input::joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value) {
+void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) {
_THREAD_SAFE_METHOD_;
ERR_FAIL_INDEX((int)p_axis, (int)JoyAxis::MAX);
Joypad &joy = joy_names[p_device];
- if (joy.last_axis[(size_t)p_axis] == p_value.value) {
+ if (joy.last_axis[(size_t)p_axis] == p_value) {
return;
}
- //when changing direction quickly, insert fake event to release pending inputmap actions
- float last = joy.last_axis[(size_t)p_axis];
- if (p_value.min == 0 && (last < 0.25 || last > 0.75) && (last - 0.5) * (p_value.value - 0.5) < 0) {
- JoyAxisValue jx;
- jx.min = p_value.min;
- jx.value = p_value.value < 0.5 ? 0.6 : 0.4;
- joy_axis(p_device, p_axis, jx);
- } else if (ABS(last) > 0.5 && last * p_value.value <= 0) {
- JoyAxisValue jx;
- jx.min = p_value.min;
- jx.value = last > 0 ? 0.1 : -0.1;
- joy_axis(p_device, p_axis, jx);
- }
-
- joy.last_axis[(size_t)p_axis] = p_value.value;
- float val = p_value.min == 0 ? -1.0f + 2.0f * p_value.value : p_value.value;
+ joy.last_axis[(size_t)p_axis] = p_value;
if (joy.mapping == -1) {
- _axis_event(p_device, p_axis, val);
+ _axis_event(p_device, p_axis, p_value);
return;
}
- JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, val);
+ JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value);
if (map.type == TYPE_BUTTON) {
bool pressed = map.value > 0.5;
@@ -989,10 +974,15 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value)
}
if (map.type == TYPE_AXIS) {
- _axis_event(p_device, (JoyAxis)map.index, map.value);
+ JoyAxis axis = JoyAxis(map.index);
+ float value = map.value;
+ if (axis == JoyAxis::TRIGGER_LEFT || axis == JoyAxis::TRIGGER_RIGHT) {
+ // Convert to a value between 0.0f and 1.0f.
+ value = 0.5f + value / 2.0f;
+ }
+ _axis_event(p_device, axis, value);
return;
}
- //printf("invalid mapping\n");
}
void Input::joy_hat(int p_device, HatMask p_val) {
diff --git a/core/input/input.h b/core/input/input.h
index 8b1d7d6161..e5ef31ab4f 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -77,11 +77,6 @@ public:
JOYPADS_MAX = 16,
};
- struct JoyAxisValue {
- int min;
- float value;
- };
-
typedef void (*EventDispatchFunc)(const Ref<InputEvent> &p_event);
private:
@@ -313,7 +308,7 @@ public:
void parse_mapping(String p_mapping);
void joy_button(int p_device, JoyButton p_button, bool p_pressed);
- void joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value);
+ void joy_axis(int p_device, JoyAxis p_axis, float p_value);
void joy_hat(int p_device, HatMask p_val);
void add_joy_mapping(String p_mapping, bool p_update_existing = false);