diff options
author | Andreas Haas <liu.gam3@gmail.com> | 2017-02-21 17:02:49 +0100 |
---|---|---|
committer | Andreas Haas <liu.gam3@gmail.com> | 2017-02-26 21:01:31 +0100 |
commit | a175ac7032407af8e0ffe9fcb23edd5b57c6548f (patch) | |
tree | 55b9a768892e2c01d15075b1a7861eae078ce009 /platform/osx | |
parent | de0045cf1b0a5e20fbf74da192039d344ee8d0c7 (diff) |
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/osx')
-rw-r--r-- | platform/osx/joypad_osx.cpp | 17 | ||||
-rw-r--r-- | platform/osx/joypad_osx.h | 3 |
2 files changed, 1 insertions, 19 deletions
diff --git a/platform/osx/joypad_osx.cpp b/platform/osx/joypad_osx.cpp index 5d25017aa6..98bcc8dc73 100644 --- a/platform/osx/joypad_osx.cpp +++ b/platform/osx/joypad_osx.cpp @@ -275,7 +275,6 @@ void JoypadOSX::_device_removed(int p_id) { input->joy_connection_changed(p_id, false, ""); device_list[device].free(); device_list.remove(device); - attached_devices[p_id] = false; } static String _hex_str(uint8_t p_byte) { @@ -307,7 +306,7 @@ bool JoypadOSX::configure_joypad(IOHIDDeviceRef p_device_ref, joypad* p_joy) { } name = c_name; - int id = get_free_joy_id(); + int id = input->get_unused_joy_id(); ERR_FAIL_COND_V(id == -1, false); p_joy->id = id; int vendor = 0; @@ -510,16 +509,6 @@ void JoypadOSX::joypad_vibration_stop(int p_id, uint64_t p_timestamp) { FFEffectStop(joy->ff_object); } -int JoypadOSX::get_free_joy_id() { - for (int i = 0; i < JOYPADS_MAX; i++) { - if (!attached_devices[i]) { - attached_devices[i] = true; - return i; - } - } - return -1; -} - int JoypadOSX::get_joy_index(int p_id) const { for (int i = 0; i < device_list.size(); i++) { if (device_list[i].id == p_id) return i; @@ -582,10 +571,6 @@ JoypadOSX::JoypadOSX() self = this; input = (InputDefault*)Input::get_singleton(); - for (int i = 0; i < JOYPADS_MAX; i++) { - attached_devices[i] = false; - } - int okay = 1; const void *vals[] = { (void *) create_match_dictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay), diff --git a/platform/osx/joypad_osx.h b/platform/osx/joypad_osx.h index aafd82880d..71a0335316 100644 --- a/platform/osx/joypad_osx.h +++ b/platform/osx/joypad_osx.h @@ -95,14 +95,11 @@ private: InputDefault *input; IOHIDManagerRef hid_manager; - bool attached_devices[JOYPADS_MAX]; Vector<joypad> device_list; bool have_device(IOHIDDeviceRef p_device) const; bool configure_joypad(IOHIDDeviceRef p_device_ref, joypad *p_joy); - - int get_free_joy_id(); int get_joy_index(int p_id) const; void poll_joypads() const; |