(MFI_joypad) Cleanups

This commit is contained in:
twinaphex 2020-09-11 12:39:05 +02:00
parent ab9202c0aa
commit 7c36e615c2
1 changed files with 92 additions and 75 deletions

View File

@ -98,7 +98,8 @@ static void apple_gamecontroller_joypad_poll_internal(GCController *controller)
*buttons |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
*buttons |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 120100 || __TV_OS_VERSION_MAX_ALLOWED >= 120100
if (@available(iOS 12.1, *)) {
if (@available(iOS 12.1, *))
{
*buttons |= gp.leftThumbstickButton.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L3) : 0;
*buttons |= gp.rightThumbstickButton.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R3) : 0;
}
@ -115,18 +116,18 @@ static void apple_gamecontroller_joypad_poll_internal(GCController *controller)
// LS + Menu => Select
// LT + Menu => L3
// RT + Menu => R3
if ( gp.buttonMenu.pressed ) {
if ( gp.leftShoulder.pressed ) {
if (gp.buttonMenu.pressed )
{
if (gp.leftShoulder.pressed)
*buttons |= 1 << RETRO_DEVICE_ID_JOYPAD_SELECT;
} else if ( gp.leftTrigger.pressed ) {
else if (gp.leftTrigger.pressed)
*buttons |= 1 << RETRO_DEVICE_ID_JOYPAD_L3;
} else if ( gp.rightTrigger.pressed ) {
else if (gp.rightTrigger.pressed)
*buttons |= 1 << RETRO_DEVICE_ID_JOYPAD_R3;
} else {
else
*buttons |= 1 << RETRO_DEVICE_ID_JOYPAD_START;
}
}
}
#endif
mfi_axes[slot][0] = gp.leftThumbstick.xAxis.value * 32767.0f;
@ -168,22 +169,31 @@ static void apple_gamecontroller_joypad_register(GCGamepad *gamepad)
apple_gamecontroller_joypad_poll_internal(updateGamepad.controller);
};
if (@available(iOS 13, *)) {
if (@available(iOS 13, *))
{
// controllerPausedHandler is deprecated in favor of being able to deal with the menu
// button as any other button
return;
} else {
}
else
{
gamepad.controller.controllerPausedHandler = ^(GCController *controller)
{
uint32_t slot = (uint32_t)controller.playerIndex;
// Support buttons that aren't supported by the mFi controller via "hotkey" combinations:
//
// LS + Menu => Select
// LT + Menu => L3
// RT + Menu => R3
// Note that these are just button presses, and it does not simulate holding down the button
if ( controller.gamepad.leftShoulder.pressed || controller.extendedGamepad.leftShoulder.pressed ) {
/* Support buttons that aren't supported by the mFi
* controller via "hotkey" combinations:
*
* LS + Menu => Select
* LT + Menu => L3
* RT + Menu => R3
* Note that these are just button presses, and it
* does not simulate holding down the button
*/
if ( controller.gamepad.leftShoulder.pressed
|| controller.extendedGamepad.leftShoulder.pressed )
{
mfi_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START);
mfi_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_L);
mfi_buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_SELECT);
@ -192,7 +202,9 @@ static void apple_gamecontroller_joypad_register(GCGamepad *gamepad)
});
return;
}
if ( controller.extendedGamepad.leftTrigger.pressed ) {
if (controller.extendedGamepad.leftTrigger.pressed )
{
mfi_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_L2);
mfi_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START);
mfi_buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_L3);
@ -201,7 +213,9 @@ static void apple_gamecontroller_joypad_register(GCGamepad *gamepad)
});
return;
}
if ( controller.extendedGamepad.rightTrigger.pressed ) {
if (controller.extendedGamepad.rightTrigger.pressed )
{
mfi_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_R2);
mfi_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START);
mfi_buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_R3);
@ -216,8 +230,7 @@ static void apple_gamecontroller_joypad_register(GCGamepad *gamepad)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
mfi_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START);
});
};
}
}
}
@ -233,9 +246,9 @@ static void apple_gamecontroller_joypad_connect(GCController *controller)
? desired_index : 0;
/* prevent same controller getting set twice */
if ( [mfiControllers containsObject:controller] ) {
if ([mfiControllers containsObject:controller])
return;
}
if (mfi_controllers[desired_index] != (uint32_t)controller.hash)
{
/* desired slot is unused, take it */
@ -262,25 +275,29 @@ static void apple_gamecontroller_joypad_connect(GCController *controller)
[mfiControllers addObject:controller];
// move any non-game controllers (like the siri remote) to the end
if ( mfiControllers.count > 1 ) {
if (mfiControllers.count > 1)
{
int newPlayerIndex = 0;
NSInteger connectedNonGameControllerIndex = NSNotFound;
NSUInteger index = 0;
for (GCController *connectedController in mfiControllers) {
if ( connectedController.gamepad == nil && connectedController.extendedGamepad == nil ) {
for (GCController *connectedController in mfiControllers)
{
if ( connectedController.gamepad == nil
&& connectedController.extendedGamepad == nil )
connectedNonGameControllerIndex = index;
}
index++;
}
if ( connectedNonGameControllerIndex != NSNotFound ) {
if (connectedNonGameControllerIndex != NSNotFound)
{
GCController *nonGameController = [mfiControllers objectAtIndex:connectedNonGameControllerIndex];
[mfiControllers removeObjectAtIndex:connectedNonGameControllerIndex];
[mfiControllers addObject:nonGameController];
}
int newPlayerIndex = 0;
for (GCController *gc in mfiControllers) {
for (GCController *gc in mfiControllers)
gc.playerIndex = newPlayerIndex++;
}
}
apple_gamecontroller_joypad_register(controller.gamepad);
mfi_joypad_autodetect_add(controller.playerIndex);