91 [setup startThread:@"engineProtocol"]; |
86 [setup startThread:@"engineProtocol"]; |
92 const char **gameArgs = [setup getSettings]; |
87 const char **gameArgs = [setup getSettings]; |
93 [setup release]; |
88 [setup release]; |
94 |
89 |
95 // since the sdlwindow is not yet created, we add the overlayController with a delay |
90 // since the sdlwindow is not yet created, we add the overlayController with a delay |
96 [self performSelector:@selector(displayOverlayLater) withObject:nil afterDelay:0.5]; |
91 [self performSelector:@selector(displayOverlayLater) withObject:nil afterDelay:0.3]; |
97 |
92 |
98 // this is the pascal fuction that starts the game (wrapped around isInGame) |
93 // this is the pascal fuction that starts the game (wrapped around isInGame) |
99 isInGame = YES; |
94 isInGame = YES; |
100 Game(gameArgs); |
95 Game(gameArgs); |
101 isInGame = NO; |
96 isInGame = NO; |
|
97 free(gameArgs); |
102 |
98 |
103 free(gameArgs); |
99 UIWindow *aWin = [[[UIApplication sharedApplication] windows] objectAtIndex:0]; |
|
100 [aWin makeKeyAndVisible]; |
|
101 aWin = [[[UIApplication sharedApplication] windows] lastObject]; |
|
102 [aWin removeFromSuperview]; |
|
103 |
|
104 DLog(@"%@",[[UIApplication sharedApplication] windows]); |
104 |
105 |
105 [UIView beginAnimations:@"inserting main controller" context:NULL]; |
106 [UIView beginAnimations:@"inserting main controller" context:NULL]; |
106 [UIView setAnimationDuration:1]; |
107 [UIView setAnimationDuration:1]; |
107 mainViewController.view.alpha = 1; |
108 mainViewController.view.alpha = 1; |
108 [UIView commitAnimations]; |
109 [UIView commitAnimations]; |
109 } |
110 } |
110 |
111 |
111 -(void) displayOverlayLater { |
112 -(void) displayOverlayLater { |
112 // overlay with controls, become visible after 4 seconds, with a transparency effect |
113 // overlay with controls, become visible later, with a transparency effect |
113 OverlayViewController *overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil]; |
114 OverlayViewController *overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil]; |
114 |
115 |
|
116 // keyWindow is the frontmost window |
115 [[[UIApplication sharedApplication] keyWindow] addSubview:overlayController.view]; |
117 [[[UIApplication sharedApplication] keyWindow] addSubview:overlayController.view]; |
116 [overlayController release]; |
118 [overlayController release]; |
117 } |
119 } |
118 |
120 |
119 // override the direct execution of SDL_main to allow us to implement the frontend (or even using a nib) |
121 // override the direct execution of SDL_main to allow us to implement the frontend (or even using a nib) |
120 -(void) applicationDidFinishLaunching:(UIApplication *)application { |
122 -(void) applicationDidFinishLaunching:(UIApplication *)application { |
121 [application setStatusBarHidden:YES]; |
123 [application setStatusBarHidden:YES]; |
122 [application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; |
124 [application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; |
123 |
125 |
124 uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
126 UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
125 uiwindow.backgroundColor = [UIColor blackColor]; |
127 uiwindow.backgroundColor = [UIColor blackColor]; |
126 // needed to keep the app running after a game (gets released in sdl_uikitwindow) |
|
127 [uiwindow retain]; |
|
128 |
128 |
129 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
129 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
130 mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil]; |
130 mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil]; |
131 else |
131 else |
132 mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil]; |
132 mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil]; |
146 longjmp(*(jump_env()), 1); |
146 longjmp(*(jump_env()), 1); |
147 } |
147 } |
148 } |
148 } |
149 |
149 |
150 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application { |
150 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application { |
|
151 if (mainViewController.view.superview == nil) |
|
152 mainViewController = nil; |
|
153 MSG_MEMCLEAN(); |
151 print_free_memory(); |
154 print_free_memory(); |
152 } |
155 } |
153 |
156 |
154 -(void) applicationWillResignActive:(UIApplication *)application { |
157 -(void) applicationWillResignActive:(UIApplication *)application { |
155 //NSLog(@"%@", NSStringFromSelector(_cmd)); |
|
156 if (isInGame) { |
158 if (isInGame) { |
157 HW_pause(); |
159 HW_pause(); |
158 |
160 |
159 /* |
|
160 // Send every window on every screen a MINIMIZED event. |
161 // Send every window on every screen a MINIMIZED event. |
161 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
162 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
162 if (!_this) |
163 if (!_this) |
163 return; |
164 return; |
164 |
165 |
167 const SDL_VideoDisplay *display = &_this->displays[i]; |
168 const SDL_VideoDisplay *display = &_this->displays[i]; |
168 SDL_Window *window; |
169 SDL_Window *window; |
169 for (window = display->windows; window != nil; window = window->next) |
170 for (window = display->windows; window != nil; window = window->next) |
170 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
171 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
171 } |
172 } |
172 */ |
|
173 } |
173 } |
174 } |
174 } |
175 |
175 |
176 -(void) applicationDidBecomeActive:(UIApplication *)application { |
176 -(void) applicationDidBecomeActive:(UIApplication *)application { |
177 //NSLog(@"%@", NSStringFromSelector(_cmd)); |
177 //NSLog(@"%@", NSStringFromSelector(_cmd)); |
178 if (isInGame) { |
178 if (isInGame) { |
179 HW_pause(); |
179 HW_pause(); |
180 |
180 |
181 /* |
|
182 // Send every window on every screen a RESTORED event. |
181 // Send every window on every screen a RESTORED event. |
183 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
182 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
184 if (!_this) |
183 if (!_this) |
185 return; |
184 return; |
186 |
185 |