60 +(SDLUIKitDelegate *)sharedAppDelegate { |
61 +(SDLUIKitDelegate *)sharedAppDelegate { |
61 /* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */ |
62 /* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */ |
62 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
63 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
63 } |
64 } |
64 |
65 |
|
66 void preSDL_main(){ |
|
67 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
68 |
|
69 SDL_main(forward_argc, forward_argv); |
|
70 |
|
71 [pool release]; |
|
72 } |
65 |
73 |
66 - (void) startSDLgame { |
74 - (void) startSDLgame { |
67 pthread_t threadID; |
75 pthread_t threadID; |
68 |
76 |
69 pthread_create (&threadID, NULL, (void *) (*engineProtocolThread), NULL); |
77 if (NO == isServerRunning) { |
70 pthread_detach (threadID); |
78 // don't start another server because the port is already bound |
|
79 pthread_create (&threadID, NULL, (void *) (*engineProtocolThread), NULL); |
|
80 pthread_detach (threadID); |
|
81 isServerRunning = YES; |
|
82 } |
71 |
83 |
72 setupArgsForLocalPlay(); |
84 setupArgsForLocalPlay(); |
73 |
85 |
|
86 // remove the current view to free resources |
|
87 [UIView beginAnimations:nil context:NULL]; |
|
88 [UIView setAnimationDuration:1.5]; |
|
89 controller.view.alpha = 0; |
|
90 [UIView commitAnimations]; |
|
91 [controller.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.5]; |
|
92 //[controller.view removeFromSuperview]; |
|
93 |
74 /* run the user's application, passing argc and argv */ |
94 /* run the user's application, passing argc and argv */ |
75 NSLog(@"Game is launching..."); |
95 NSLog(@"Game is launching..."); |
76 SDL_main(forward_argc, forward_argv); |
96 /*pthread_create (&threadID, NULL, (void *) (*preSDL_main), NULL); |
|
97 pthread_detach (threadID);*/ |
|
98 int res = SDL_main(forward_argc, forward_argv); |
|
99 |
77 // can't reach here yet |
100 // can't reach here yet |
78 NSLog(@"Game exited"); |
101 NSLog(@"Game exited with status %d", res); |
79 |
102 |
80 //[self performSelector:@selector(makeNewView) withObject:nil afterDelay:0.0]; |
103 //[self performSelector:@selector(makeNewView) withObject:nil afterDelay:0.0]; |
81 /* exit, passing the return status from the user's application */ |
104 /* exit, passing the return status from the user's application */ |
82 //exit(exit_status); |
105 //exit(exit_status); |
83 } |
106 } |
89 /* Set working directory to resource path */ |
112 /* Set working directory to resource path */ |
90 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
113 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
91 //#import "SoundEffect.h" |
114 //#import "SoundEffect.h" |
92 // SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]]; |
115 // SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]]; |
93 // SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]]; |
116 // SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]]; |
94 |
|
95 [window addSubview:controller.view]; |
117 [window addSubview:controller.view]; |
96 [window makeKeyAndVisible]; |
118 [window makeKeyAndVisible]; |
97 |
|
98 // REMOVE ME when you're done with reverse engineering the protocol |
|
99 [self performSelector:@selector(startSDLgame)]; |
|
100 } |
119 } |
101 |
120 |
102 -(void) applicationWillTerminate:(UIApplication *)application { |
121 -(void) applicationWillTerminate:(UIApplication *)application { |
103 /* free the memory we used to hold copies of argc and argv */ |
122 /* free the memory we used to hold copies of argc and argv */ |
104 int i; |
123 int i; |
105 for (i=0; i < forward_argc; i++) { |
124 for (i=0; i < forward_argc; i++) { |
106 free(forward_argv[i]); |
125 free(forward_argv[i]); |
107 } |
126 } |
108 free(forward_argv); |
127 free(forward_argv); |
109 SDL_SendQuit(); |
128 SDL_SendQuit(); |
110 /* hack to prevent automatic termination. See SDL_uikitevents.m for details */ |
129 /* hack to prevent automatic termination. See SDL_uikitevents.m for details */ |
111 // have to remove this otherwise game goes on when pushing the home button |
130 // have to remove this otherwise game goes on when pushing the home button |
112 //longjmp(*(jump_env()), 1); |
131 //longjmp(*(jump_env()), 1); |
113 |
|
114 NSLog(@"Closing App..."); |
|
115 } |
132 } |
116 |
133 |
117 -(void) applicationWillResignActive:(UIApplication*)application |
134 -(void) applicationWillResignActive:(UIApplication*)application |
118 { |
135 { |
119 // NSLog(@"%@", NSStringFromSelector(_cmd)); |
136 // NSLog(@"%@", NSStringFromSelector(_cmd)); |
131 NSLog(@"Rotating..."); |
148 NSLog(@"Rotating..."); |
132 return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); |
149 return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); |
133 } |
150 } |
134 */ |
151 */ |
135 |
152 |
|
153 void IPH_returnFrontend (void) { |
|
154 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
155 |
|
156 [[[SDLUIKitDelegate sharedAppDelegate].window viewWithTag:54867] removeFromSuperview]; |
|
157 [[SDLUIKitDelegate sharedAppDelegate].window addSubview:[SDLUIKitDelegate sharedAppDelegate].controller.view]; |
|
158 // [[SDLUIKitDelegate sharedAppDelegate].window makeKeyAndVisible]; |
|
159 NSLog(@"Game exited..."); |
|
160 // pthread_exit(NULL); |
|
161 [pool release]; |
|
162 exit(0); |
|
163 // while(1); //prevent exiting |
|
164 } |
|
165 |
|
166 |
136 -(void) dealloc { |
167 -(void) dealloc { |
137 [controller release]; |
168 [controller release]; |
138 [window release]; |
169 [window release]; |
139 [super dealloc]; |
170 [super dealloc]; |
140 } |
171 } |