diff options
Diffstat (limited to 'core/input/input.cpp')
-rw-r--r-- | core/input/input.cpp | 34 |
1 files changed, 12 insertions, 22 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) { |