summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorMarcel Admiraal <madmiraal@users.noreply.github.com>2020-04-23 13:01:36 +0100
committerMarcel Admiraal <madmiraal@users.noreply.github.com>2020-05-13 10:33:32 +0100
commite7fee711b3d2417720ecfae86bc9351927f6daa0 (patch)
treeae98dc80389fa088c9fe57bb68c77b80ce35c62f /core
parent1176e078b965994964e7699efd41d9a8958db6da (diff)
Update game controller enums.
Diffstat (limited to 'core')
-rw-r--r--core/global_constants.cpp133
-rw-r--r--core/input/input.cpp248
-rw-r--r--core/input/input.h49
-rw-r--r--core/input/input_event.h170
-rw-r--r--core/project_settings.cpp14
5 files changed, 282 insertions, 332 deletions
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index afcb283e05..4f415a2056 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -88,7 +88,8 @@ static Vector<_GlobalConstant> _global_constants;
VARIANT_ENUM_CAST(KeyList);
VARIANT_ENUM_CAST(KeyModifierMask);
VARIANT_ENUM_CAST(ButtonList);
-VARIANT_ENUM_CAST(JoystickList);
+VARIANT_ENUM_CAST(JoyButtonList);
+VARIANT_ENUM_CAST(JoyAxisList);
VARIANT_ENUM_CAST(MidiMessageList);
void register_global_constants() {
@@ -388,90 +389,70 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_XBUTTON1);
BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_XBUTTON2);
- //joypads
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_0);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_1);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_2);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_3);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_4);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_5);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_6);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_7);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_8);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_9);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_10);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_11);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_12);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_13);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_14);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_15);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_MAX);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_CIRCLE);
+ // Joypad buttons
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_INVALID_BUTTON);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_A);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_B);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_BACK);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_GUIDE);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_START);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_LEFT_STICK);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_RIGHT_STICK);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_LEFT_SHOULDER);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_RIGHT_SHOULDER);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_DPAD_UP);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_DPAD_DOWN);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_DPAD_LEFT);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_DPAD_RIGHT);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SDL_BUTTONS);
BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_CROSS);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_CIRCLE);
BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_SQUARE);
BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_TRIANGLE);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_B);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_SELECT);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_START);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_PS);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_L1);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_R1);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_L3);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_R3);
BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_A);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_B);
BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_X);
BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_BACK);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_START);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_HOME);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_LS);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_RS);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_LB);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_RB);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_MAX);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_A);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_B);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_X);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_Y);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_GRIP);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_PAD);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_TRIGGER);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_AX);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_BY);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_MENU);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_MENU);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_SELECT);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_START);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_UP);
- 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_L);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_L2);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_L3);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_R);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_R2);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_R3);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_0);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_1);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_2);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_3);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_4);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_5);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_6);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_7);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_8);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_9);
+ // Joypad axes
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_INVALID_AXIS);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_LEFT_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_LEFT_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_RIGHT_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_RIGHT_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_TRIGGER_LEFT);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_TRIGGER_RIGHT);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SDL_AXES);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_0_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_0_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_1_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_1_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_2_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_2_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_3_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_3_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_4_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_4_Y);
BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_MAX);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_LX);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_LY);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_RX);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_RY);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_L2);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_R2);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_ANALOG_TRIGGER);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_ANALOG_GRIP);
-
- BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_TOUCHPADX);
- BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_TOUCHPADY);
-
// midi
BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_OFF);
BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_ON);
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 8d0686cce4..97757cc965 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -39,6 +39,87 @@
#include "editor/editor_settings.h"
#endif
+static const char *_joy_buttons[JOY_SDL_BUTTONS + 1] = {
+ "a",
+ "b",
+ "x",
+ "y",
+ "back",
+ "guide",
+ "start",
+ "leftstick",
+ "rightstick",
+ "leftshoulder",
+ "rightshoulder",
+ "dpup",
+ "dpdown",
+ "dpleft",
+ "dpright",
+ nullptr
+};
+
+static const char *_joy_button_names[JOY_BUTTON_MAX] = {
+ "Face Bottom",
+ "Face Right",
+ "Face Left",
+ "Face Top",
+ "Select",
+ "Guide",
+ "Start",
+ "Left Stick",
+ "Right Stick",
+ "Left Shoulder",
+ "Right Shoulder",
+ "D-Pad Up",
+ "D-Pad Down",
+ "D-Pad Left",
+ "D-Pad Right",
+ "Button 15",
+ "Button 16",
+ "Button 17",
+ "Button 18",
+ "Button 19",
+ "Button 20",
+ "Button 21",
+ "Button 22",
+ "Button 23",
+ "Button 24",
+ "Button 25",
+ "Button 26",
+ "Button 27",
+ "Button 28",
+ "Button 29",
+ "Button 30",
+ "Button 31",
+ "Button 32",
+ "Button 33",
+ "Button 34",
+ "Button 35"
+};
+
+static const char *_joy_axes[JOY_SDL_AXES + 1] = {
+ "leftx",
+ "lefty",
+ "rightx",
+ "righty",
+ "lefttrigger",
+ "righttrigger",
+ nullptr
+};
+
+static const char *_joy_axis_names[JOY_AXIS_MAX] = {
+ "Left Stick X",
+ "Left Stick Y",
+ "Right Stick X",
+ "Right Stick Y",
+ "Left Trigger",
+ "Right Trigger",
+ "Joystick 3 Stick X",
+ "Joystick 3 Stick Y",
+ "Joystick 4 Stick X",
+ "Joystick 4 Stick Y"
+};
+
Input *Input::singleton = nullptr;
void (*Input::set_mouse_mode_func)(Input::MouseMode) = nullptr;
@@ -336,13 +417,12 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, S
} else {
js.connected = false;
for (int i = 0; i < JOY_BUTTON_MAX; i++) {
-
- if (i < JOY_AXIS_MAX)
- set_joy_axis(p_idx, i, 0.0f);
-
int c = _combine_device(i, p_idx);
joy_buttons_pressed.erase(c);
- };
+ }
+ for (int i = 0; i < JOY_AXIS_MAX; i++) {
+ set_joy_axis(p_idx, i, 0.0f);
+ }
};
joy_names[p_idx] = js;
@@ -892,23 +972,17 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis);
if (map.type == TYPE_BUTTON) {
- //send axis event for triggers
- if (map.index == JOY_L2 || map.index == JOY_R2) {
- float value = p_value.min == 0 ? p_value.value : 0.5f + p_value.value / 2.0f;
- int axis = map.index == JOY_L2 ? JOY_ANALOG_L2 : JOY_ANALOG_R2;
- _axis_event(p_device, axis, value);
- }
- if (map.index == JOY_DPAD_UP || map.index == JOY_DPAD_DOWN) {
+ if (map.index == JOY_BUTTON_DPAD_UP || map.index == JOY_BUTTON_DPAD_DOWN) {
bool pressed = p_value.value != 0.0f;
- int button = p_value.value < 0 ? JOY_DPAD_UP : JOY_DPAD_DOWN;
+ int button = p_value.value < 0 ? JOY_BUTTON_DPAD_UP : JOY_BUTTON_DPAD_DOWN;
if (!pressed) {
- if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_UP, p_device))) {
- _button_event(p_device, JOY_DPAD_UP, false);
+ if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_UP, p_device))) {
+ _button_event(p_device, JOY_BUTTON_DPAD_UP, false);
}
- if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_DOWN, p_device))) {
- _button_event(p_device, JOY_DPAD_DOWN, false);
+ if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_DOWN, p_device))) {
+ _button_event(p_device, JOY_BUTTON_DPAD_DOWN, false);
}
}
if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) {
@@ -917,16 +991,17 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
_button_event(p_device, button, true);
return;
}
- if (map.index == JOY_DPAD_LEFT || map.index == JOY_DPAD_RIGHT) {
+
+ if (map.index == JOY_BUTTON_DPAD_LEFT || map.index == JOY_BUTTON_DPAD_RIGHT) {
bool pressed = p_value.value != 0.0f;
- int button = p_value.value < 0 ? JOY_DPAD_LEFT : JOY_DPAD_RIGHT;
+ int button = p_value.value < 0 ? JOY_BUTTON_DPAD_LEFT : JOY_BUTTON_DPAD_RIGHT;
if (!pressed) {
- if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_LEFT, p_device))) {
- _button_event(p_device, JOY_DPAD_LEFT, false);
+ if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_LEFT, p_device))) {
+ _button_event(p_device, JOY_BUTTON_DPAD_LEFT, false);
}
- if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_RIGHT, p_device))) {
- _button_event(p_device, JOY_DPAD_RIGHT, false);
+ if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_RIGHT, p_device))) {
+ _button_event(p_device, JOY_BUTTON_DPAD_RIGHT, false);
}
}
if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) {
@@ -935,12 +1010,14 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
_button_event(p_device, button, true);
return;
}
+
float deadzone = p_value.min == 0 ? 0.5f : 0.0f;
bool pressed = p_value.value > deadzone;
if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) {
// button already pressed or released, this is an axis bounce value
return;
}
+
_button_event(p_device, map.index, pressed);
return;
}
@@ -961,19 +1038,19 @@ void Input::joy_hat(int p_device, int p_val) {
JoyEvent map[HAT_MAX];
map[HAT_UP].type = TYPE_BUTTON;
- map[HAT_UP].index = SDL_BUTTON_DPAD_UP;
+ map[HAT_UP].index = JOY_BUTTON_DPAD_UP;
map[HAT_UP].value = 0;
map[HAT_RIGHT].type = TYPE_BUTTON;
- map[HAT_RIGHT].index = SDL_BUTTON_DPAD_RIGHT;
+ map[HAT_RIGHT].index = JOY_BUTTON_DPAD_RIGHT;
map[HAT_RIGHT].value = 0;
map[HAT_DOWN].type = TYPE_BUTTON;
- map[HAT_DOWN].index = SDL_BUTTON_DPAD_DOWN;
+ map[HAT_DOWN].index = JOY_BUTTON_DPAD_DOWN;
map[HAT_DOWN].value = 0;
map[HAT_LEFT].type = TYPE_BUTTON;
- map[HAT_LEFT].index = SDL_BUTTON_DPAD_LEFT;
+ map[HAT_LEFT].index = JOY_BUTTON_DPAD_LEFT;
map[HAT_LEFT].value = 0;
if (joy.mapping != -1) {
@@ -1027,7 +1104,7 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping,
event.type = TYPE_MAX;
for (int i = 0; i < mapping.bindings.size(); i++) {
- const SDLExtendedJoyBind binding = mapping.bindings[i];
+ const JoyBinding binding = mapping.bindings[i];
if (binding.inputType == TYPE_BUTTON && binding.input.button == p_button) {
event.type = binding.outputType;
switch (binding.outputType) {
@@ -1051,7 +1128,7 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i
event.type = TYPE_MAX;
for (int i = 0; i < mapping.bindings.size(); i++) {
- const SDLExtendedJoyBind binding = mapping.bindings[i];
+ const JoyBinding binding = mapping.bindings[i];
if (binding.inputType == TYPE_AXIS && binding.input.axis.axis == p_axis) {
event.type = binding.outputType;
switch (binding.outputType) {
@@ -1072,7 +1149,7 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i
void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[]) {
for (int i = 0; i < mapping.bindings.size(); i++) {
- const SDLExtendedJoyBind binding = mapping.bindings[i];
+ const JoyBinding binding = mapping.bindings[i];
if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) {
int index;
@@ -1109,51 +1186,22 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J
}
}
-static const char *sdl_buttons[] = {
- "a",
- "b",
- "x",
- "y",
- "back",
- "guide",
- "start",
- "leftstick",
- "rightstick",
- "leftshoulder",
- "rightshoulder",
- "dpup",
- "dpdown",
- "dpleft",
- "dpright",
- nullptr
-};
+JoyButtonList Input::_get_output_button(String output) {
-Input::SDLJoyButton Input::_get_output_button(String output) {
-
- for (int i = 0; sdl_buttons[i]; i++) {
- if (output == sdl_buttons[i])
- return SDLJoyButton(i);
+ for (int i = 0; _joy_buttons[i]; i++) {
+ if (output == _joy_buttons[i])
+ return JoyButtonList(i);
}
- return SDLJoyButton::SDL_INVALID_BUTTON;
+ return JoyButtonList::JOY_INVALID_BUTTON;
}
-static const char *sdl_axes[] = {
- "leftx",
- "lefty",
- "rightx",
- "righty",
- "lefttrigger",
- "righttrigger",
- nullptr
-};
-
-Input::SDLJoyAxis Input::_get_output_axis(String output) {
+JoyAxisList Input::_get_output_axis(String output) {
- for (int i = 0; sdl_axes[i]; i++) {
- if (output == sdl_axes[i])
- return SDLJoyAxis(i);
+ for (int i = 0; _joy_axes[i]; i++) {
+ if (output == _joy_axes[i])
+ return JoyAxisList(i);
}
- return SDLJoyAxis::SDL_INVALID_AXIS;
+ return JoyAxisList::JOY_INVALID_AXIS;
}
void Input::parse_mapping(String p_mapping) {
@@ -1208,18 +1256,18 @@ void Input::parse_mapping(String p_mapping) {
if (input[input.length() - 1] == '~')
invert_axis = true;
- SDLJoyButton output_button = _get_output_button(output);
- SDLJoyAxis output_axis = _get_output_axis(output);
- ERR_CONTINUE_MSG(output_button == SDL_INVALID_BUTTON && output_axis == SDL_INVALID_AXIS,
+ JoyButtonList output_button = _get_output_button(output);
+ JoyAxisList output_axis = _get_output_axis(output);
+ ERR_CONTINUE_MSG(output_button == JOY_INVALID_BUTTON && output_axis == JOY_INVALID_AXIS,
String(entry[idx] + "\nUnrecognised output string: " + output));
- ERR_CONTINUE_MSG(output_button != SDL_INVALID_BUTTON && output_axis != SDL_INVALID_AXIS,
+ ERR_CONTINUE_MSG(output_button != JOY_INVALID_BUTTON && output_axis != JOY_INVALID_AXIS,
String("BUG: Output string matched both button and axis: " + output));
- SDLExtendedJoyBind binding;
- if (output_button != SDL_INVALID_BUTTON) {
+ JoyBinding binding;
+ if (output_button != JOY_INVALID_BUTTON) {
binding.outputType = TYPE_BUTTON;
binding.output.button = output_button;
- } else if (output_axis != SDL_INVALID_AXIS) {
+ } else if (output_axis != JOY_INVALID_AXIS) {
binding.outputType = TYPE_AXIS;
binding.output.axis.axis = output_axis;
binding.output.axis.range = output_range;
@@ -1316,50 +1364,18 @@ Array Input::get_connected_joypads() {
return ret;
}
-static const char *_buttons[JOY_BUTTON_MAX] = {
- "Face Button Bottom",
- "Face Button Right",
- "Face Button Left",
- "Face Button Top",
- "L",
- "R",
- "L2",
- "R2",
- "L3",
- "R3",
- "Select",
- "Start",
- "DPAD Up",
- "DPAD Down",
- "DPAD Left",
- "DPAD Right"
-};
-
-static const char *_axes[JOY_AXIS_MAX] = {
- "Left Stick X",
- "Left Stick Y",
- "Right Stick X",
- "Right Stick Y",
- "",
- "",
- "L2",
- "R2",
- "",
- ""
-};
-
String Input::get_joy_button_string(int p_button) {
- ERR_FAIL_INDEX_V(p_button, JOY_BUTTON_MAX, "");
- return _buttons[p_button];
+ ERR_FAIL_INDEX_V(p_button, JOY_BUTTON_MAX, "Invalid button");
+ return _joy_button_names[p_button];
}
int Input::get_joy_button_index_from_string(String p_button) {
for (int i = 0; i < JOY_BUTTON_MAX; i++) {
- if (p_button == _buttons[i]) {
+ if (p_button == _joy_button_names[i]) {
return i;
}
}
- ERR_FAIL_V(-1);
+ ERR_FAIL_V(JOY_INVALID_BUTTON);
}
int Input::get_unused_joy_id() {
@@ -1372,17 +1388,17 @@ int Input::get_unused_joy_id() {
}
String Input::get_joy_axis_string(int p_axis) {
- ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, "");
- return _axes[p_axis];
+ ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, "Invalid axis");
+ return _joy_axis_names[p_axis];
}
int Input::get_joy_axis_index_from_string(String p_axis) {
for (int i = 0; i < JOY_AXIS_MAX; i++) {
- if (p_axis == _axes[i]) {
+ if (p_axis == _joy_axis_names[i]) {
return i;
}
}
- ERR_FAIL_V(-1);
+ ERR_FAIL_V(JOY_INVALID_AXIS);
}
Input::Input() {
diff --git a/core/input/input.h b/core/input/input.h
index f95dff47a9..ef50973827 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -145,7 +145,7 @@ private:
StringName name;
StringName uid;
bool connected;
- bool last_buttons[JOY_BUTTON_MAX + 19]; //apparently SDL specifies 35 possible buttons on android
+ bool last_buttons[JOY_BUTTON_MAX];
float last_axis[JOY_AXIS_MAX];
float filter;
int last_hat;
@@ -154,11 +154,9 @@ private:
Joypad() {
for (int i = 0; i < JOY_AXIS_MAX; i++) {
-
last_axis[i] = 0.0f;
}
- for (int i = 0; i < JOY_BUTTON_MAX + 19; i++) {
-
+ for (int i = 0; i < JOY_BUTTON_MAX; i++) {
last_buttons[i] = false;
}
connected = false;
@@ -183,37 +181,6 @@ private:
TYPE_MAX,
};
- enum SDLJoyButton {
- SDL_INVALID_BUTTON = -1,
- SDL_BUTTON_A,
- SDL_BUTTON_B,
- SDL_BUTTON_X,
- SDL_BUTTON_Y,
- SDL_BUTTON_BACK,
- SDL_BUTTON_GUIDE,
- SDL_BUTTON_START,
- SDL_BUTTON_LEFTSTICK,
- SDL_BUTTON_RIGHTSTICK,
- SDL_BUTTON_LEFTSHOULDER,
- SDL_BUTTON_RIGHTSHOULDER,
- SDL_BUTTON_DPAD_UP,
- SDL_BUTTON_DPAD_DOWN,
- SDL_BUTTON_DPAD_LEFT,
- SDL_BUTTON_DPAD_RIGHT,
- SDL_BUTTON_MAX
- };
-
- enum SDLJoyAxis {
- SDL_INVALID_AXIS = -1,
- SDL_AXIS_LEFTX,
- SDL_AXIS_LEFTY,
- SDL_AXIS_RIGHTX,
- SDL_AXIS_RIGHTY,
- SDL_AXIS_TRIGGERLEFT,
- SDL_AXIS_TRIGGERRIGHT,
- SDL_AXIS_MAX,
- };
-
enum JoyAxisRange {
NEGATIVE_HALF_AXIS = -1,
FULL_AXIS = 0,
@@ -226,7 +193,7 @@ private:
int value;
};
- struct SDLExtendedJoyBind {
+ struct JoyBinding {
JoyType inputType;
union {
int button;
@@ -245,10 +212,10 @@ private:
JoyType outputType;
union {
- SDLJoyButton button;
+ JoyButtonList button;
struct {
- SDLJoyAxis axis;
+ JoyAxisList axis;
JoyAxisRange range;
} axis;
@@ -258,7 +225,7 @@ private:
struct JoyDeviceMapping {
String uid;
String name;
- Vector<SDLExtendedJoyBind> bindings;
+ Vector<JoyBinding> bindings;
};
Vector<JoyDeviceMapping> map_db;
@@ -266,8 +233,8 @@ private:
JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button);
JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis);
void _get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]);
- SDLJoyButton _get_output_button(String output);
- SDLJoyAxis _get_output_axis(String output);
+ JoyButtonList _get_output_button(String output);
+ JoyAxisList _get_output_axis(String output);
void _button_event(int p_device, int p_index, bool p_pressed);
void _axis_event(int p_device, int p_axis, float p_value);
float _handle_deadzone(int p_device, int p_axis, float p_value);
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 8774b3b1db..99ea2efee9 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -59,98 +59,84 @@ enum ButtonList {
BUTTON_MASK_XBUTTON2 = (1 << (BUTTON_XBUTTON2 - 1))
};
-enum JoystickList {
-
- JOY_BUTTON_0 = 0,
- JOY_BUTTON_1 = 1,
- JOY_BUTTON_2 = 2,
- JOY_BUTTON_3 = 3,
- JOY_BUTTON_4 = 4,
- JOY_BUTTON_5 = 5,
- JOY_BUTTON_6 = 6,
- JOY_BUTTON_7 = 7,
- JOY_BUTTON_8 = 8,
- JOY_BUTTON_9 = 9,
- JOY_BUTTON_10 = 10,
- JOY_BUTTON_11 = 11,
- JOY_BUTTON_12 = 12,
- JOY_BUTTON_13 = 13,
- JOY_BUTTON_14 = 14,
- JOY_BUTTON_15 = 15,
- JOY_BUTTON_MAX = 16,
-
- JOY_L = JOY_BUTTON_4,
- JOY_R = JOY_BUTTON_5,
- JOY_L2 = JOY_BUTTON_6,
- JOY_R2 = JOY_BUTTON_7,
- JOY_L3 = JOY_BUTTON_8,
- JOY_R3 = JOY_BUTTON_9,
- JOY_SELECT = JOY_BUTTON_10,
- JOY_START = JOY_BUTTON_11,
- JOY_DPAD_UP = JOY_BUTTON_12,
- JOY_DPAD_DOWN = JOY_BUTTON_13,
- JOY_DPAD_LEFT = JOY_BUTTON_14,
- JOY_DPAD_RIGHT = JOY_BUTTON_15,
-
- JOY_SONY_CIRCLE = JOY_BUTTON_1,
- JOY_SONY_X = JOY_BUTTON_0,
- JOY_SONY_SQUARE = JOY_BUTTON_2,
- JOY_SONY_TRIANGLE = JOY_BUTTON_3,
-
- JOY_XBOX_A = JOY_BUTTON_0,
- JOY_XBOX_B = JOY_BUTTON_1,
- JOY_XBOX_X = JOY_BUTTON_2,
- JOY_XBOX_Y = JOY_BUTTON_3,
-
- JOY_DS_A = JOY_BUTTON_1,
- JOY_DS_B = JOY_BUTTON_0,
- JOY_DS_X = JOY_BUTTON_3,
- JOY_DS_Y = JOY_BUTTON_2,
-
- JOY_WII_C = JOY_BUTTON_5,
- JOY_WII_Z = JOY_BUTTON_6,
-
- JOY_WII_MINUS = JOY_BUTTON_10,
- JOY_WII_PLUS = JOY_BUTTON_11,
-
- JOY_VR_GRIP = JOY_BUTTON_2,
- JOY_VR_PAD = JOY_BUTTON_14,
- JOY_VR_TRIGGER = JOY_BUTTON_15,
-
- JOY_OCULUS_AX = JOY_BUTTON_7,
- JOY_OCULUS_BY = JOY_BUTTON_1,
- JOY_OCULUS_MENU = JOY_BUTTON_3,
-
- JOY_OPENVR_MENU = JOY_BUTTON_1,
-
- // end of history
-
- JOY_AXIS_0 = 0,
- JOY_AXIS_1 = 1,
- JOY_AXIS_2 = 2,
- JOY_AXIS_3 = 3,
- JOY_AXIS_4 = 4,
- JOY_AXIS_5 = 5,
- JOY_AXIS_6 = 6,
- JOY_AXIS_7 = 7,
- JOY_AXIS_8 = 8,
- JOY_AXIS_9 = 9,
- JOY_AXIS_MAX = 10,
-
- JOY_ANALOG_LX = JOY_AXIS_0,
- JOY_ANALOG_LY = JOY_AXIS_1,
-
- JOY_ANALOG_RX = JOY_AXIS_2,
- JOY_ANALOG_RY = JOY_AXIS_3,
-
- JOY_ANALOG_L2 = JOY_AXIS_6,
- JOY_ANALOG_R2 = JOY_AXIS_7,
-
- JOY_VR_ANALOG_TRIGGER = JOY_AXIS_2,
- JOY_VR_ANALOG_GRIP = JOY_AXIS_4,
-
- JOY_OPENVR_TOUCHPADX = JOY_AXIS_0,
- JOY_OPENVR_TOUCHPADY = JOY_AXIS_1,
+enum JoyButtonList {
+
+ JOY_INVALID_BUTTON = -1,
+
+ // SDL Buttons
+ JOY_BUTTON_A = 0,
+ JOY_BUTTON_B = 1,
+ JOY_BUTTON_X = 2,
+ JOY_BUTTON_Y = 3,
+ JOY_BUTTON_BACK = 4,
+ JOY_BUTTON_GUIDE = 5,
+ JOY_BUTTON_START = 6,
+ JOY_BUTTON_LEFT_STICK = 7,
+ JOY_BUTTON_RIGHT_STICK = 8,
+ JOY_BUTTON_LEFT_SHOULDER = 9,
+ JOY_BUTTON_RIGHT_SHOULDER = 10,
+ JOY_BUTTON_DPAD_UP = 11,
+ JOY_BUTTON_DPAD_DOWN = 12,
+ JOY_BUTTON_DPAD_LEFT = 13,
+ JOY_BUTTON_DPAD_RIGHT = 14,
+ JOY_SDL_BUTTONS = 15,
+
+ // Sony Buttons
+ JOY_SONY_X = JOY_BUTTON_A,
+ JOY_SONY_CROSS = JOY_BUTTON_A,
+ JOY_SONY_CIRCLE = JOY_BUTTON_B,
+ JOY_SONY_SQUARE = JOY_BUTTON_X,
+ JOY_SONY_TRIANGLE = JOY_BUTTON_Y,
+ JOY_SONY_SELECT = JOY_BUTTON_BACK,
+ JOY_SONY_START = JOY_BUTTON_START,
+ JOY_SONY_PS = JOY_BUTTON_GUIDE,
+ JOY_SONY_L1 = JOY_BUTTON_LEFT_SHOULDER,
+ JOY_SONY_R1 = JOY_BUTTON_RIGHT_SHOULDER,
+ JOY_SONY_L3 = JOY_BUTTON_LEFT_STICK,
+ JOY_SONY_R3 = JOY_BUTTON_RIGHT_STICK,
+
+ // Xbox Buttons
+ JOY_XBOX_A = JOY_BUTTON_A,
+ JOY_XBOX_B = JOY_BUTTON_B,
+ JOY_XBOX_X = JOY_BUTTON_X,
+ JOY_XBOX_Y = JOY_BUTTON_Y,
+ JOY_XBOX_BACK = JOY_BUTTON_BACK,
+ JOY_XBOX_START = JOY_BUTTON_START,
+ JOY_XBOX_HOME = JOY_BUTTON_GUIDE,
+ JOY_XBOX_LS = JOY_BUTTON_LEFT_STICK,
+ JOY_XBOX_RS = JOY_BUTTON_RIGHT_STICK,
+ JOY_XBOX_LB = JOY_BUTTON_LEFT_SHOULDER,
+ JOY_XBOX_RB = JOY_BUTTON_RIGHT_SHOULDER,
+
+ JOY_BUTTON_MAX = 36 // Apparently Android supports up to 36 buttons.
+};
+
+enum JoyAxisList {
+
+ JOY_INVALID_AXIS = -1,
+
+ // SDL Axes
+ JOY_AXIS_LEFT_X = 0,
+ JOY_AXIS_LEFT_Y = 1,
+ JOY_AXIS_RIGHT_X = 2,
+ JOY_AXIS_RIGHT_Y = 3,
+ JOY_AXIS_TRIGGER_LEFT = 4,
+ JOY_AXIS_TRIGGER_RIGHT = 5,
+ JOY_SDL_AXES = 6,
+
+ // Joystick axes.
+ JOY_AXIS_0_X = 0,
+ JOY_AXIS_0_Y = 1,
+ JOY_AXIS_1_X = 2,
+ JOY_AXIS_1_Y = 3,
+ JOY_AXIS_2_X = 4,
+ JOY_AXIS_2_Y = 5,
+ JOY_AXIS_3_X = 6,
+ JOY_AXIS_3_Y = 7,
+ JOY_AXIS_4_X = 8,
+ JOY_AXIS_4_Y = 9,
+
+ JOY_AXIS_MAX = 10 // OpenVR supports up to 5 Joysticks making a total of 10 axes.
};
enum MidiMessageList {
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 8829181489..12522281d0 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -1037,7 +1037,7 @@ ProjectSettings::ProjectSettings() {
key->set_keycode(KEY_SPACE);
events.push_back(key);
joyb.instance();
- joyb->set_button_index(JOY_BUTTON_0);
+ joyb->set_button_index(JOY_BUTTON_A);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_accept", action);
@@ -1050,7 +1050,7 @@ ProjectSettings::ProjectSettings() {
key->set_keycode(KEY_SPACE);
events.push_back(key);
joyb.instance();
- joyb->set_button_index(JOY_BUTTON_3);
+ joyb->set_button_index(JOY_BUTTON_Y);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_select", action);
@@ -1063,7 +1063,7 @@ ProjectSettings::ProjectSettings() {
key->set_keycode(KEY_ESCAPE);
events.push_back(key);
joyb.instance();
- joyb->set_button_index(JOY_BUTTON_1);
+ joyb->set_button_index(JOY_BUTTON_B);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_cancel", action);
@@ -1097,7 +1097,7 @@ ProjectSettings::ProjectSettings() {
key->set_keycode(KEY_LEFT);
events.push_back(key);
joyb.instance();
- joyb->set_button_index(JOY_DPAD_LEFT);
+ joyb->set_button_index(JOY_BUTTON_DPAD_LEFT);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_left", action);
@@ -1110,7 +1110,7 @@ ProjectSettings::ProjectSettings() {
key->set_keycode(KEY_RIGHT);
events.push_back(key);
joyb.instance();
- joyb->set_button_index(JOY_DPAD_RIGHT);
+ joyb->set_button_index(JOY_BUTTON_DPAD_RIGHT);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_right", action);
@@ -1123,7 +1123,7 @@ ProjectSettings::ProjectSettings() {
key->set_keycode(KEY_UP);
events.push_back(key);
joyb.instance();
- joyb->set_button_index(JOY_DPAD_UP);
+ joyb->set_button_index(JOY_BUTTON_DPAD_UP);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_up", action);
@@ -1136,7 +1136,7 @@ ProjectSettings::ProjectSettings() {
key->set_keycode(KEY_DOWN);
events.push_back(key);
joyb.instance();
- joyb->set_button_index(JOY_DPAD_DOWN);
+ joyb->set_button_index(JOY_BUTTON_DPAD_DOWN);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_down", action);