22 |
22 |
23 #import "SDL_uikitappdelegate.h" |
23 #import "SDL_uikitappdelegate.h" |
24 #import "SDL_uikitopenglview.h" |
24 #import "SDL_uikitopenglview.h" |
25 #import "SDL_uikitwindow.h" |
25 #import "SDL_uikitwindow.h" |
26 #import "SDL_events_c.h" |
26 #import "SDL_events_c.h" |
27 #import "../SDL_sysvideo.h" |
|
28 #import "jumphack.h" |
27 #import "jumphack.h" |
29 #import "SDL_video.h" |
28 #import "SDL_video.h" |
30 #import "SDL_mixer.h" |
29 #import "SDL_mixer.h" |
31 #import "PascalImports.h" |
30 #import "PascalImports.h" |
32 #import "ObjcExports.h" |
31 #import "ObjcExports.h" |
33 #import "CommodityFunctions.h" |
32 #import "CommodityFunctions.h" |
34 #import "GameSetup.h" |
33 #import "GameSetup.h" |
35 #import "MainMenuViewController.h" |
34 #import "MainMenuViewController.h" |
36 #import "OverlayViewController.h" |
35 #import "OverlayViewController.h" |
|
36 #import "Appirater.h" |
|
37 #include <unistd.h> |
37 |
38 |
38 #ifdef main |
39 #ifdef main |
39 #undef main |
40 #undef main |
40 #endif |
41 #endif |
41 |
42 |
42 #define BLACKVIEW_TAG 17935 |
43 #define BLACKVIEW_TAG 17935 |
43 #define SECONDBLACKVIEW_TAG 48620 |
44 #define SECONDBLACKVIEW_TAG 48620 |
44 #define VALGRIND "/opt/valgrind/bin/valgrind" |
45 #define VALGRIND "/opt/fink/bin/valgrind" |
45 |
46 |
46 int main (int argc, char *argv[]) { |
47 int main (int argc, char *argv[]) { |
47 #ifdef VALGRIND_REXEC |
48 #ifdef VALGRIND_REXEC |
48 // Using the valgrind build config, rexec ourself in valgrind |
49 // Using the valgrind build config, rexec ourself in valgrind |
49 // from http://landonf.bikemonkey.org/code/iphone/iPhone_Simulator_Valgrind.20081224.html |
50 // from http://landonf.bikemonkey.org/code/iphone/iPhone_Simulator_Valgrind.20081224.html |
50 if (argc < 2 || (argc >= 2 && strcmp(argv[1], "-valgrind") != 0)) |
51 if (argc < 2 || (argc >= 2 && strcmp(argv[1], "-valgrind") != 0)) |
51 execl(VALGRIND, VALGRIND, "--leak-check=full", argv[0], "-valgrind", NULL); |
52 execl(VALGRIND, VALGRIND, "--leak-check=full", "--dsymutil=yes", argv[0], "-valgrind", NULL); |
52 #endif |
53 #endif |
53 |
|
54 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
54 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
55 int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
55 int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
56 [pool release]; |
56 [pool release]; |
57 return retVal; |
57 return retVal; |
58 } |
58 } |
171 gameWindow = [[UIApplication sharedApplication] keyWindow]; |
171 gameWindow = [[UIApplication sharedApplication] keyWindow]; |
172 [gameWindow addSubview:self.overlayController.view]; |
172 [gameWindow addSubview:self.overlayController.view]; |
173 } |
173 } |
174 |
174 |
175 // override the direct execution of SDL_main to allow us to implement the frontend (or even using a nib) |
175 // override the direct execution of SDL_main to allow us to implement the frontend (or even using a nib) |
176 -(void) applicationDidFinishLaunching:(UIApplication *)application { |
176 -(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |
177 [application setStatusBarHidden:YES]; |
177 [application setStatusBarHidden:YES]; |
178 |
178 |
179 self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
179 self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
180 |
180 |
181 if (IS_IPAD()) |
181 if (IS_IPAD()) |
225 -(void) applicationWillResignActive:(UIApplication *)application { |
228 -(void) applicationWillResignActive:(UIApplication *)application { |
226 UIDevice* device = [UIDevice currentDevice]; |
229 UIDevice* device = [UIDevice currentDevice]; |
227 if ([device respondsToSelector:@selector(isMultitaskingSupported)] && |
230 if ([device respondsToSelector:@selector(isMultitaskingSupported)] && |
228 device.multitaskingSupported && |
231 device.multitaskingSupported && |
229 self.isInGame) { |
232 self.isInGame) { |
230 // there is a bug on iphone that presents a sdl view with a black screen, so it returns to frontend |
233 // multiasking in-game works only for ios >= 4.2, returns a black screen on other verions |
231 if (IS_IPAD()) |
234 if (NSClassFromString(@"UIPrintInfo")) |
232 HW_suspend(); |
235 HW_suspend(); |
233 else { |
236 else { |
234 // while screen is loading you can't call HW_terminate() so we close the app |
237 // so the game returns to the configuration view |
235 if (isGameRunning()) |
238 if (isGameRunning()) |
236 HW_terminate(NO); |
239 HW_terminate(NO); |
237 else { |
240 else { |
238 // force app closure |
241 // while screen is loading you can't call HW_terminate() so we close the app |
239 SDL_SendQuit(); |
242 SDL_SendQuit(); |
240 HW_terminate(YES); |
243 HW_terminate(YES); |
241 longjmp(*(jump_env()), 1); |
244 longjmp(*(jump_env()), 1); |
242 } |
245 } |
243 } |
246 } |