Mercurial > sdl-ios-xcode
diff src/video/uikit/SDL_uikitappdelegate.m @ 2349:0381047f2210 gsoc2008_iphone
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.
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Thu, 17 Jul 2008 22:29:37 +0000 |
parents | |
children | 32602672020e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/uikit/SDL_uikitappdelegate.m Thu Jul 17 22:29:37 2008 +0000 @@ -0,0 +1,80 @@ +// +// SDLUIKitDelegate.m +// iPodSDL +// +// Created by Holmes Futrell on 5/29/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import "SDL_uikitappdelegate.h" +#import "SDL_uikitopenglview.h" +#import <pthread.h> +#import "SDL_events_c.h" +#import "jump.h" + +#ifdef main +#undef main +#endif + +UIWindow *uikitWindow=nil; +SDL_uikitopenglview *uikitEAGLView=nil; + +extern int SDL_main(int argc, char *argv[]); +static int forward_argc; +static char **forward_argv; + +int main(int argc, char **argv) { + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + /* store arguments */ + forward_argc = argc; + forward_argv = (char **)malloc(argc * sizeof(char *)); + int i; + for (i=0; i<argc; i++) { + forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char)); + strcpy(forward_argv[i], argv[i]); + } + + UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate"); + + [pool release]; + +} + +@implementation SDLUIKitDelegate + +- (void)applicationDidFinishLaunching:(UIApplication *)application { + + /* Set working directory to resource path */ + [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; + + /* run the user's application, passing argc and argv */ + int exit_status = SDL_main(forward_argc, forward_argv); + + /* free the memory we used to hold copies of argc and argv */ + int i; + for (i=0; i<forward_argc; i++) { + free(forward_argv[i]); + } + free(forward_argv); + + /* exit, passing the return status from the user's application */ + exit(exit_status); + +} + +- (void)applicationWillTerminate:(UIApplication *)application { + + SDL_SendQuit(); + longjmp(*(jump_env()), 1); // hack to prevent automatic termination + +} + +-(void)dealloc { + [uikitWindow release]; + [uikitEAGLView release]; + [super dealloc]; +} + +@end