Fixed building on iOS with MFI controllers disabled

This commit is contained in:
Sam Lantinga 2020-05-27 10:14:08 -07:00
parent 97ca96bdee
commit e9f567c707

View file

@ -393,8 +393,6 @@ static int
IOS_JoystickInit(void) IOS_JoystickInit(void)
{ {
@autoreleasepool { @autoreleasepool {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
#if !TARGET_OS_TV #if !TARGET_OS_TV
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) { if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) {
/* Default behavior, accelerometer as joystick */ /* Default behavior, accelerometer as joystick */
@ -417,6 +415,8 @@ IOS_JoystickInit(void)
SDL_AppleTVRemoteRotationHintChanged, NULL); SDL_AppleTVRemoteRotationHintChanged, NULL);
#endif /* TARGET_OS_TV */ #endif /* TARGET_OS_TV */
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
connectObserver = [center addObserverForName:GCControllerDidConnectNotification connectObserver = [center addObserverForName:GCControllerDidConnectNotification
object:nil object:nil
queue:nil queue:nil
@ -466,17 +466,24 @@ IOS_JoystickGetDeviceName(int device_index)
static int static int
IOS_JoystickGetDevicePlayerIndex(int device_index) IOS_JoystickGetDevicePlayerIndex(int device_index)
{ {
#ifdef SDL_JOYSTICK_MFI
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index); SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
return device ? (int)device->controller.playerIndex : -1; if (device && device->controller) {
return (int)device->controller.playerIndex;
}
#endif
return -1;
} }
static void static void
IOS_JoystickSetDevicePlayerIndex(int device_index, int player_index) IOS_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{ {
#ifdef SDL_JOYSTICK_MFI
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index); SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
if (device) { if (device && device->controller) {
device->controller.playerIndex = player_index; device->controller.playerIndex = player_index;
} }
#endif
} }
static SDL_JoystickGUID static SDL_JoystickGUID