From a175ac7032407af8e0ffe9fcb23edd5b57c6548f Mon Sep 17 00:00:00 2001 From: Andreas Haas Date: Tue, 21 Feb 2017 17:02:49 +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 --- platform/windows/joypad.cpp | 14 ++------------ platform/windows/joypad.h | 1 - 2 files changed, 2 insertions(+), 13 deletions(-) (limited to 'platform/windows') diff --git a/platform/windows/joypad.cpp b/platform/windows/joypad.cpp index f2848268fc..4c1eeb425a 100644 --- a/platform/windows/joypad.cpp +++ b/platform/windows/joypad.cpp @@ -87,16 +87,6 @@ bool JoypadWindows::have_device(const GUID &p_guid) { return false; } -int JoypadWindows::check_free_joy_slot() const { - - for (int i = 0; i < JOYPADS_MAX; i++) { - - if (!attached_joypads[i]) - return i; - } - return -1; -} - // adapted from SDL2, works a lot better than the MSDN version bool JoypadWindows::is_xinput_device(const GUID *p_guid) { @@ -146,7 +136,7 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) { bool JoypadWindows::setup_dinput_joypad(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; @@ -296,7 +286,7 @@ void JoypadWindows::probe_joypads() { dwResult = xinput_get_state(i, &x_joypads[i].state); if ( dwResult == ERROR_SUCCESS) { - int id = check_free_joy_slot(); + int id = input->get_unused_joy_id(); if (id != -1 && !x_joypads[i].attached) { x_joypads[i].attached = true; diff --git a/platform/windows/joypad.h b/platform/windows/joypad.h index 63eee8c015..d6670c90db 100644 --- a/platform/windows/joypad.h +++ b/platform/windows/joypad.h @@ -132,7 +132,6 @@ private: void load_xinput(); void unload_xinput(); - int check_free_joy_slot() const; unsigned int post_hat(unsigned int p_last_id, int p_device, DWORD p_dpad); bool have_device(const GUID &p_guid); -- cgit v1.2.3