1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

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
This commit is contained in:
Andreas Haas
2017-03-25 23:41:00 +01:00
parent ed3134088b
commit 8c06da0d49
8 changed files with 20 additions and 42 deletions

View File

@@ -89,16 +89,6 @@ bool joystick_windows::have_device(const GUID &p_guid) {
return false;
}
int joystick_windows::check_free_joy_slot() const {
for (int i = 0; i < JOYSTICKS_MAX; i++) {
if (!attached_joysticks[i])
return i;
}
return -1;
}
// adapted from SDL2, works a lot better than the MSDN version
bool joystick_windows::is_xinput_device(const GUID *p_guid) {
@@ -147,7 +137,7 @@ bool joystick_windows::is_xinput_device(const GUID *p_guid) {
bool joystick_windows::setup_dinput_joystick(const DIDEVICEINSTANCE *instance) {
HRESULT hr;
int num = check_free_joy_slot();
int num = input->get_unused_joy_id();
if (have_device(instance->guidInstance) || num == -1)
return false;
@@ -295,7 +285,7 @@ void joystick_windows::probe_joysticks() {
dwResult = xinput_get_state(i, &x_joysticks[i].state);
if (dwResult == ERROR_SUCCESS) {
int id = check_free_joy_slot();
int id = input->get_unused_joy_id();
if (id != -1 && !x_joysticks[i].attached) {
x_joysticks[i].attached = true;