cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m
changeset 2723 eaa6ac1e95ea
parent 2720 a5111ec4d25f
child 2738 bfccb2ec4334
equal deleted inserted replaced
2722:d891285e500f 2723:eaa6ac1e95ea
    37 #ifdef main
    37 #ifdef main
    38 #undef main
    38 #undef main
    39 #endif
    39 #endif
    40 
    40 
    41 int main (int argc, char *argv[]) {
    41 int main (int argc, char *argv[]) {
    42     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    42 	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    43     int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate");
    43 	int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate");
    44     [pool release];
    44 	[pool release];
    45     return retVal;
    45 	return retVal;
    46 }
    46 }
    47 
    47 
    48 @implementation SDLUIKitDelegate
    48 @implementation SDLUIKitDelegate
    49 
    49 
    50 @synthesize uiwindow, window, controller;
    50 @synthesize uiwindow, window, controller;
    91 	// library or call SDL_main? pascal quits at the end of the main
    91 	// library or call SDL_main? pascal quits at the end of the main
    92 	Game(gameArgs);
    92 	Game(gameArgs);
    93 	
    93 	
    94 	free(gameArgs);
    94 	free(gameArgs);
    95 	NSLog(@"Game is exting...");
    95 	NSLog(@"Game is exting...");
    96 
    96 	
       
    97 	[[uiwindow viewWithTag:54321] removeFromSuperview];
    97 	[setup release];
    98 	[setup release];
    98 
    99 
    99 	[UIView beginAnimations:@"inserting main controller" context:NULL];
   100 	[UIView beginAnimations:@"inserting main controller" context:NULL];
   100 	[UIView setAnimationDuration:1];
   101 	[UIView setAnimationDuration:1];
   101 	controller.view.alpha = 1;
   102 	controller.view.alpha = 1;
   102 	[UIView commitAnimations];
   103 	[UIView commitAnimations];
   103 	
   104 	
   104 	[uiwindow addSubview:controller.view];
   105 	[uiwindow addSubview: controller.view];
   105 	[uiwindow makeKeyAndVisible];
   106 	[uiwindow makeKeyAndVisible];
   106 	
   107 	
   107 	[internal_pool release];
   108 	[internal_pool release];
   108 }
   109 }
   109 
   110 
   110 -(BOOL) checkFirstRun {
   111 -(BOOL) checkFirstRun {
   111 	BOOL isFirstRun = NO;
   112 	BOOL isFirstRun = NO;
       
   113 	
       
   114 	//use a nssthread a ask the user to wait
   112 	
   115 	
   113 	NSString *filePath = [self dataFilePath:@"settings.plist"];
   116 	NSString *filePath = [self dataFilePath:@"settings.plist"];
   114 	if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) {
   117 	if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) {
   115 		isFirstRun = YES;
   118 		isFirstRun = YES;
   116 		// file not present, let's create it
   119 		// file not present, let's create it
   134 	NSString *documentsDirectory = [paths objectAtIndex:0];
   137 	NSString *documentsDirectory = [paths objectAtIndex:0];
   135 	return [documentsDirectory stringByAppendingPathComponent:fileName];
   138 	return [documentsDirectory stringByAppendingPathComponent:fileName];
   136 }
   139 }
   137 
   140 
   138 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
   141 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
       
   142 	/* we get too many ones on ipod touch
   139 	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Running low on memory"
   143 	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Running low on memory"
   140 							message:@"I will try to free some memory but game might slow down a little"
   144 							message:@"I will try to free some memory but game might slow down a little"
   141 						       delegate:nil
   145 						       delegate:nil
   142 					      cancelButtonTitle:@"Ok"
   146 					      cancelButtonTitle:@"Ok"
   143 					      otherButtonTitles:nil ];
   147 					      otherButtonTitles:nil ];
   144 	[alert show];
   148 	[alert show];
   145 	[alert release];
   149 	[alert release];
       
   150 	*/
   146 }
   151 }
   147 
   152 
   148 #pragma mark -
   153 #pragma mark -
   149 #pragma mark SDLUIKitDelegate methods
   154 #pragma mark SDLUIKitDelegate methods
   150 // override the direct execution of SDL_main to allow us to implement the frontend (even using a nib)
   155 // override the direct execution of SDL_main to allow us to implement the frontend (even using a nib)
   175 -(void) applicationDidBecomeActive:(UIApplication*)application {
   180 -(void) applicationDidBecomeActive:(UIApplication*)application {
   176 //	NSLog(@"%@", NSStringFromSelector(_cmd));
   181 //	NSLog(@"%@", NSStringFromSelector(_cmd));
   177 	SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0);
   182 	SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0);
   178 }
   183 }
   179 
   184 
   180 /*
       
   181 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
       
   182 	NSLog(@"Rotating...");
       
   183 	return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
       
   184 }
       
   185 */
       
   186 
       
   187 @end
   185 @end