(iOS) Make apple_gamecontroller 'backwards compatible' with iOS 6

by doing runtime check for iOS version and then returning early
This commit is contained in:
twinaphex 2013-12-28 21:49:31 +01:00
parent ff036066e2
commit b41c3cc6bd
2 changed files with 33 additions and 6 deletions

View File

@ -21,7 +21,7 @@
96366C5516C9AC3300D64A22 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96366C5416C9AC3300D64A22 /* CoreAudio.framework */; };
96366C5916C9ACF500D64A22 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96366C5816C9ACF500D64A22 /* AudioToolbox.framework */; };
963C3C32186E3D2600A6EB1E /* apple_gamecontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 963C3C31186E3D2600A6EB1E /* apple_gamecontroller.m */; };
963C3C34186E3DED00A6EB1E /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963C3C33186E3DED00A6EB1E /* GameController.framework */; settings = {ATTRIBUTES = (Required, ); }; };
963C3C34186E3DED00A6EB1E /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963C3C33186E3DED00A6EB1E /* GameController.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
963F5AC816CC523B009BBD19 /* RAGameView.m in Sources */ = {isa = PBXBuildFile; fileRef = 963F5AC516CC523B009BBD19 /* RAGameView.m */; };
9646869517BBBEAE00C5EA69 /* platform.m in Sources */ = {isa = PBXBuildFile; fileRef = 9646869417BBBEAE00C5EA69 /* platform.m */; };
966B9CBD16E41E7A005B61E1 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 966B9CB816E41E7A005B61E1 /* Default-568h@2x.png */; };

View File

@ -14,6 +14,10 @@
*/
#include <Availability.h>
#ifdef IOS
#include <UIKit/UIDevice.h>
static NSArray *versionCompatibility;
#endif
#if defined(__IPHONE_7_0) && !defined(OSX)
@ -24,6 +28,10 @@
static void apple_gamecontroller_poll(GCController* controller)
{
#ifdef IOS
if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 )
return;
#endif
if (!controller || controller.playerIndex == MAX_PLAYERS)
return;
@ -68,8 +76,12 @@ static void apple_gamecontroller_poll(GCController* controller)
}
}
void apple_gamecontroller_poll_all()
void apple_gamecontroller_poll_all(void)
{
#ifdef IOS
if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 )
return;
#endif
NSArray* controllers = [GCController controllers];
for (int i = 0; i != [controllers count]; i ++)
@ -78,6 +90,10 @@ void apple_gamecontroller_poll_all()
void apple_gamecontroller_connect(GCController* controller)
{
#ifdef IOS
if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 )
return;
#endif
int32_t slot = apple_joypad_connect_gcapi();
controller.playerIndex = (slot >= 0 && slot < MAX_PLAYERS) ? slot : GCControllerPlayerIndexUnset;
@ -95,15 +111,26 @@ void apple_gamecontroller_connect(GCController* controller)
void apple_gamecontroller_disconnect(GCController* controller)
{
#ifdef IOS
if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 )
return;
#endif
if (controller.playerIndex == GCControllerPlayerIndexUnset)
return;
apple_joypad_disconnect(controller.playerIndex);
}
void apple_gamecontroller_init()
void apple_gamecontroller_init(void)
{
[[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification object:nil queue:[NSOperationQueue mainQueue]
#ifdef IOS
versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 )
return;
#endif
[[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification object:nil queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) { apple_gamecontroller_connect([note object]); } ];
[[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification object:nil queue:[NSOperationQueue mainQueue]
@ -112,12 +139,12 @@ void apple_gamecontroller_init()
#else
void apple_gamecontroller_init()
void apple_gamecontroller_init(void)
{
}
void apple_gamecontroller_poll_all()
void apple_gamecontroller_poll_all(void)
{
}