mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-13 06:10:55 +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>
|
#include <AvailabilityMacros.h>
|
||||||
#import <GameController/GameController.h>
|
#import <GameController/GameController.h>
|
||||||
|
|
||||||
|
#ifndef MAX_MFI_CONTROLLERS
|
||||||
|
#define MAX_MFI_CONTROLLERS 4
|
||||||
|
#endif
|
||||||
|
|
||||||
static uint32_t mfi_buttons[MAX_USERS];
|
static uint32_t mfi_buttons[MAX_USERS];
|
||||||
static int16_t mfi_axes[MAX_USERS][6];
|
static int16_t mfi_axes[MAX_USERS][6];
|
||||||
|
|
||||||
|
static GCController* mfi_controllers[MAX_MFI_CONTROLLERS];
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
GCCONTROLLER_PLAYER_INDEX_UNSET = -1,
|
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)
|
static void apple_gamecontroller_joypad_connect(GCController *controller)
|
||||||
{
|
{
|
||||||
if (controller.playerIndex == GCControllerPlayerIndexUnset)
|
signed desired_index = (int32_t)controller.playerIndex;
|
||||||
return;
|
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)
|
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)
|
if (pad == GCCONTROLLER_PLAYER_INDEX_UNSET)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
mfi_controllers[pad] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool apple_gamecontroller_joypad_init(void *data)
|
bool apple_gamecontroller_joypad_init(void *data)
|
||||||
@ -150,6 +183,7 @@ bool apple_gamecontroller_joypad_init(void *data)
|
|||||||
static bool inited = false;
|
static bool inited = false;
|
||||||
if (inited)
|
if (inited)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!apple_gamecontroller_available())
|
if (!apple_gamecontroller_available())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user