author | nemo |
Fri, 05 Mar 2010 02:51:12 +0000 | |
changeset 2938 | 451f917ac46c |
parent 2803 | 1f446fc5c8ec |
child 3006 | da6023c2745b |
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" |
2688 | 32 |
|
33 |
#ifdef main |
|
34 |
#undef main |
|
35 |
#endif |
|
36 |
||
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
|
37 |
int main (int argc, char *argv[]) { |
2723 | 38 |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
39 |
int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
|
40 |
[pool release]; |
|
41 |
return retVal; |
|
2688 | 42 |
} |
43 |
||
44 |
@implementation SDLUIKitDelegate |
|
45 |
||
2738
bfccb2ec4334
new graphics from Tiy and frontend is loaded in landscape mode
koda
parents:
2723
diff
changeset
|
46 |
@synthesize uiwindow, window, viewController; |
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 { |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
55 |
self = [super init]; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
56 |
self.uiwindow = nil; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
57 |
self.window = NULL; |
2738
bfccb2ec4334
new graphics from Tiy and frontend is loaded in landscape mode
koda
parents:
2723
diff
changeset
|
58 |
self.viewController = nil; |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
59 |
return self; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
60 |
} |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
61 |
|
2696 | 62 |
-(void) dealloc { |
2738
bfccb2ec4334
new graphics from Tiy and frontend is loaded in landscape mode
koda
parents:
2723
diff
changeset
|
63 |
[viewController release]; |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
64 |
[uiwindow release]; |
2696 | 65 |
[super dealloc]; |
66 |
} |
|
67 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
68 |
#pragma mark - |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
69 |
#pragma mark Custom stuff |
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
|
70 |
-(IBAction) startSDLgame { |
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
|
71 |
NSAutoreleasePool *internal_pool = [[NSAutoreleasePool alloc] init]; |
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
|
72 |
|
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
|
73 |
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
|
74 |
[setup startThread:@"engineProtocol"]; |
2696 | 75 |
|
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
76 |
// remove the current view to free resources |
2698 | 77 |
[UIView beginAnimations:@"removing main controller" context:NULL]; |
78 |
[UIView setAnimationDuration:1]; |
|
2743 | 79 |
self.viewController.mainView.alpha = 0; |
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
80 |
[UIView commitAnimations]; |
2698 | 81 |
|
2691 | 82 |
NSLog(@"Game is launching..."); |
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
|
83 |
const char **gameArgs = [setup getSettings]; |
2772 | 84 |
[setup release]; |
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 |
|
2772 | 86 |
// this is the pascal fuction that starts the game |
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 |
Game(gameArgs); |
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 |
|
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 |
free(gameArgs); |
2698 | 90 |
NSLog(@"Game is exting..."); |
91 |
||
2740 | 92 |
[uiwindow addSubview: viewController.view]; |
93 |
[uiwindow makeKeyAndVisible]; |
|
94 |
||
2698 | 95 |
[UIView beginAnimations:@"inserting main controller" context:NULL]; |
96 |
[UIView setAnimationDuration:1]; |
|
2743 | 97 |
self.viewController.mainView.alpha = 1; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
98 |
[UIView commitAnimations]; |
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
|
99 |
|
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
|
100 |
[internal_pool release]; |
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
|
101 |
} |
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
|
102 |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
103 |
-(NSString *)dataFilePath: (NSString *)fileName { |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
return [documentsDirectory stringByAppendingPathComponent:fileName]; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
107 |
} |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
108 |
|
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
109 |
#pragma mark - |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
110 |
#pragma mark SDLUIKitDelegate methods |
2688 | 111 |
// override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
112 |
-(void) applicationDidFinishLaunching:(UIApplication *)application { |
|
113 |
[application setStatusBarHidden:YES animated:NO]; |
|
2738
bfccb2ec4334
new graphics from Tiy and frontend is loaded in landscape mode
koda
parents:
2723
diff
changeset
|
114 |
[application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; |
2740 | 115 |
|
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 |
|
2740 | 119 |
self.viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil]; |
2720 | 120 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
121 |
// Set working directory to resource path |
2688 | 122 |
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
2696 | 123 |
|
2738
bfccb2ec4334
new graphics from Tiy and frontend is loaded in landscape mode
koda
parents:
2723
diff
changeset
|
124 |
[uiwindow addSubview:viewController.view]; |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
125 |
[uiwindow makeKeyAndVisible]; |
2740 | 126 |
[uiwindow layoutSubviews]; |
2688 | 127 |
} |
128 |
||
129 |
-(void) applicationWillTerminate:(UIApplication *)application { |
|
130 |
SDL_SendQuit(); |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
131 |
// hack to prevent automatic termination. See SDL_uikitevents.m for details |
2688 | 132 |
// have to remove this otherwise game goes on when pushing the home button |
133 |
//longjmp(*(jump_env()), 1); |
|
134 |
} |
|
135 |
||
2698 | 136 |
-(void) applicationWillResignActive:(UIApplication*)application { |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
137 |
//NSLog(@"%@", NSStringFromSelector(_cmd)); |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
138 |
SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
2688 | 139 |
} |
140 |
||
2698 | 141 |
-(void) applicationDidBecomeActive:(UIApplication*)application { |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2772
diff
changeset
|
142 |
//NSLog(@"%@", NSStringFromSelector(_cmd)); |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2702
diff
changeset
|
143 |
SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
2688 | 144 |
} |
145 |
||
146 |
@end |