This commit is contained in:
libretroadmin 2023-02-20 13:21:17 +01:00
parent 23b8f3d97d
commit 2d2d96660a
2 changed files with 79 additions and 77 deletions

View File

@ -70,18 +70,16 @@ static void apple_gamecontroller_joypad_poll_internal(GCController *controller)
/* If we have not assigned a slot to this controller yet, ignore it. */
if (slot >= MAX_USERS)
return;
buttons = &mfi_buttons[slot];
/* retain the values from the paused controller handler and pass them through */
if (@available(iOS 13, *))
{
/* The menu button can be pressed/unpressed
* like any other button in iOS 13,
* so no need to passthrough anything */
if (@available(iOS 13, *))
*buttons = 0;
}
else
{
buttons = &mfi_buttons[slot];
/* Use the paused controller handler for iOS versions below 13 */
pause = *buttons & (1 << RETRO_DEVICE_ID_JOYPAD_START);
select = *buttons & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT);
@ -302,13 +300,13 @@ static void mfi_joypad_autodetect_add(unsigned autoconf_pad)
- (void)setupEngine MFI_RUMBLE_AVAIL
{
NSError *error;
if (self.engine)
return;
if (!self.controller)
return;
CHHapticEngine *engine = [self.controller.haptics createEngineWithLocality:GCHapticsLocalityDefault];
NSError *error;
[engine startAndReturnError:&error];
if (error)
return;
@ -316,7 +314,8 @@ static void mfi_joypad_autodetect_add(unsigned autoconf_pad)
self.engine = engine;
__weak MFIRumbleController *weakSelf = self;
self.engine.stoppedHandler = ^(CHHapticEngineStoppedReason stoppedReason) {
self.engine.stoppedHandler = ^(CHHapticEngineStoppedReason stoppedReason)
{
MFIRumbleController *strongSelf = weakSelf;
if (!strongSelf)
return;
@ -386,7 +385,8 @@ static void mfi_joypad_autodetect_add(unsigned autoconf_pad)
- (void)shutdown
{
if (@available(iOS 14, tvOS 14, macOS 11, *)) {
if (@available(iOS 14, tvOS 14, macOS 11, *))
{
_weakPlayer = nil;
_strongPlayer = nil;
self.engine = nil;
@ -397,24 +397,23 @@ static void mfi_joypad_autodetect_add(unsigned autoconf_pad)
static void apple_gamecontroller_joypad_setup_haptics(GCController *controller)
{
if (@available(iOS 14, tvOS 14, macOS 11, *)) {
if (@available(iOS 14, tvOS 14, macOS 11, *))
mfi_rumblers[controller.playerIndex] = [[MFIRumbleController alloc] initWithController:controller];
}
}
static void apple_gamecontroller_joypad_connect(GCController *controller)
{
signed desired_index = (int32_t)controller.playerIndex;
desired_index = (desired_index >= 0 && desired_index < MAX_MFI_CONTROLLERS)
? desired_index : 0;
if (!(desired_index >= 0 && desired_index < MAX_MFI_CONTROLLERS))
desired_index = 0;
/* prevent same controller getting set twice */
/* Prevent same controller getting set twice */
if ([mfiControllers containsObject:controller])
return;
if (mfi_controllers[desired_index] != (uint32_t)controller.hash)
{
/* desired slot is unused, take it */
/* Desired slot is unused, take it */
if (!mfi_controllers[desired_index])
{
controller.playerIndex = desired_index;
@ -422,7 +421,7 @@ static void apple_gamecontroller_joypad_connect(GCController *controller)
}
else
{
/* find a new slot for this controller that's unused */
/* Find a new slot for this controller that's unused */
unsigned i;
for (i = 0; i < MAX_MFI_CONTROLLERS; ++i)
@ -438,7 +437,7 @@ static void apple_gamecontroller_joypad_connect(GCController *controller)
[mfiControllers addObject:controller];
/* Move any non-game controllers (like the siri remote) to the end */
/* Move any non-game controllers (like the Siri remote) to the end */
if (mfiControllers.count > 1)
{
int newPlayerIndex = 0;
@ -590,17 +589,17 @@ static int16_t apple_gamecontroller_joypad_state(
static bool apple_gamecontroller_joypad_set_rumble(unsigned pad,
enum retro_rumble_effect type, uint16_t strength)
{
NSError *error;
if (pad >= MAX_MFI_CONTROLLERS)
return false;
if (@available(iOS 14, tvOS 14, macOS 11, *)) {
if (pad < MAX_MFI_CONTROLLERS)
{
if (@available(iOS 14, tvOS 14, macOS 11, *))
{
MFIRumbleController *rumble = mfi_rumblers[pad];
if (!rumble)
return false;
if (rumble)
{
NSError *error;
id<CHHapticPatternPlayer> player = (type == RETRO_RUMBLE_STRONG ? rumble.strongPlayer : rumble.weakPlayer);
if (!player)
return false;
if (player)
{
if (strength == 0)
[player stopAtTime:0 error:&error];
else
@ -615,9 +614,11 @@ static bool apple_gamecontroller_joypad_set_rumble(unsigned pad,
[player startAtTime:0 error:&error];
}
return error;
} else {
return false;
}
}
}
}
return false;
}
static bool apple_gamecontroller_joypad_query_pad(unsigned pad)
@ -627,10 +628,9 @@ static bool apple_gamecontroller_joypad_query_pad(unsigned pad)
static const char *apple_gamecontroller_joypad_name(unsigned pad)
{
if (pad >= MAX_USERS)
return NULL;
if (pad < MAX_USERS)
return "mFi Controller";
return NULL;
}
input_device_driver_t mfi_joypad = {

View File

@ -27,7 +27,9 @@
#include "../../tasks/tasks_internal.h"
#include "../../verbosity.h"
#if 0
#define LERP(p, f, t) ((((p * 10) * (t * 10)) / (f * 10)) / 10)
#endif
#if defined(ORBIS)
#include <orbis/orbisPad.h>
@ -242,7 +244,7 @@ static void ps4_joypad_poll(void)
unsigned j, k;
unsigned i = player;
if (ds_joypad_states[player].connected == false)
if (!ds_joypad_states[player].connected)
continue;
ret = scePadReadState(ds_joypad_states[player].handle[0],&buttons);