The class SDL_uikitappdelegate acts as the UIApplicationDelegate for an iPhone SDL project. This class is reponsible for application control flow, including initial setup of working directory, forwarding command line arguments to the user's main function, and handling application termination. gsoc2008_iphone
authorHolmes Futrell <hfutrell@umail.ucsb.edu>
Thu, 17 Jul 2008 22:29:37 +0000
branchgsoc2008_iphone
changeset 23490381047f2210
parent 2348 dd32c95434f4
child 2350 eb828d6c3efb
The class SDL_uikitappdelegate acts as the UIApplicationDelegate for an iPhone SDL project. This class is reponsible for application control flow, including initial setup of working directory, forwarding command line arguments to the user's main function, and handling application termination.
src/video/uikit/SDL_uikitappdelegate.h
src/video/uikit/SDL_uikitappdelegate.m
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/uikit/SDL_uikitappdelegate.h	Thu Jul 17 22:29:37 2008 +0000
     1.3 @@ -0,0 +1,17 @@
     1.4 +//
     1.5 +//  SDLUIKitDelegate.h
     1.6 +//  iPodSDL
     1.7 +//
     1.8 +//  Created by Holmes Futrell on 5/29/08.
     1.9 +//  Copyright 2008 __MyCompanyName__. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#import <UIKit/UIKit.h>
    1.13 +#import "SDL_uikitopenglview.h"
    1.14 +
    1.15 +@interface SDLUIKitDelegate : NSObject<UIApplicationDelegate> {
    1.16 +	UIWindow *window;
    1.17 +	SDL_uikitopenglview *view;
    1.18 +}
    1.19 +
    1.20 +@end
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Thu Jul 17 22:29:37 2008 +0000
     2.3 @@ -0,0 +1,80 @@
     2.4 +//
     2.5 +//  SDLUIKitDelegate.m
     2.6 +//  iPodSDL
     2.7 +//
     2.8 +//  Created by Holmes Futrell on 5/29/08.
     2.9 +//  Copyright 2008 __MyCompanyName__. All rights reserved.
    2.10 +//
    2.11 +
    2.12 +#import "SDL_uikitappdelegate.h"
    2.13 +#import "SDL_uikitopenglview.h"
    2.14 +#import <pthread.h>
    2.15 +#import "SDL_events_c.h"
    2.16 +#import "jump.h"
    2.17 +
    2.18 +#ifdef main
    2.19 +#undef main
    2.20 +#endif
    2.21 +
    2.22 +UIWindow *uikitWindow=nil;
    2.23 +SDL_uikitopenglview *uikitEAGLView=nil;
    2.24 +
    2.25 +extern int SDL_main(int argc, char *argv[]);
    2.26 +static int forward_argc;
    2.27 +static char **forward_argv;
    2.28 +
    2.29 +int main(int argc, char **argv) {
    2.30 +
    2.31 +	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    2.32 +	
    2.33 +	/* store arguments */
    2.34 +	forward_argc = argc;
    2.35 +	forward_argv = (char **)malloc(argc * sizeof(char *));
    2.36 +	int i;
    2.37 +	for (i=0; i<argc; i++) {
    2.38 +		forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
    2.39 +		strcpy(forward_argv[i], argv[i]);
    2.40 +	}
    2.41 +
    2.42 +	UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate");
    2.43 +	
    2.44 +	[pool release];
    2.45 +	
    2.46 +}
    2.47 +
    2.48 +@implementation SDLUIKitDelegate
    2.49 +
    2.50 +- (void)applicationDidFinishLaunching:(UIApplication *)application {
    2.51 +			
    2.52 +	/* Set working directory to resource path */
    2.53 +	[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
    2.54 +	
    2.55 +	/* run the user's application, passing argc and argv */
    2.56 +	int exit_status = SDL_main(forward_argc, forward_argv);
    2.57 +	
    2.58 +	/* free the memory we used to hold copies of argc and argv */
    2.59 +	int i;
    2.60 +	for (i=0; i<forward_argc; i++) {
    2.61 +		free(forward_argv[i]);
    2.62 +	}
    2.63 +	free(forward_argv);	
    2.64 +		
    2.65 +	/* exit, passing the return status from the user's application */
    2.66 +	exit(exit_status);
    2.67 +		
    2.68 +}
    2.69 +
    2.70 +- (void)applicationWillTerminate:(UIApplication *)application {
    2.71 +	
    2.72 +	SDL_SendQuit();
    2.73 +	longjmp(*(jump_env()), 1); // hack to prevent automatic termination
    2.74 +	
    2.75 +}
    2.76 +
    2.77 +-(void)dealloc {
    2.78 +	[uikitWindow release];
    2.79 +	[uikitEAGLView release]; 
    2.80 +	[super dealloc];
    2.81 +}
    2.82 +
    2.83 +@end