Mercurial > sdl-ios-xcode
comparison src/video/uikit/SDL_uikitappdelegate.m @ 2765:f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Bring SDL to iPhone and iPod Touch
by Holmes Futrell, mentored by Sam Lantinga
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 04 Oct 2008 06:46:59 +0000 |
parents | |
children | 99210400e8b9 |
comparison
equal
deleted
inserted
replaced
2764:4868c0df2e83 | 2765:f55c87ae336b |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2006 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Lesser General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2.1 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public | |
16 License along with this library; if not, write to the Free Software | |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
23 #import "SDL_uikitappdelegate.h" | |
24 #import "SDL_uikitopenglview.h" | |
25 #import "SDL_events_c.h" | |
26 #import "jumphack.h" | |
27 | |
28 #ifdef main | |
29 #undef main | |
30 #endif | |
31 | |
32 extern int SDL_main(int argc, char *argv[]); | |
33 static int forward_argc; | |
34 static char **forward_argv; | |
35 | |
36 int main(int argc, char **argv) { | |
37 | |
38 int i; | |
39 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
40 | |
41 /* store arguments */ | |
42 forward_argc = argc; | |
43 forward_argv = (char **)malloc(argc * sizeof(char *)); | |
44 for (i=0; i<argc; i++) { | |
45 forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char)); | |
46 strcpy(forward_argv[i], argv[i]); | |
47 } | |
48 | |
49 /* Give over control to run loop, SDLUIKitDelegate will handle most things from here */ | |
50 UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate"); | |
51 | |
52 [pool release]; | |
53 | |
54 } | |
55 | |
56 @implementation SDLUIKitDelegate | |
57 | |
58 @synthesize window; | |
59 | |
60 /* convenience method */ | |
61 +(SDLUIKitDelegate *)sharedAppDelegate { | |
62 /* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */ | |
63 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; | |
64 } | |
65 | |
66 - (id)init { | |
67 self = [super init]; | |
68 window = nil; | |
69 return self; | |
70 } | |
71 | |
72 - (void)applicationDidFinishLaunching:(UIApplication *)application { | |
73 | |
74 /* Set working directory to resource path */ | |
75 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; | |
76 | |
77 /* run the user's application, passing argc and argv */ | |
78 int exit_status = SDL_main(forward_argc, forward_argv); | |
79 | |
80 /* free the memory we used to hold copies of argc and argv */ | |
81 int i; | |
82 for (i=0; i<forward_argc; i++) { | |
83 free(forward_argv[i]); | |
84 } | |
85 free(forward_argv); | |
86 | |
87 /* exit, passing the return status from the user's application */ | |
88 exit(exit_status); | |
89 | |
90 } | |
91 | |
92 - (void)applicationWillTerminate:(UIApplication *)application { | |
93 | |
94 SDL_SendQuit(); | |
95 /* hack to prevent automatic termination. See SDL_uikitevents.m for details */ | |
96 longjmp(*(jump_env()), 1); | |
97 | |
98 } | |
99 | |
100 -(void)dealloc { | |
101 [window release]; | |
102 [super dealloc]; | |
103 } | |
104 | |
105 @end |