diff --git a/CMakeLists.txt b/CMakeLists.txt index d3859c2d7b..f3685a05fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -658,6 +658,10 @@ elseif(IOS) if(EXISTS "${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks/GameController.framework") set(nativeExtraLibs ${nativeExtraLibs} "-weak_framework GameController") endif() + + set_source_files_properties(ios/AppDelegate.m PROPERTIES COMPILE_FLAGS -fobjc-arc) + set_source_files_properties(ios/ViewController.mm PROPERTIES COMPILE_FLAGS -fobjc-arc) + set(TargetBin PPSSPP) elseif(USING_QT_UI) # Currently unused @@ -1476,6 +1480,7 @@ if(IOS) set_target_properties(${TargetBin} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "../ios/PPSSPP-Info.plist" XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "iPhone/iPad" + XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES ) endif() diff --git a/ios/AppDelegate.m b/ios/AppDelegate.m index 8601d4fee7..f2a6cced88 100644 --- a/ios/AppDelegate.m +++ b/ios/AppDelegate.m @@ -6,17 +6,10 @@ @implementation AppDelegate -- (void)dealloc -{ - [_window release]; - [_viewController release]; - [super dealloc]; -} - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; - self.viewController = [[[ViewController alloc] init] autorelease]; + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.viewController = [[ViewController alloc] init]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; diff --git a/ios/ViewController.mm b/ios/ViewController.mm index d64e6f6fa9..b1944b6b78 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -42,28 +42,26 @@ ViewController* sharedViewController; std::map iCadeToKeyMap; } -@property (strong, nonatomic) EAGLContext *context; -@property (nonatomic,retain) NSString* documentsPath; -@property (nonatomic,retain) NSString* bundlePath; -@property (nonatomic,retain) NSMutableArray* touches; -@property (nonatomic,retain) AudioEngine* audioEngine; -@property (nonatomic,retain) iCadeReaderView *iCadeView; +@property (nonatomic) EAGLContext* context; +@property (nonatomic) NSString* documentsPath; +@property (nonatomic) NSString* bundlePath; +@property (nonatomic) NSMutableArray* touches; +@property (nonatomic) AudioEngine* audioEngine; +@property (nonatomic) iCadeReaderView* iCadeView; #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 -@property (nonatomic,retain) GCController *gameController __attribute__((weak_import)); +@property (nonatomic) GCController *gameController __attribute__((weak_import)); #endif @end @implementation ViewController -@synthesize documentsPath,bundlePath,touches,audioEngine,iCadeView; - (id)init { self = [super init]; if (self) { sharedViewController = self; - self.touches = [[[NSMutableArray alloc] init] autorelease]; - + self.touches = [NSMutableArray array]; self.documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; self.bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/assets/"]; @@ -103,7 +101,8 @@ ViewController* sharedViewController; iCadeToKeyMap[iCadeButtonH] = NKCODE_BUTTON_3; // Circle #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 - if ([GCController class]) { // Checking the availability of a GameController framework + if ([GCController class]) // Checking the availability of a GameController framework + { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidConnect:) name:GCControllerDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidDisconnect:) name:GCControllerDidDisconnectNotification object:nil]; } @@ -118,9 +117,14 @@ ViewController* sharedViewController; self.view.frame = [[UIScreen mainScreen] bounds]; self.view.multipleTouchEnabled = YES; - self.context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease]; + self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; + + if (!self.context) + { + self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + } - GLKView *view = (GLKView *)self.view; + GLKView* view = (GLKView *)self.view; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; [EAGLContext setCurrentContext:self.context]; @@ -129,7 +133,8 @@ ViewController* sharedViewController; float scale = [UIScreen mainScreen].scale; CGSize size = [[UIApplication sharedApplication].delegate window].frame.size; - if (size.height > size.width) { + if (size.height > size.width) + { float h = size.height; size.height = size.width; size.width = h; @@ -148,12 +153,7 @@ ViewController* sharedViewController; dp_xscale = (float)dp_xres / (float)pixel_xres; dp_yscale = (float)dp_yres / (float)pixel_yres; - -/* - UISwipeGestureRecognizer* gesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)] autorelease]; - [self.view addGestureRecognizer:gesture]; -*/ - + self.iCadeView = [[iCadeReaderView alloc] init]; [self.view addSubview:self.iCadeView]; self.iCadeView.delegate = self; @@ -194,14 +194,8 @@ ViewController* sharedViewController; self.gameController = nil; } #endif - self.iCadeView = nil; - self.audioEngine = nil; - self.touches = nil; - self.documentsPath = nil; - self.bundlePath = nil; - + NativeShutdown(); - [super dealloc]; } // For iOS before 6.0 @@ -229,11 +223,6 @@ ViewController* sharedViewController; time_update(); } -- (void)swipeGesture:(id)sender -{ - // TODO: Use a swipe gesture to handle BACK -} - - (void)touchX:(float)x y:(float)y code:(int)code pointerId:(int)pointerId { lock_guard guard(input_state.lock); @@ -292,9 +281,10 @@ ViewController* sharedViewController; return index; } -- (void)touchesBegan:(NSSet *)_touches withEvent:(UIEvent *)event +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - for(UITouch* touch in _touches) { + for(UITouch* touch in touches) + { NSDictionary* dict = @{@"touch":touch,@"index":@([self freeTouchIndex])}; [self.touches addObject:dict]; CGPoint point = [touch locationInView:self.view]; @@ -302,18 +292,20 @@ ViewController* sharedViewController; } } -- (void)touchesMoved:(NSSet *)_touches withEvent:(UIEvent *)event +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - for(UITouch* touch in _touches) { + for(UITouch* touch in touches) + { CGPoint point = [touch locationInView:self.view]; NSDictionary* dict = [self touchDictBy:touch]; [self touchX:point.x y:point.y code:0 pointerId:[[dict objectForKey:@"index"] intValue]]; } } -- (void)touchesEnded:(NSSet *)_touches withEvent:(UIEvent *)event +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - for(UITouch* touch in _touches) { + for(UITouch* touch in touches) + { CGPoint point = [touch locationInView:self.view]; NSDictionary* dict = [self touchDictBy:touch]; [self touchX:point.x y:point.y code:2 pointerId:[[dict objectForKey:@"index"] intValue]]; @@ -326,19 +318,6 @@ ViewController* sharedViewController; [(GLKView*)self.view bindDrawable]; } -void LaunchBrowser(char const* url) -{ - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithCString:url encoding:NSStringEncodingConversionAllowLossy]]]; -} - -void bindDefaultFBO() -{ - [sharedViewController bindDefaultFBO]; -} - -void EnableFZ(){}; -void DisableFZ(){}; - - (void)buttonDown:(iCadeState)button { if (simulateAnalog && @@ -591,3 +570,16 @@ void DisableFZ(){}; #endif @end + +void LaunchBrowser(char const* url) +{ + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithCString:url encoding:NSStringEncodingConversionAllowLossy]]]; +} + +void bindDefaultFBO() +{ + [sharedViewController bindDefaultFBO]; +} + +void EnableFZ(){}; +void DisableFZ(){}; diff --git a/ios/main.mm b/ios/main.mm index d9a2cf20af..6e5dea13d4 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -7,6 +7,7 @@ #import #import "AppDelegate.h" +#import #include "base/NativeApp.h" @@ -30,7 +31,6 @@ void System_SendMessage(const char *command, const char *parameter) { FOUNDATION_EXTERN void AudioServicesPlaySystemSoundWithVibration(unsigned long, objc_object*, NSDictionary*); void Vibrate(int length_ms) { - NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSArray *pattern = @[@YES, @30, @NO, @2];