author | koda |
Wed, 13 Jan 2010 09:41:35 +0000 | |
changeset 2693 | 3207e0eacd43 |
parent 2692 | ce9992075118 |
child 2696 | 41aa7b56c17b |
permissions | -rw-r--r-- |
2688 | 1 |
/* |
2 |
SDL - Simple DirectMedia Layer |
|
3 |
Copyright (C) 1997-2009 Sam Lantinga |
|
4 |
||
5 |
This library is free software; you can redistribute it and/or |
|
6 |
modify it under the terms of the GNU Lesser General Public |
|
7 |
License as published by the Free Software Foundation; either |
|
8 |
version 2.1 of the License, or (at your option) any later version. |
|
9 |
||
10 |
This library is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
Lesser General Public License for more details. |
|
14 |
||
15 |
You should have received a copy of the GNU Lesser General Public |
|
16 |
License along with this library; if not, write to the Free Software |
|
17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
||
19 |
Sam Lantinga, mods for Hedgewars by Vittorio Giovara |
|
20 |
slouken@libsdl.org, vittorio.giovara@gmail.com |
|
21 |
*/ |
|
22 |
||
2691 | 23 |
#import <pthread.h> |
2688 | 24 |
#import "SDL_uikitappdelegate.h" |
25 |
#import "SDL_uikitopenglview.h" |
|
26 |
#import "SDL_events_c.h" |
|
27 |
#import "jumphack.h" |
|
28 |
#import "SDL_video.h" |
|
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
29 |
#import "GameSetup.h" |
2688 | 30 |
|
31 |
#ifdef main |
|
32 |
#undef main |
|
33 |
#endif |
|
34 |
||
35 |
extern int SDL_main(int argc, char *argv[]); |
|
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
36 |
BOOL isServerRunning = NO; |
2688 | 37 |
|
38 |
int main (int argc, char **argv) { |
|
39 |
int i; |
|
40 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
41 |
||
42 |
/* store arguments */ |
|
43 |
forward_argc = argc; |
|
44 |
forward_argv = (char **)malloc(argc * sizeof(char *)); |
|
45 |
for (i = 0; i < argc; i++) { |
|
46 |
forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char)); |
|
47 |
strcpy(forward_argv[i], argv[i]); |
|
48 |
} |
|
49 |
||
50 |
/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */ |
|
51 |
UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate"); |
|
52 |
||
53 |
[pool release]; |
|
54 |
} |
|
55 |
||
56 |
@implementation SDLUIKitDelegate |
|
57 |
||
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
58 |
@synthesize window, windowID, controller, setup; |
2688 | 59 |
|
60 |
/* convenience method */ |
|
61 |
+(SDLUIKitDelegate *)sharedAppDelegate { |
|
62 |
/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */ |
|
63 |
return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
|
64 |
} |
|
65 |
||
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
66 |
-(void) launchSDL_main{ |
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
67 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
68 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
69 |
// must setup arguments in the same thread |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
70 |
[setup setArgsForLocalPlay]; |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
71 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
72 |
// run the user's application, passing argc and argv |
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
73 |
SDL_main(forward_argc, forward_argv); |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
74 |
|
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
75 |
[pool release]; |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
76 |
} |
2691 | 77 |
|
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
78 |
-(IBAction) startSDLgame { |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
79 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
80 |
[setup startThread:@"engineProtocol"]; |
2691 | 81 |
|
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
82 |
// remove the current view to free resources |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
83 |
[UIView beginAnimations:nil context:NULL]; |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
84 |
[UIView setAnimationDuration:1.5]; |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
85 |
controller.view.alpha = 0; |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
86 |
[UIView commitAnimations]; |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
87 |
[controller.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.5]; |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
88 |
//[controller.view removeFromSuperview]; |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
89 |
|
2691 | 90 |
NSLog(@"Game is launching..."); |
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
91 |
|
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
92 |
[NSThread detachNewThreadSelector:@selector(launchSDL_main) toTarget:self withObject:nil]; |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
93 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
94 |
//SDL_main(forward_argc, forward_argv); |
2688 | 95 |
|
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
96 |
|
2688 | 97 |
} |
98 |
||
99 |
// override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
|
100 |
-(void) applicationDidFinishLaunching:(UIApplication *)application { |
|
101 |
[application setStatusBarHidden:YES animated:NO]; |
|
102 |
||
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
103 |
setup = [[GameSetup alloc] init]; |
2688 | 104 |
/* Set working directory to resource path */ |
105 |
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
|
2689 | 106 |
//#import "SoundEffect.h" |
107 |
// SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]]; |
|
108 |
// SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]]; |
|
2688 | 109 |
[window addSubview:controller.view]; |
110 |
[window makeKeyAndVisible]; |
|
111 |
} |
|
112 |
||
113 |
-(void) applicationWillTerminate:(UIApplication *)application { |
|
114 |
/* free the memory we used to hold copies of argc and argv */ |
|
115 |
int i; |
|
116 |
for (i=0; i < forward_argc; i++) { |
|
117 |
free(forward_argv[i]); |
|
118 |
} |
|
119 |
free(forward_argv); |
|
120 |
SDL_SendQuit(); |
|
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
121 |
/* hack to prevent automatic termination. See SDL_uikitevents.m for details */ |
2688 | 122 |
// have to remove this otherwise game goes on when pushing the home button |
123 |
//longjmp(*(jump_env()), 1); |
|
124 |
} |
|
125 |
||
126 |
-(void) applicationWillResignActive:(UIApplication*)application |
|
127 |
{ |
|
128 |
// NSLog(@"%@", NSStringFromSelector(_cmd)); |
|
129 |
SDL_SendWindowEvent(self.windowID, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
|
130 |
} |
|
131 |
||
132 |
-(void) applicationDidBecomeActive:(UIApplication*)application |
|
133 |
{ |
|
134 |
// NSLog(@"%@", NSStringFromSelector(_cmd)); |
|
135 |
SDL_SendWindowEvent(self.windowID, SDL_WINDOWEVENT_RESTORED, 0, 0); |
|
136 |
} |
|
137 |
||
138 |
/* |
|
139 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
140 |
NSLog(@"Rotating..."); |
|
141 |
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); |
|
142 |
} |
|
143 |
*/ |
|
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
144 |
+(void) resetFrontend { |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
145 |
[[[SDLUIKitDelegate sharedAppDelegate].window viewWithTag:54867] removeFromSuperview]; |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
146 |
[[SDLUIKitDelegate sharedAppDelegate].window addSubview:[SDLUIKitDelegate sharedAppDelegate].controller.view]; |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
147 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
148 |
[UIView beginAnimations:nil context:NULL]; |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
149 |
[UIView setAnimationDuration:1]; |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
150 |
[SDLUIKitDelegate sharedAppDelegate].controller.view.alpha = 1; |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
151 |
[UIView commitAnimations]; |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
152 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
153 |
[[SDLUIKitDelegate sharedAppDelegate].window makeKeyAndVisible]; |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
154 |
} |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
155 |
|
2688 | 156 |
|
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
157 |
void IPH_returnFrontend (void) { |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
158 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
159 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
160 |
[SDLUIKitDelegate resetFrontend]; |
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
161 |
NSLog(@"Game exited..."); |
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
162 |
|
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
163 |
[pool release]; |
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
164 |
[NSThread exit]; |
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
165 |
} |
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
166 |
|
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
167 |
|
2688 | 168 |
-(void) dealloc { |
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
2692
diff
changeset
|
169 |
[setup release]; |
2688 | 170 |
[controller release]; |
171 |
[window release]; |
|
172 |
[super dealloc]; |
|
173 |
} |
|
174 |
||
175 |
@end |