author | koda |
Fri, 09 Apr 2010 11:09:26 +0000 | |
changeset 3328 | fe87c2242984 |
parent 3318 | 591c42242106 |
child 3335 | 2520ee7a5484 |
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 |
||
3316 | 38 |
#define VALGRIND "/opt/valgrind/bin/valgrind" |
39 |
||
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
|
40 |
int main (int argc, char *argv[]) { |
3316 | 41 |
#ifdef VALGRIND_REXEC |
42 |
// Using the valgrind build config, rexec ourself in valgrind |
|
43 |
// from http://landonf.bikemonkey.org/code/iphone/iPhone_Simulator_Valgrind.20081224.html |
|
44 |
if (argc < 2 || (argc >= 2 && strcmp(argv[1], "-valgrind") != 0)) { |
|
45 |
execl(VALGRIND, VALGRIND, "--leak-check=full", "--show-reachable=yes", argv[0], "-valgrind", NULL); |
|
46 |
} |
|
47 |
#endif |
|
48 |
||
3027 | 49 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
2723 | 50 |
int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
51 |
[pool release]; |
|
52 |
return retVal; |
|
2688 | 53 |
} |
54 |
||
55 |
@implementation SDLUIKitDelegate |
|
3316 | 56 |
@synthesize uiwindow, window, viewController; |
2688 | 57 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
58 |
// convenience method |
2688 | 59 |
+(SDLUIKitDelegate *)sharedAppDelegate { |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
60 |
// the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method |
2688 | 61 |
return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
62 |
} |
|
63 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
64 |
-(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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
} 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
|
72 |
return nil; |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
73 |
} |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
74 |
|
2696 | 75 |
-(void) dealloc { |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
76 |
[uiwindow release]; |
2696 | 77 |
[super dealloc]; |
78 |
} |
|
79 |
||
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
80 |
// 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
|
81 |
-(IBAction) startSDLgame { |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
82 |
[viewController disappear]; |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
83 |
|
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
84 |
// 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
|
85 |
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
|
86 |
[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
|
87 |
const char **gameArgs = [setup getSettings]; |
2772 | 88 |
[setup release]; |
3006 | 89 |
|
3316 | 90 |
OverlayViewController *overlayController; |
3027 | 91 |
// overlay with controls, become visible after 2 seconds |
3318 | 92 |
overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil]; |
3317
198ec44b6d92
minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents:
3316
diff
changeset
|
93 |
|
3027 | 94 |
[uiwindow addSubview:overlayController.view]; |
3063 | 95 |
[overlayController release]; |
96 |
||
97 |
isInGame = YES; |
|
3006 | 98 |
Game(gameArgs); // this is the pascal fuction that starts the game |
3063 | 99 |
isInGame = NO; |
3006 | 100 |
|
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
101 |
free(gameArgs); |
3006 | 102 |
[overlayController.view removeFromSuperview]; |
103 |
||
3027 | 104 |
[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
|
105 |
} |
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
|
106 |
|
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
107 |
// get a path-to-file string |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
108 |
-(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
|
109 |
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
|
110 |
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
|
111 |
return [documentsDirectory stringByAppendingPathComponent:fileName]; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
112 |
} |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
113 |
|
2688 | 114 |
// override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
115 |
-(void) applicationDidFinishLaunching:(UIApplication *)application { |
|
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
3063
diff
changeset
|
116 |
//[application setStatusBarHidden:YES animated:NO]; |
3199 | 117 |
//[application setStatusBarHidden:YES withAnimation:NO]; |
3270 | 118 |
[application setStatusBarHidden:YES]; |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
3063
diff
changeset
|
119 |
[application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; |
2740 | 120 |
|
121 |
self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
|
122 |
self.uiwindow.backgroundColor = [UIColor blackColor]; |
|
2738
bfccb2ec4334
new graphics from Tiy and frontend is loaded in landscape mode
koda
parents:
2723
diff
changeset
|
123 |
|
3305 | 124 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
125 |
self.viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil]; |
|
126 |
else |
|
127 |
self.viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil]; |
|
3063 | 128 |
[uiwindow addSubview:viewController.view]; |
129 |
[viewController release]; |
|
2720 | 130 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
131 |
// Set working directory to resource path |
2688 | 132 |
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
2696 | 133 |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
134 |
[uiwindow makeKeyAndVisible]; |
2740 | 135 |
[uiwindow layoutSubviews]; |
2688 | 136 |
} |
137 |
||
138 |
-(void) applicationWillTerminate:(UIApplication *)application { |
|
139 |
SDL_SendQuit(); |
|
3063 | 140 |
if (isInGame) { |
141 |
HW_terminate(YES); |
|
3250
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3199
diff
changeset
|
142 |
// hack to prevent automatic termination. See SDL_uikitevents.m for details |
3063 | 143 |
longjmp(*(jump_env()), 1); |
144 |
} |
|
2688 | 145 |
} |
146 |
||
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
147 |
-(void) applicationWillResignActive:(UIApplication *)application { |
3063 | 148 |
NSLog(@"%@", NSStringFromSelector(_cmd)); |
149 |
if (isInGame) HW_pause(); |
|
150 |
//SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
|
2688 | 151 |
} |
152 |
||
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
153 |
-(void) applicationDidBecomeActive:(UIApplication *)application { |
3063 | 154 |
NSLog(@"%@", NSStringFromSelector(_cmd)); |
155 |
if (isInGame) HW_pause(); |
|
156 |
//SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
|
2688 | 157 |
} |
158 |
||
159 |
@end |