early-access version 2835

This commit is contained in:
pineappleEA
2022-07-15 04:00:50 +02:00
parent 5c0ee5eba6
commit 0e7aef7e36
1173 changed files with 55320 additions and 18881 deletions

View File

@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -69,6 +69,9 @@ static NSString *GCInputXboxShareButton = @"Button Share";
#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 130000) || (__MAC_OS_VERSION_MAX_ALLOWED >= 1500000))
@property(nonatomic, readonly) NSString *productCategory;
#endif
#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 140500) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 140500) || (__MAC_OS_X_VERSION_MAX_ALLOWED >= 110300))
@property(class, nonatomic, readwrite) BOOL shouldMonitorBackgroundEvents;
#endif
@end
@interface GCExtendedGamepad (SDL)
#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 121000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 121000) || (__MAC_OS_VERSION_MAX_ALLOWED >= 1401000))
@@ -177,6 +180,10 @@ IsControllerXbox(GCController *controller)
static BOOL
IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controller)
{
if ((@available(macOS 11.3, *)) && !GCController.shouldMonitorBackgroundEvents) {
GCController.shouldMonitorBackgroundEvents = YES;
}
Uint16 *guid16 = (Uint16 *)device->guid.data;
Uint16 vendor = 0;
Uint16 product = 0;
@@ -327,6 +334,15 @@ IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controlle
subtype = 1;
}
if (SDL_strcmp(name, "Backbone One") == 0) {
/* The Backbone app uses share button */
if ((device->button_mask & (1 << SDL_CONTROLLER_BUTTON_MISC1)) != 0) {
device->button_mask &= ~(1 << SDL_CONTROLLER_BUTTON_MISC1);
--nbuttons;
device->has_xbox_share_button = SDL_FALSE;
}
}
device->naxes = 6; /* 2 thumbsticks and 2 triggers */
device->nhats = 1; /* d-pad */
device->nbuttons = nbuttons;
@@ -631,6 +647,12 @@ IOS_JoystickGetDeviceName(int device_index)
return device ? device->name : "Unknown";
}
static const char *
IOS_JoystickGetDevicePath(int device_index)
{
return NULL;
}
static int
IOS_JoystickGetDevicePlayerIndex(int device_index)
{
@@ -719,7 +741,7 @@ IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
#ifdef ENABLE_MFI_SENSORS
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller;
GCMotion *motion = controller.motion;
if (motion && motion.hasRotationRate) {
@@ -732,7 +754,7 @@ IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
#endif /* ENABLE_MFI_SENSORS */
#ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller;
for (id key in controller.physicalInputProfile.buttons) {
GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key];
@@ -944,7 +966,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
}
#ifdef ENABLE_MFI_SENSORS
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCMotion *motion = controller.motion;
if (motion && motion.sensorsActive) {
float data[3];
@@ -1037,7 +1059,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
}
#ifdef ENABLE_MFI_BATTERY
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCDeviceBattery *battery = controller.battery;
if (battery) {
SDL_JoystickPowerLevel ePowerLevel = SDL_JOYSTICK_POWER_UNKNOWN;
@@ -1078,8 +1100,8 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
#ifdef ENABLE_MFI_RUMBLE
@interface SDL_RumbleMotor : NSObject
@property(nonatomic,strong) CHHapticEngine *engine API_AVAILABLE(macos(11.0), ios(13.0), tvos(14.0));
@property(nonatomic,strong) id<CHHapticPatternPlayer> player API_AVAILABLE(macos(11.0), ios(13.0), tvos(14.0));
@property(nonatomic,strong) CHHapticEngine *engine API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0));
@property(nonatomic,strong) id<CHHapticPatternPlayer> player API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0));
@property bool active;
@end
@@ -1089,7 +1111,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
-(void)cleanup
{
@autoreleasepool {
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (self.player != nil) {
[self.player cancelAndReturnError:nil];
self.player = nil;
@@ -1105,7 +1127,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
-(int)setIntensity:(float)intensity
{
@autoreleasepool {
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
NSError *error = nil;
if (self.engine == nil) {
@@ -1151,7 +1173,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
}
}
-(id) initWithController:(GCController*)controller locality:(GCHapticsLocality)locality API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0))
-(id) initWithController:(GCController*)controller locality:(GCHapticsLocality)locality API_AVAILABLE(macos(10.16), ios(14.0), tvos(14.0))
{
@autoreleasepool {
self = [super init];
@@ -1169,7 +1191,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
return nil;
}
__weak typeof(self) weakSelf = self;
__weak __typeof(self) weakSelf = self;
self.engine.stoppedHandler = ^(CHHapticEngineStoppedReason stoppedReason) {
SDL_RumbleMotor *_this = weakSelf;
if (_this == nil) {
@@ -1251,7 +1273,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
static SDL_RumbleContext *IOS_JoystickInitRumble(GCController *controller)
{
@autoreleasepool {
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
SDL_RumbleMotor *low_frequency_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftHandle];
SDL_RumbleMotor *high_frequency_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityRightHandle];
SDL_RumbleMotor *left_trigger_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftTrigger];
@@ -1279,7 +1301,7 @@ IOS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 h
return SDL_SetError("Controller is no longer connected");
}
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (!device->rumble && device->controller && device->controller.haptics) {
SDL_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller);
if (rumble) {
@@ -1309,7 +1331,7 @@ IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 ri
return SDL_SetError("Controller is no longer connected");
}
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (!device->rumble && device->controller && device->controller.haptics) {
SDL_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller);
if (rumble) {
@@ -1342,7 +1364,7 @@ IOS_JoystickGetCapabilities(SDL_Joystick *joystick)
return 0;
}
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = device->controller;
#ifdef ENABLE_MFI_LIGHT
if (controller.light) {
@@ -1379,7 +1401,7 @@ IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
return SDL_SetError("Controller is no longer connected");
}
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = device->controller;
GCDeviceLight *light = controller.light;
if (light) {
@@ -1412,7 +1434,7 @@ IOS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
return SDL_SetError("Controller is no longer connected");
}
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = device->controller;
GCMotion *motion = controller.motion;
if (motion) {
@@ -1475,7 +1497,7 @@ IOS_JoystickClose(SDL_Joystick *joystick)
controller.playerIndex = -1;
#ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
for (id key in controller.physicalInputProfile.buttons) {
GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key];
if ([button isBoundToSystemGesture]) {
@@ -1573,7 +1595,7 @@ SDL_bool IOS_SupportedHIDDevice(IOHIDDeviceRef device)
static void
GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *name)
{
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (element) {
[element.sfSymbolsName getCString: name maxLength: 255 encoding: NSASCIIStringEncoding];
}
@@ -1607,7 +1629,7 @@ IOS_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontrol
elementName[0] = '\0';
#if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE)
if (gamecontroller && SDL_GameControllerGetJoystick(gamecontroller)->driver == &SDL_IOS_JoystickDriver) {
if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller;
if ([controller respondsToSelector:@selector(physicalInputProfile)]) {
NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements;
@@ -1720,7 +1742,7 @@ IOS_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontrolle
elementName[0] = '\0';
#if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE)
if (gamecontroller && SDL_GameControllerGetJoystick(gamecontroller)->driver == &SDL_IOS_JoystickDriver) {
if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) {
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller;
if ([controller respondsToSelector:@selector(physicalInputProfile)]) {
NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements;
@@ -1761,6 +1783,7 @@ SDL_JoystickDriver SDL_IOS_JoystickDriver =
IOS_JoystickGetCount,
IOS_JoystickDetect,
IOS_JoystickGetDeviceName,
IOS_JoystickGetDevicePath,
IOS_JoystickGetDevicePlayerIndex,
IOS_JoystickSetDevicePlayerIndex,
IOS_JoystickGetDeviceGUID,