comparison 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
comparison
equal deleted inserted replaced
2348:dd32c95434f4 2349:0381047f2210
1 //
2 // SDLUIKitDelegate.m
3 // iPodSDL
4 //
5 // Created by Holmes Futrell on 5/29/08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "SDL_uikitappdelegate.h"
10 #import "SDL_uikitopenglview.h"
11 #import <pthread.h>
12 #import "SDL_events_c.h"
13 #import "jump.h"
14
15 #ifdef main
16 #undef main
17 #endif
18
19 UIWindow *uikitWindow=nil;
20 SDL_uikitopenglview *uikitEAGLView=nil;
21
22 extern int SDL_main(int argc, char *argv[]);
23 static int forward_argc;
24 static char **forward_argv;
25
26 int main(int argc, char **argv) {
27
28 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
29
30 /* store arguments */
31 forward_argc = argc;
32 forward_argv = (char **)malloc(argc * sizeof(char *));
33 int i;
34 for (i=0; i<argc; i++) {
35 forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
36 strcpy(forward_argv[i], argv[i]);
37 }
38
39 UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate");
40
41 [pool release];
42
43 }
44
45 @implementation SDLUIKitDelegate
46
47 - (void)applicationDidFinishLaunching:(UIApplication *)application {
48
49 /* Set working directory to resource path */
50 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
51
52 /* run the user's application, passing argc and argv */
53 int exit_status = SDL_main(forward_argc, forward_argv);
54
55 /* free the memory we used to hold copies of argc and argv */
56 int i;
57 for (i=0; i<forward_argc; i++) {
58 free(forward_argv[i]);
59 }
60 free(forward_argv);
61
62 /* exit, passing the return status from the user's application */
63 exit(exit_status);
64
65 }
66
67 - (void)applicationWillTerminate:(UIApplication *)application {
68
69 SDL_SendQuit();
70 longjmp(*(jump_env()), 1); // hack to prevent automatic termination
71
72 }
73
74 -(void)dealloc {
75 [uikitWindow release];
76 [uikitEAGLView release];
77 [super dealloc];
78 }
79
80 @end