Fix game controllers ignoring the last listed button

(cherry picked from commit 18825ad4ff)
This commit is contained in:
Marcel Admiraal 2021-05-21 17:17:42 +01:00 committed by Rémi Verschelde
parent f7e9467441
commit 3c55a9c210
No known key found for this signature in database
GPG Key ID: C3336907360768E1
6 changed files with 28 additions and 18 deletions

View File

@ -415,6 +415,7 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_19);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_20);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_21);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_22);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_MAX);
BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_CIRCLE);
@ -448,6 +449,7 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_DOWN);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_LEFT);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_RIGHT);
BIND_GLOBAL_ENUM_CONSTANT(JOY_GUIDE);
BIND_GLOBAL_ENUM_CONSTANT(JOY_MISC1);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE1);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE2);

View File

@ -85,7 +85,8 @@ enum JoystickList {
JOY_BUTTON_19 = 19,
JOY_BUTTON_20 = 20,
JOY_BUTTON_21 = 21,
JOY_BUTTON_MAX = 22,
JOY_BUTTON_22 = 22,
JOY_BUTTON_MAX = 23,
JOY_L = JOY_BUTTON_4,
JOY_R = JOY_BUTTON_5,
@ -99,12 +100,13 @@ enum JoystickList {
JOY_DPAD_DOWN = JOY_BUTTON_13,
JOY_DPAD_LEFT = JOY_BUTTON_14,
JOY_DPAD_RIGHT = JOY_BUTTON_15,
JOY_MISC1 = JOY_BUTTON_16,
JOY_PADDLE1 = JOY_BUTTON_17,
JOY_PADDLE2 = JOY_BUTTON_18,
JOY_PADDLE3 = JOY_BUTTON_19,
JOY_PADDLE4 = JOY_BUTTON_20,
JOY_TOUCHPAD = JOY_BUTTON_21,
JOY_GUIDE = JOY_BUTTON_16,
JOY_MISC1 = JOY_BUTTON_17,
JOY_PADDLE1 = JOY_BUTTON_18,
JOY_PADDLE2 = JOY_BUTTON_19,
JOY_PADDLE3 = JOY_BUTTON_20,
JOY_PADDLE4 = JOY_BUTTON_21,
JOY_TOUCHPAD = JOY_BUTTON_22,
JOY_SONY_CIRCLE = JOY_BUTTON_1,
JOY_SONY_X = JOY_BUTTON_0,

View File

@ -1003,7 +1003,10 @@
<constant name="JOY_BUTTON_21" value="21" enum="JoystickList">
Gamepad button 21.
</constant>
<constant name="JOY_BUTTON_MAX" value="22" enum="JoystickList">
<constant name="JOY_BUTTON_22" value="22" enum="JoystickList">
Gamepad button 22.
</constant>
<constant name="JOY_BUTTON_MAX" value="23" enum="JoystickList">
Represents the maximum number of joystick buttons supported.
</constant>
<constant name="JOY_SONY_CIRCLE" value="1" enum="JoystickList">
@ -1081,22 +1084,25 @@
<constant name="JOY_DPAD_RIGHT" value="15" enum="JoystickList">
Gamepad DPad right.
</constant>
<constant name="JOY_MISC1" value="16" enum="JoystickList">
<constant name="JOY_GUIDE" value="16" enum="JoystickList">
Gamepad SDL guide button.
</constant>
<constant name="JOY_MISC1" value="17" enum="JoystickList">
Gamepad SDL miscellaneous button.
</constant>
<constant name="JOY_PADDLE1" value="17" enum="JoystickList">
<constant name="JOY_PADDLE1" value="18" enum="JoystickList">
Gamepad SDL paddle 1 button.
</constant>
<constant name="JOY_PADDLE2" value="18" enum="JoystickList">
<constant name="JOY_PADDLE2" value="19" enum="JoystickList">
Gamepad SDL paddle 2 button.
</constant>
<constant name="JOY_PADDLE3" value="19" enum="JoystickList">
<constant name="JOY_PADDLE3" value="20" enum="JoystickList">
Gamepad SDL paddle 3 button.
</constant>
<constant name="JOY_PADDLE4" value="20" enum="JoystickList">
<constant name="JOY_PADDLE4" value="21" enum="JoystickList">
Gamepad SDL paddle 4 button.
</constant>
<constant name="JOY_TOUCHPAD" value="21" enum="JoystickList">
<constant name="JOY_TOUCHPAD" value="22" enum="JoystickList">
Gamepad SDL touchpad button.
</constant>
<constant name="JOY_L" value="4" enum="JoystickList">

View File

@ -60,6 +60,7 @@ static const char *_button_names[JOY_BUTTON_MAX] = {
"D-Pad Down",
"D-Pad Left",
"D-Pad Right",
"Home, DualShock PS, Guide",
"Xbox Share, PS5 Microphone, Nintendo Capture",
"Xbox Paddle 1",
"Xbox Paddle 2",

View File

@ -1304,6 +1304,7 @@ static const char *_buttons[JOY_BUTTON_MAX] = {
"DPAD Down",
"DPAD Left",
"DPAD Right",
"Guide",
"Misc 1",
"Paddle 1",
"Paddle 2",

View File

@ -83,7 +83,7 @@ class InputDefault : public Input {
StringName name;
StringName uid;
bool connected;
bool last_buttons[JOY_BUTTON_MAX + 13]; //apparently SDL specifies 35 possible buttons on android
bool last_buttons[JOY_BUTTON_MAX + 12]; //apparently SDL specifies 35 possible buttons on android
float last_axis[JOY_AXIS_MAX];
int last_hat;
int mapping;
@ -91,11 +91,9 @@ class InputDefault : public Input {
Joypad() {
for (int i = 0; i < JOY_AXIS_MAX; i++) {
last_axis[i] = 0.0f;
}
for (int i = 0; i < JOY_BUTTON_MAX + 13; i++) {
for (int i = 0; i < JOY_BUTTON_MAX + 12; i++) {
last_buttons[i] = false;
}
connected = false;