77 [setup release]; |
77 [setup release]; |
78 |
78 |
79 // overlay with controls, become visible after 2 seconds |
79 // overlay with controls, become visible after 2 seconds |
80 overlayController = [[overlayViewController alloc] initWithNibName:@"overlayViewController" bundle:nil]; |
80 overlayController = [[overlayViewController alloc] initWithNibName:@"overlayViewController" bundle:nil]; |
81 [uiwindow addSubview:overlayController.view]; |
81 [uiwindow addSubview:overlayController.view]; |
82 |
82 [overlayController release]; |
|
83 |
|
84 isInGame = YES; |
83 Game(gameArgs); // this is the pascal fuction that starts the game |
85 Game(gameArgs); // this is the pascal fuction that starts the game |
|
86 isInGame = NO; |
84 |
87 |
85 free(gameArgs); |
88 free(gameArgs); |
86 [overlayController.view removeFromSuperview]; |
89 [overlayController.view removeFromSuperview]; |
87 [overlayController release]; |
|
88 |
90 |
89 [viewController appear]; |
91 [viewController appear]; |
90 } |
92 } |
91 |
93 |
92 // get a path-to-file string |
94 // get a path-to-file string |
103 |
105 |
104 self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
106 self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
105 self.uiwindow.backgroundColor = [UIColor blackColor]; |
107 self.uiwindow.backgroundColor = [UIColor blackColor]; |
106 |
108 |
107 self.viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil]; |
109 self.viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil]; |
|
110 [uiwindow addSubview:viewController.view]; |
|
111 [viewController release]; |
108 |
112 |
109 // Set working directory to resource path |
113 // Set working directory to resource path |
110 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
114 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
111 |
115 |
112 [uiwindow addSubview:viewController.view]; |
|
113 [uiwindow makeKeyAndVisible]; |
116 [uiwindow makeKeyAndVisible]; |
114 [uiwindow layoutSubviews]; |
117 [uiwindow layoutSubviews]; |
115 } |
118 } |
116 |
119 |
117 -(void) applicationWillTerminate:(UIApplication *)application { |
120 -(void) applicationWillTerminate:(UIApplication *)application { |
118 SDL_SendQuit(); |
121 SDL_SendQuit(); |
119 // hack to prevent automatic termination. See SDL_uikitevents.m for details |
122 if (isInGame) { |
120 // have to remove this otherwise game goes on when pushing the home button |
123 HW_terminate(YES); |
121 //longjmp(*(jump_env()), 1); |
124 // hack to prevent automatic termination. See SDL_uikitevents.m for details |
|
125 longjmp(*(jump_env()), 1); |
|
126 } |
122 } |
127 } |
123 |
128 |
124 -(void) applicationWillResignActive:(UIApplication *)application { |
129 -(void) applicationWillResignActive:(UIApplication *)application { |
125 //NSLog(@"%@", NSStringFromSelector(_cmd)); |
130 NSLog(@"%@", NSStringFromSelector(_cmd)); |
126 SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
131 if (isInGame) HW_pause(); |
|
132 //SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
127 } |
133 } |
128 |
134 |
129 -(void) applicationDidBecomeActive:(UIApplication *)application { |
135 -(void) applicationDidBecomeActive:(UIApplication *)application { |
130 //NSLog(@"%@", NSStringFromSelector(_cmd)); |
136 NSLog(@"%@", NSStringFromSelector(_cmd)); |
131 SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
137 if (isInGame) HW_pause(); |
|
138 //SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
132 } |
139 } |
133 |
140 |
134 @end |
141 @end |