author | koda |
Wed, 21 Apr 2010 01:57:23 +0000 | |
changeset 3361 | cfc6cd502f85 |
parent 3335 | 2520ee7a5484 |
child 3365 | 37ac593e9027 |
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 |
|
3361 | 56 |
@synthesize uiwindow, window; |
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; |
3361 | 68 |
viewController = nil; |
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
|
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 { |
3361 | 76 |
SDL_DestroyWindow(self.window); |
3335 | 77 |
[viewController release]; |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
78 |
[uiwindow release]; |
2696 | 79 |
[super dealloc]; |
80 |
} |
|
81 |
||
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
82 |
// 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
|
83 |
-(IBAction) startSDLgame { |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
84 |
[viewController disappear]; |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
85 |
|
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
86 |
// 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
|
87 |
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
|
88 |
[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
|
89 |
const char **gameArgs = [setup getSettings]; |
2772 | 90 |
[setup release]; |
3006 | 91 |
|
3316 | 92 |
OverlayViewController *overlayController; |
3027 | 93 |
// overlay with controls, become visible after 2 seconds |
3318 | 94 |
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
|
95 |
|
3027 | 96 |
[uiwindow addSubview:overlayController.view]; |
3063 | 97 |
[overlayController release]; |
98 |
||
99 |
isInGame = YES; |
|
3006 | 100 |
Game(gameArgs); // this is the pascal fuction that starts the game |
3063 | 101 |
isInGame = NO; |
3006 | 102 |
|
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
103 |
free(gameArgs); |
3006 | 104 |
[overlayController.view removeFromSuperview]; |
105 |
||
3027 | 106 |
[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
|
107 |
} |
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
|
108 |
|
2688 | 109 |
// override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
110 |
-(void) applicationDidFinishLaunching:(UIApplication *)application { |
|
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
3063
diff
changeset
|
111 |
//[application setStatusBarHidden:YES animated:NO]; |
3199 | 112 |
//[application setStatusBarHidden:YES withAnimation:NO]; |
3270 | 113 |
[application setStatusBarHidden:YES]; |
3116
97dc65a47b15
branch ipad/iphone files to keep compatibility between versions
koda
parents:
3063
diff
changeset
|
114 |
[application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; |
3361 | 115 |
|
2740 | 116 |
self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
117 |
self.uiwindow.backgroundColor = [UIColor blackColor]; |
|
2738
bfccb2ec4334
new graphics from Tiy and frontend is loaded in landscape mode
koda
parents:
2723
diff
changeset
|
118 |
|
3305 | 119 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
3361 | 120 |
viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil]; |
3305 | 121 |
else |
3361 | 122 |
viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil]; |
3063 | 123 |
[uiwindow addSubview:viewController.view]; |
2720 | 124 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
125 |
// Set working directory to resource path |
2688 | 126 |
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
2696 | 127 |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
128 |
[uiwindow makeKeyAndVisible]; |
2740 | 129 |
[uiwindow layoutSubviews]; |
2688 | 130 |
} |
131 |
||
132 |
-(void) applicationWillTerminate:(UIApplication *)application { |
|
133 |
SDL_SendQuit(); |
|
3063 | 134 |
if (isInGame) { |
135 |
HW_terminate(YES); |
|
3250
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3199
diff
changeset
|
136 |
// hack to prevent automatic termination. See SDL_uikitevents.m for details |
3063 | 137 |
longjmp(*(jump_env()), 1); |
138 |
} |
|
2688 | 139 |
} |
140 |
||
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
141 |
-(void) applicationWillResignActive:(UIApplication *)application { |
3335 | 142 |
//NSLog(@"%@", NSStringFromSelector(_cmd)); |
3063 | 143 |
if (isInGame) HW_pause(); |
144 |
//SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
|
2688 | 145 |
} |
146 |
||
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
147 |
-(void) applicationDidBecomeActive:(UIApplication *)application { |
3335 | 148 |
//NSLog(@"%@", NSStringFromSelector(_cmd)); |
3063 | 149 |
if (isInGame) HW_pause(); |
150 |
//SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
|
2688 | 151 |
} |
152 |
||
153 |
@end |