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