mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-25 12:17:04 +00:00
(mfi_joypad.m) should now work for regular mfi pads, courtesy of vinikun-mac
This commit is contained in:
parent
fa93c11d7b
commit
0e0db66f79
@ -24,9 +24,15 @@
|
||||
#include <AvailabilityMacros.h>
|
||||
#import <GameController/GameController.h>
|
||||
|
||||
#ifndef MAX_MFI_CONTROLLERS
|
||||
#define MAX_MFI_CONTROLLERS 4
|
||||
#endif
|
||||
|
||||
static uint32_t mfi_buttons[MAX_USERS];
|
||||
static int16_t mfi_axes[MAX_USERS][6];
|
||||
|
||||
static GCController* mfi_controllers[MAX_MFI_CONTROLLERS];
|
||||
|
||||
enum
|
||||
{
|
||||
GCCONTROLLER_PLAYER_INDEX_UNSET = -1,
|
||||
@ -132,17 +138,44 @@ static void apple_gamecontroller_joypad_register(GCGamepad *gamepad)
|
||||
|
||||
static void apple_gamecontroller_joypad_connect(GCController *controller)
|
||||
{
|
||||
if (controller.playerIndex == GCControllerPlayerIndexUnset)
|
||||
return;
|
||||
signed desired_index = (int32_t)controller.playerIndex;
|
||||
desired_index = (desired_index >= 0 && desired_index < MAX_MFI_CONTROLLERS)
|
||||
? desired_index : GCCONTROLLER_PLAYER_INDEX_UNSET;
|
||||
|
||||
apple_gamecontroller_joypad_register(controller.gamepad);
|
||||
/* prevent same controller getting set twice */
|
||||
if (mfi_controllers[desired_index] != controller)
|
||||
{
|
||||
/* desired slot is unused, take it */
|
||||
if (!mfi_controllers[desired_index])
|
||||
{
|
||||
controller.playerIndex = desired_index;
|
||||
mfi_controllers[desired_index] = controller;
|
||||
}
|
||||
/* find a new slot for this controller that's unused */
|
||||
else if (desired_index == GCCONTROLLER_PLAYER_INDEX_UNSET || mfi_controllers[desired_index])
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < MAX_MFI_CONTROLLERS; ++i)
|
||||
if (!mfi_controllers[i])
|
||||
{
|
||||
mfi_controllers[i] = controller;
|
||||
controller.playerIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
apple_gamecontroller_joypad_register(controller.gamepad);
|
||||
}
|
||||
}
|
||||
|
||||
static void apple_gamecontroller_joypad_disconnect(GCController* controller)
|
||||
{
|
||||
unsigned pad = (uint32_t)controller.playerIndex;
|
||||
signed pad = (int32_t)controller.playerIndex;
|
||||
|
||||
if (pad == GCCONTROLLER_PLAYER_INDEX_UNSET)
|
||||
return;
|
||||
|
||||
mfi_controllers[pad] = NULL;
|
||||
}
|
||||
|
||||
bool apple_gamecontroller_joypad_init(void *data)
|
||||
@ -150,6 +183,7 @@ bool apple_gamecontroller_joypad_init(void *data)
|
||||
static bool inited = false;
|
||||
if (inited)
|
||||
return true;
|
||||
|
||||
if (!apple_gamecontroller_available())
|
||||
return false;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user