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:
@ -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),
|
||||
|
||||
Reference in New Issue
Block a user