Browse Source

Apply Xcode ARC and Modern Obj-C refactors to IOS project

Paul Jan 12 years ago
parent
commit
217e2df

+ 2 - 0
engine/compilers/Xcode_iOS/Torque2D.xcodeproj/project.pbxproj

@@ -3425,6 +3425,7 @@
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
 				"FRAMEWORK_SEARCH_PATHS[arch=*]" = "";
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "Torque2D/Torque2D-Prefix.pch";
@@ -3447,6 +3448,7 @@
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
 				"FRAMEWORK_SEARCH_PATHS[arch=*]" = "";
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "Torque2D/Torque2D-Prefix.pch";

+ 1 - 1
engine/source/platformiOS/T2DAppDelegate.h

@@ -27,6 +27,6 @@
 	IBOutlet UIWindow *window;
 }
 
-@property (nonatomic, retain) UIWindow *window;
+@property (nonatomic, strong) UIWindow *window;
 
 @end

+ 0 - 6
engine/source/platformiOS/T2DAppDelegate.mm

@@ -41,12 +41,6 @@ bool _iOSTorqueFatalError = false;
 
 @synthesize window = _window;
 
-- (void)dealloc 
-{
-    [_window release];
-
-    [super dealloc];
-}
 
 - (void)applicationDidFinishLaunching:(UIApplication *)application {
     

+ 20 - 27
engine/source/platformiOS/iOSAlerts.mm

@@ -52,40 +52,39 @@
 
 
 
-bool iOSButtonBox(const char *windowTitle, const char *message, int numButtons = 0, NSString *buttons[] = nil, iOSAlertDelegate *delegate = nil) 
+bool iOSButtonBox(const char *windowTitle, const char *message, int numButtons = 0, NSArray *buttons = nil, iOSAlertDelegate *delegate = nil)
 {
-
-	UIAlertView *Alert =  [[UIAlertView alloc] initWithTitle: [NSString stringWithUTF8String: windowTitle]
-													 message: [NSString stringWithUTF8String: message] 
-													delegate: delegate 
+    
+	UIAlertView *Alert =  [[UIAlertView alloc] initWithTitle: @(windowTitle)
+													 message: @(message)
+													delegate: delegate
 										   cancelButtonTitle: nil
 										   otherButtonTitles: nil ];
 	
 	if(numButtons > 0)
 	{
 		NSString *current = nil;
-		for( int i = 1;  i < numButtons ; i++ ) 
+		for( int i = 1;  i < numButtons ; i++ )
 		{
 			current = buttons[i];
 			[Alert addButtonWithTitle: current ];
 		}
 	}
-	else 
+	else
 	{
 		[Alert addButtonWithTitle: @"OK" ];
 	}
-
+    
 	
 	[Alert show];
 	
 	// PUAP -Mat NOTE: NSRunLoop is not Thread-Safe, see documentation
-
-	while (Alert.visible) 
+    
+	while (Alert.visible)
 	{
 		[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.100]];
 	}
 	
-	[Alert release];
 	
 	return true;
 }
@@ -99,22 +98,20 @@ void Platform::AlertOK(const char *windowTitle, const char *message)
 	
 	iOSButtonBox( windowTitle, message, 0, nil, delegate );
 	
-	[delegate release];
 }
 //-----------------------------------------------------------------------------
 bool Platform::AlertOKCancel(const char *windowTitle, const char *message)
-{	
+{
 	iOSAlertDelegate *delegate = [[iOSAlertDelegate alloc] init];
 	
-
-	NSString *buttons[] = { @"OK", @"Cancel" };
+    
+	NSArray *buttons = @[ @"OK", @"Cancel" ];
 	
 	//Luma:	Need to pass the delegate in as well
-	iOSButtonBox( windowTitle, message, 2, buttons, delegate );	
+	iOSButtonBox( windowTitle, message, 2, buttons, delegate );
 	
 	//Luma: Zero is NOT the cancel button index... it is based on the order of the buttons in the above array
 	bool returnValue = (delegate->buttonNumber != 1 );
-	[delegate release];
 	return returnValue;
 }
 
@@ -124,29 +121,25 @@ bool Platform::AlertRetry(const char *windowTitle, const char *message)
 	iOSAlertDelegate *delegate = [[iOSAlertDelegate alloc] init];
 	
 	//Luma:	Should be Retry / Cancel, not Cancel / Retry
-	NSString *buttons[] = { @"Retry",
-							@"Cancel",
-						  };
-
+    NSArray  *buttons = @[@"Retry", @"Cancel"];
+    
 	//Luma:	Need to pass the delegate in as well
-	iOSButtonBox( windowTitle, message, 2, buttons, delegate );	
+	iOSButtonBox( windowTitle, message, 2, buttons, delegate );
 	
 	//Luma: Zero is NOT the cancel button index... it is based on the order of the buttons in the above array
 	bool returnValue = (delegate->buttonNumber != 1 );
-	[delegate release];
 	return returnValue;
 }
 
 
 bool Platform::AlertYesNo(const char *windowTitle, const char *message)
