author | koda |
Sun, 04 Apr 2010 19:51:53 +0000 | |
changeset 3305 | 91074496d5c9 |
parent 3270 | 9bd8fb1707b9 |
child 3316 | 52f0482b043f |
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" |
2698 | 30 |
#import "PascalImports.h" |
2772 | 31 |
#import "MainMenuViewController.h" |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
3063
diff
changeset
|
32 |
#import "OverlayViewController.h" |
2688 | 33 |
|
34 |
#ifdef main |
|
35 |
#undef main |
|
36 |
#endif |
|
37 |
||
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2701
diff
changeset
|
38 |
int main (int argc, char *argv[]) { |
3027 | 39 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
2723 | 40 |
int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
41 |
[pool release]; |
|
42 |
return retVal; |
|
2688 | 43 |
} |
44 |
||
45 |
@implementation SDLUIKitDelegate |
|
3006 | 46 |
@synthesize uiwindow, window, viewController, overlayController; |
2688 | 47 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
48 |
// convenience method |
2688 | 49 |
+(SDLUIKitDelegate *)sharedAppDelegate { |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
50 |
// the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method |
2688 | 51 |
return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
52 |
} |
|
53 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
54 |
-(id) init { |
3122
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3116
diff
changeset
|
55 |
if (self = [super init]){ |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3116
diff
changeset
|
56 |
self.uiwindow = nil; |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3116
diff
changeset
|
57 |
self.window = NULL; |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3116
diff
changeset
|
58 |
self.viewController = nil; |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3116
diff
changeset
|
59 |
self.overlayController = nil; |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3116
diff
changeset
|
60 |
isInGame = NO; |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3116
diff
changeset
|
61 |
return self; |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3116
diff
changeset
|
62 |
} else |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3116
diff
changeset
|
63 |
return nil; |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
64 |
} |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
65 |
|
2696 | 66 |
-(void) dealloc { |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
67 |
[uiwindow release]; |
2696 | 68 |
[super dealloc]; |
69 |
} |
|
70 |
||
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
71 |
// main routine for calling the actual game engine |
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
|
72 |
-(IBAction) startSDLgame { |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
73 |
[viewController disappear]; |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
74 |
|
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
75 |
// pull out useful configuration info from various files |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2701
diff
changeset
|
76 |
GameSetup *setup = [[GameSetup 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
|
77 |
[setup startThread:@"engineProtocol"]; |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2701
diff
changeset
|
78 |
const char **gameArgs = [setup getSettings]; |
2772 | 79 |
[setup release]; |
3006 | 80 |
|
3027 | 81 |
// overlay with controls, become visible after 2 seconds |
3305 | 82 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
83 |
overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController-iPad" bundle:nil]; |
|
84 |
else |
|
85 |
overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController-iPhone" bundle:nil]; |
|
86 |
||
3027 | 87 |
[uiwindow addSubview:overlayController.view]; |
3063 | 88 |
[overlayController release]; |
89 |
||
90 |
isInGame = YES; |
|
3006 | 91 |
Game(gameArgs); // this is the pascal fuction that starts the game |
3063 | 92 |
isInGame = NO; |
3006 | 93 |
|
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
94 |
free(gameArgs); |
3006 | 95 |
[overlayController.view removeFromSuperview]; |
96 |
||
3027 | 97 |
[viewController appear]; |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2701
diff
changeset
|
98 |
} |
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2701
diff
changeset
|
99 |
|
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
100 |
// get a path-to-file string |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
101 |
-(NSString *)dataFilePath:(NSString *)fileName { |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
102 |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
103 |
NSString *documentsDirectory = [paths objectAtIndex:0]; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
104 |
return [documentsDirectory stringByAppendingPathComponent:fileName]; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
105 |
} |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
106 |
|
2688 | 107 |
// override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
108 |
-(void) applicationDidFinishLaunching:(UIApplication *)application { |
|
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
3063
diff
changeset
|
109 |
//[application setStatusBarHidden:YES animated:NO]; |
3199 | 110 |
//[application setStatusBarHidden:YES withAnimation:NO]; |
3270 | 111 |
[application setStatusBarHidden:YES]; |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
3063
diff
changeset
|
112 |
[application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; |
2740 | 113 |
|
114 |
self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
|
115 |
self.uiwindow.backgroundColor = [UIColor blackColor]; |
|
2738
bfccb2ec4334
new graphics from Tiy and frontend is loaded in landscape mode
koda
parents:
2723
diff
changeset
|
116 |
|
3305 | 117 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
118 |
self.viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil]; |
|
119 |
else |
|
120 |
self.viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil]; |
|
3063 | 121 |
[uiwindow addSubview:viewController.view]; |
122 |
[viewController release]; |
|
2720 | 123 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
124 |
// Set working directory to resource path |
2688 | 125 |
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
2696 | 126 |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
127 |
[uiwindow makeKeyAndVisible]; |
2740 | 128 |
[uiwindow layoutSubviews]; |
2688 | 129 |
} |
130 |
||
131 |
-(void) applicationWillTerminate:(UIApplication *)application { |
|
132 |
SDL_SendQuit(); |
|
3063 | 133 |
if (isInGame) { |
134 |
HW_terminate(YES); |
|
3250
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3199
diff
changeset
|
135 |
// hack to prevent automatic termination. See SDL_uikitevents.m for details |
3063 | 136 |
longjmp(*(jump_env()), 1); |
137 |
} |
|
2688 | 138 |
} |
139 |
||
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
140 |
-(void) applicationWillResignActive:(UIApplication *)application { |
3063 | 141 |
NSLog(@"%@", NSStringFromSelector(_cmd)); |
142 |
if (isInGame) HW_pause(); |
|
143 |
//SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
|
2688 | 144 |
} |
145 |
||
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
146 |
-(void) applicationDidBecomeActive:(UIApplication *)application { |
3063 | 147 |
NSLog(@"%@", NSStringFromSelector(_cmd)); |
148 |
if (isInGame) HW_pause(); |
|
149 |
//SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
|
2688 | 150 |
} |
151 |
||
152 |
@end |