summaryrefslogtreecommitdiffstats
path: root/platform/windows/joypad.cpp
diff options
context:
space:
mode:
authorAndreas Haas <liu.gam3@gmail.com>2017-02-21 17:02:49 +0100
committerAndreas Haas <liu.gam3@gmail.com>2017-02-26 21:01:31 +0100
commita175ac7032407af8e0ffe9fcb23edd5b57c6548f (patch)
tree55b9a768892e2c01d15075b1a7861eae078ce009 /platform/windows/joypad.cpp
parentde0045cf1b0a5e20fbf74da192039d344ee8d0c7 (diff)
downloadredot-engine-a175ac7032407af8e0ffe9fcb23edd5b57c6548f.tar.gz
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
Diffstat (limited to 'platform/windows/joypad.cpp')
-rw-r--r--platform/windows/joypad.cpp14
1 files changed, 2 insertions, 12 deletions
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;