-{	
+{
 	iOSAlertDelegate *delegate = [[iOSAlertDelegate alloc] init];
 	
-	NSString *buttons[] = { @"Yes", @"No" };
+    NSArray  *buttons = @[@"Yes", @"No"];
 	
-	iOSButtonBox( windowTitle, message, 2, buttons, delegate );	
+	iOSButtonBox( windowTitle, message, 2, buttons, delegate );
 	bool returnValue = (delegate->buttonNumber != 1 );
-	[delegate release];
 	
 	return returnValue;
 }

+ 1 - 1
engine/source/platformiOS/iOSMotionManager.h

@@ -43,7 +43,7 @@
 @property (readwrite, assign) bool accelerometerEnabled;
 @property (readwrite, assign) bool gyroscopeEnabled;
 
-@property (retain) CMAttitude* referenceAttitude;
+@property (strong) CMAttitude* referenceAttitude;
 
 // Accelerometer related functions
 - (void) enableAccelerometer;

+ 3 - 10
engine/source/platformiOS/iOSMotionManager.mm

@@ -42,7 +42,7 @@ static const double kUpdateInterval = 0.2;
 
 - (id)init
 {
-    [super init];
+    if (!(self = [super init])) return nil;
     
     if(self != NULL)
     {
@@ -70,13 +70,6 @@ static const double kUpdateInterval = 0.2;
 }
 
 
-- (void)dealloc
-{
-    if( motionManager != NULL )
-        [motionManager release];
-    
-    [super dealloc];
-}
 
 double accelAxes[6];
 
@@ -274,7 +267,7 @@ void (^motionHandler)(CMDeviceMotion*, NSError*) = ^(CMDeviceMotion *motionData,
     if(motionManager.deviceMotionAvailable)
     {
         if(referenceAttitude == NULL)
-            referenceAttitude = [motionManager.deviceMotion.attitude retain];
+            referenceAttitude = motionManager.deviceMotion.attitude;
         
         [motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:motionHandler];
     }
@@ -301,7 +294,7 @@ void (^motionHandler)(CMDeviceMotion*, NSError*) = ^(CMDeviceMotion *motionData,
 {
     if(motionManager.deviceMotionAvailable)
     {
-        referenceAttitude = [motionManager.deviceMotion.attitude retain];
+        referenceAttitude = motionManager.deviceMotion.attitude;
         return true;
     }
     

+ 0 - 1
engine/source/platformiOS/iOSOGLVideo.mm

@@ -156,7 +156,6 @@ bool OpenGLDevice::cleanupContextAndWindow()
 void OpenGLDevice::shutdown()
 {
     Con::printf("Shutting down the OpenGL display device...");
-    [platState.ctx release];
 }
 
 

+ 36 - 36
engine/source/platformiOS/iOSPlatform.mm

@@ -109,49 +109,49 @@ S32 Platform::messageBox(const UTF8 *title, const UTF8 *message, MBButtons butto
 bool Platform::pathCopy(const char* source, const char* dest, bool nooverwrite)
 {
    NSFileManager *manager = [NSFileManager defaultManager];
-   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+   @autoreleasepool {
    
-   NSString *nsource = [[NSString stringWithUTF8String:source] stringByStandardizingPath];
-   NSString *ndest   = [[NSString stringWithUTF8String:dest] stringByStandardizingPath];
-   NSString *ndestFolder = [ndest stringByDeletingLastPathComponent];
-   
-   if(! [manager fileExistsAtPath:nsource])
-   {
-      Con::errorf("Platform::pathCopy: no file exists at %s",source);
-      return false;
-   }
-    
-    //Catcher for the errors.
-    NSError** returnValue = nil;
-   
-   if( [manager fileExistsAtPath:ndest] )
-   {
-      if(nooverwrite)
+      NSString *nsource = [@(source) stringByStandardizingPath];
+      NSString *ndest   = [@(dest) stringByStandardizingPath];
+      NSString *ndestFolder = [ndest stringByDeletingLastPathComponent];
+      
+      if(! [manager fileExistsAtPath:nsource])
       {
-         Con::errorf("Platform::pathCopy file already exists at %s",dest);
+         Con::errorf("Platform::pathCopy: no file exists at %s",source);
          return false;
       }
        
-      Con::warnf("Deleting files at path: %s", dest);
-      bool deleted = [manager removeItemAtPath:ndest error:returnValue];
-      if(!deleted)
+       //Catcher for the errors.
+       NSError* returnValue = nil;
+      
+      if( [manager fileExistsAtPath:ndest] )
       {
-         Con::errorf("Copy failed! Could not delete files at path: %s", dest);
-         return false;
+         if(nooverwrite)
+         {
+            Con::errorf("Platform::pathCopy file already exists at %s",dest);
+            return false;
+         }
+          
+         Con::warnf("Deleting files at path: %s", dest);
+         bool deleted = [manager removeItemAtPath:ndest error:&returnValue];
+         if(!deleted)
+         {
+            Con::errorf("Copy failed! Could not delete files at path: %s", dest);
+            return false;
+         }
       }
+      
+      if([manager fileExistsAtPath:ndestFolder] == NO)
+      {
+         ndestFolder = [ndestFolder stringByAppendingString:@"/"]; // createpath requires a trailing slash
+         Platform::createPath([ndestFolder UTF8String]);
+      }
+      
+      bool ret = [manager copyItemAtPath:nsource toPath:ndest error:&returnValue];
+      
+      return ret;
    }
    
-   if([manager fileExistsAtPath:ndestFolder] == NO)
-   {
-      ndestFolder = [ndestFolder stringByAppendingString:@"/"]; // createpath requires a trailing slash
-      Platform::createPath([ndestFolder UTF8String]);
-   }
-   
-   bool ret = [manager copyItemAtPath:nsource toPath:ndest error:returnValue];
-   
-   [pool release];
-   return ret;
-   
 }
 
 //-----------------------------------------------------------------------------
@@ -176,9 +176,9 @@ bool Platform::fileRename(const char *source, const char *dest)
       Con::warnf("Platform::fileRename: Deleting files at path: %s", dest);
    }
     
-    NSError** returnValue = NULL;
+    NSError* returnValue = NULL;
    
-   bool ret = [manager moveItemAtPath:nsource toPath:ndest error:returnValue];
+   bool ret = [manager moveItemAtPath:nsource toPath:ndest error:&returnValue];
   
    return ret;
 }

+ 1 - 2
engine/source/platformiOS/iOSStrings.mm

@@ -409,10 +409,9 @@ void dQsort(void *base, U32 nelem, U32 width, int (QSORT_CALLBACK *fcmp)(const v
 StringTableEntry Platform::createUUID( void )
 {
     CFUUIDRef ref = CFUUIDCreate(nil);
-    NSString* uuid = (NSString *)CFUUIDCreateString(nil,ref);
+    NSString* uuid = (__bridge_transfer NSString *)CFUUIDCreateString(nil,ref);
     CFRelease(ref);
 
     StringTableEntry uuidString = StringTable->insert([uuid UTF8String]);
-    [uuid release];
     return uuidString;
 }

+ 5 - 5
engine/source/platformiOS/iOSThread.mm

@@ -47,11 +47,11 @@ static void *ThreadRunHandler(void * arg)
 {
    PlatformThreadData *mData = reinterpret_cast<PlatformThreadData*>(arg);
    Thread *thread = mData->mThread;
-	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-   mData->mThreadID = ThreadManager::getCurrentThreadId();
-   ThreadManager::addThread(thread);
-   thread->run(mData->mRunArg);
-   	[pool release];
+	@autoreleasepool {
+      mData->mThreadID = ThreadManager::getCurrentThreadId();
+      ThreadManager::addThread(thread);
+      thread->run(mData->mRunArg);
+   	}
 	mData->mGateway.release();
    // we could delete the Thread here, if it wants to be auto-deleted...
    if(thread->autoDelete)

+ 1 - 1
engine/source/platformiOS/iOSUtil.mm

@@ -214,7 +214,7 @@ CFSocketRef CreateCFSocketToURLAndPort(const char *ipAddress, U16 port)
     inet_aton(ipAddress, &addr4.sin_addr);
 
     NSData *address = [NSData dataWithBytes:&addr4 length:sizeof(addr4)];
-    CFSocketConnectToAddress(socket, (CFDataRef)address, -1);
+    CFSocketConnectToAddress(socket, (__bridge CFDataRef)address, -1);
 
     CFRunLoopSourceRef source;
     source = CFSocketCreateRunLoopSource(NULL, socket, 1);

+ 0 - 2
engine/source/platformiOS/iOSWindow.mm

@@ -319,8 +319,6 @@ bool Platform::openWebBrowser(const char *webAddress)
     NSString *string = [[NSString alloc] initWithUTF8String:webAddress];
     NSURL *url = [[NSURL alloc] initWithString:string];
     bool ret = [platState.application openURL:url];
-    [string release];
-    [url release];
 
     return ret;// this bails on the application, switching to Safari
 }