From 8c06da0d49825dd4cbdd48f0cb7f2bb80b10a56e Mon Sep 17 00:00:00 2001 From: Andreas Haas Date: Sat, 25 Mar 2017 23:41:00 +0100 Subject: Better handling of joypad device IDs. Now InputDefault is responsible for giving out joypad device IDs to the platform, instead of each platform handling this itself. This makes it possible for c++ modules to add their own "custom" gamepad devices, without the risk of messing up events in case the user also has regular gamepads attached (using the OS code). For now, it's implemented for the main desktop platforms. Possible targets for future work: android, uwp, javascript --- main/input_default.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'main/input_default.cpp') diff --git a/main/input_default.cpp b/main/input_default.cpp index 1c4b8f8e5..61169985b 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -1157,6 +1157,15 @@ int InputDefault::get_joy_button_index_from_string(String p_button) { ERR_FAIL_V(-1); } +int InputDefault::get_unused_joy_id() { + for (int i = 0; i < JOYSTICKS_MAX; i++) { + if (!joy_names.has(i) || !joy_names[i].connected) { + return i; + } + } + return -1; +} + String InputDefault::get_joy_axis_string(int p_axis) { ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, ""); return _axes[p_axis]; -- cgit v1.2.3-70-g09d2