Android: Fix joypad trigger value range
`Input::joy_axis` converts trigger values to be between 0.0f to 1.0f by default. This is not needed for Android, as values are already within that range, as per Android documentation: https://developer.android.com/reference/android/view/MotionEvent#AXIS_RTRIGGER
This patch prevents this conversion on Android, which caused L2 and R2 triggers to get stuck pressed. https://github.com/godotengine/godot/issues/79263
(cherry picked from commit d413a02079
)
This commit is contained in:
parent
a285553472
commit
76d5a0e723
|
@ -1060,7 +1060,8 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value);
|
JoyAxisRange range;
|
||||||
|
JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value, range);
|
||||||
|
|
||||||
if (map.type == TYPE_BUTTON) {
|
if (map.type == TYPE_BUTTON) {
|
||||||
bool pressed = map.value > 0.5;
|
bool pressed = map.value > 0.5;
|
||||||
|
@ -1100,7 +1101,7 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) {
|
||||||
if (map.type == TYPE_AXIS) {
|
if (map.type == TYPE_AXIS) {
|
||||||
JoyAxis axis = JoyAxis(map.index);
|
JoyAxis axis = JoyAxis(map.index);
|
||||||
float value = map.value;
|
float value = map.value;
|
||||||
if (axis == JoyAxis::TRIGGER_LEFT || axis == JoyAxis::TRIGGER_RIGHT) {
|
if (range == FULL_AXIS && (axis == JoyAxis::TRIGGER_LEFT || axis == JoyAxis::TRIGGER_RIGHT)) {
|
||||||
// Convert to a value between 0.0f and 1.0f.
|
// Convert to a value between 0.0f and 1.0f.
|
||||||
value = 0.5f + value / 2.0f;
|
value = 0.5f + value / 2.0f;
|
||||||
}
|
}
|
||||||
|
@ -1206,7 +1207,7 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping,
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value) {
|
Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value, JoyAxisRange &r_range) {
|
||||||
JoyEvent event;
|
JoyEvent event;
|
||||||
|
|
||||||
for (int i = 0; i < mapping.bindings.size(); i++) {
|
for (int i = 0; i < mapping.bindings.size(); i++) {
|
||||||
|
@ -1252,6 +1253,7 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, J
|
||||||
case TYPE_AXIS:
|
case TYPE_AXIS:
|
||||||
event.index = (int)binding.output.axis.axis;
|
event.index = (int)binding.output.axis.axis;
|
||||||
event.value = value;
|
event.value = value;
|
||||||
|
r_range = binding.output.axis.range;
|
||||||
if (binding.output.axis.range != binding.input.axis.range) {
|
if (binding.output.axis.range != binding.input.axis.range) {
|
||||||
switch (binding.output.axis.range) {
|
switch (binding.output.axis.range) {
|
||||||
case POSITIVE_HALF_AXIS:
|
case POSITIVE_HALF_AXIS:
|
||||||
|
|
|
@ -219,7 +219,7 @@ private:
|
||||||
Vector<JoyDeviceMapping> map_db;
|
Vector<JoyDeviceMapping> map_db;
|
||||||
|
|
||||||
JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button);
|
JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button);
|
||||||
JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value);
|
JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value, JoyAxisRange &r_range);
|
||||||
void _get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[(size_t)HatDir::MAX]);
|
void _get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[(size_t)HatDir::MAX]);
|
||||||
JoyButton _get_output_button(String output);
|
JoyButton _get_output_button(String output);
|
||||||
JoyAxis _get_output_axis(String output);
|
JoyAxis _get_output_axis(String output);
|
||||||
|
|
Loading…
Reference in New Issue