26 #import "SDL_events_c.h" |
26 #import "SDL_events_c.h" |
27 #import "jumphack.h" |
27 #import "jumphack.h" |
28 #import "SDL_video.h" |
28 #import "SDL_video.h" |
29 #import "GameSetup.h" |
29 #import "GameSetup.h" |
30 |
30 |
|
31 //#import "SoundEffect.h" |
|
32 // SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]]; |
|
33 // SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]]; |
|
34 |
|
35 |
31 #ifdef main |
36 #ifdef main |
32 #undef main |
37 #undef main |
33 #endif |
38 #endif |
34 |
39 |
35 extern int SDL_main(int argc, char *argv[]); |
40 extern int SDL_main(int argc, char *argv[]); |
36 BOOL isServerRunning = NO; |
|
37 |
|
38 int main (int argc, char **argv) { |
41 int main (int argc, char **argv) { |
39 int i; |
42 int i; |
40 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
43 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
41 |
44 |
42 /* store arguments */ |
45 /* store arguments */ |
61 +(SDLUIKitDelegate *)sharedAppDelegate { |
64 +(SDLUIKitDelegate *)sharedAppDelegate { |
62 /* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */ |
65 /* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */ |
63 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
66 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
64 } |
67 } |
65 |
68 |
|
69 -(void) dealloc { |
|
70 [setup release]; |
|
71 [controller release]; |
|
72 [window release]; |
|
73 [super dealloc]; |
|
74 } |
|
75 |
66 -(void) launchSDL_main{ |
76 -(void) launchSDL_main{ |
67 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
77 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
68 |
78 |
69 // must setup arguments in the same thread |
79 // must setup arguments in the same thread |
70 [setup setArgsForLocalPlay]; |
80 [setup setArgsForLocalPlay]; |
76 } |
86 } |
77 |
87 |
78 -(IBAction) startSDLgame { |
88 -(IBAction) startSDLgame { |
79 |
89 |
80 [setup startThread:@"engineProtocol"]; |
90 [setup startThread:@"engineProtocol"]; |
81 |
91 [setup loadSettingsFromFile:@"settings.plist" forKey:@"systemSettings"]; |
|
92 |
82 // remove the current view to free resources |
93 // remove the current view to free resources |
83 [UIView beginAnimations:nil context:NULL]; |
94 [UIView beginAnimations:nil context:NULL]; |
84 [UIView setAnimationDuration:1.5]; |
95 [UIView setAnimationDuration:1.5]; |
85 controller.view.alpha = 0; |
96 controller.view.alpha = 0; |
86 [UIView commitAnimations]; |
97 [UIView commitAnimations]; |
87 [controller.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.5]; |
98 [controller.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.5]; |
88 //[controller.view removeFromSuperview]; |
99 |
89 |
|
90 NSLog(@"Game is launching..."); |
100 NSLog(@"Game is launching..."); |
91 |
101 |
92 [NSThread detachNewThreadSelector:@selector(launchSDL_main) toTarget:self withObject:nil]; |
102 [NSThread detachNewThreadSelector:@selector(launchSDL_main) toTarget:self withObject:nil]; |
93 |
103 |
94 //SDL_main(forward_argc, forward_argv); |
|
95 |
|
96 |
|
97 } |
104 } |
98 |
105 |
99 // override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
106 // override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
100 -(void) applicationDidFinishLaunching:(UIApplication *)application { |
107 -(void) applicationDidFinishLaunching:(UIApplication *)application { |
101 [application setStatusBarHidden:YES animated:NO]; |
108 [application setStatusBarHidden:YES animated:NO]; |
102 |
109 |
103 setup = [[GameSetup alloc] init]; |
110 setup = [[GameSetup alloc] init]; |
104 /* Set working directory to resource path */ |
111 /* Set working directory to resource path */ |
105 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
112 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
106 //#import "SoundEffect.h" |
113 |
107 // SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]]; |
|
108 // SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]]; |
|
109 [window addSubview:controller.view]; |
114 [window addSubview:controller.view]; |
110 [window makeKeyAndVisible]; |
115 [window makeKeyAndVisible]; |
111 } |
116 } |
112 |
117 |
113 -(void) applicationWillTerminate:(UIApplication *)application { |
118 -(void) applicationWillTerminate:(UIApplication *)application { |
148 [UIView beginAnimations:nil context:NULL]; |
153 [UIView beginAnimations:nil context:NULL]; |
149 [UIView setAnimationDuration:1]; |
154 [UIView setAnimationDuration:1]; |
150 [SDLUIKitDelegate sharedAppDelegate].controller.view.alpha = 1; |
155 [SDLUIKitDelegate sharedAppDelegate].controller.view.alpha = 1; |
151 [UIView commitAnimations]; |
156 [UIView commitAnimations]; |
152 |
157 |
|
158 [[SDLUIKitDelegate sharedAppDelegate].setup unloadSettings]; |
153 [[SDLUIKitDelegate sharedAppDelegate].window makeKeyAndVisible]; |
159 [[SDLUIKitDelegate sharedAppDelegate].window makeKeyAndVisible]; |
154 } |
160 } |
155 |
161 |
156 |
162 #pragma mark - |
|
163 #pragma mark Convenience methods |
157 void IPH_returnFrontend (void) { |
164 void IPH_returnFrontend (void) { |
158 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
165 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
159 |
166 |
160 [SDLUIKitDelegate resetFrontend]; |
167 [SDLUIKitDelegate resetFrontend]; |
161 NSLog(@"Game exited..."); |
168 NSLog(@"Game exited..."); |