author | koda |
Sat, 16 Jan 2010 17:30:37 +0000 | |
changeset 2698 | 90585aba87ad |
parent 2697 | 75880595a9f1 |
child 2699 | 249adefa9c1c |
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" |
2688 | 31 |
|
2696 | 32 |
//#import "SoundEffect.h" |
33 |
// SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]]; |
|
34 |
// SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]]; |
|
35 |
||
36 |
||
2688 | 37 |
#ifdef main |
38 |
#undef main |
|
39 |
#endif |
|
40 |
||
2698 | 41 |
int main(int argc, char *argv[]) { |
42 |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
|
43 |
int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
|
44 |
[pool release]; |
|
45 |
return retVal; |
|
2688 | 46 |
} |
47 |
||
48 |
@implementation SDLUIKitDelegate |
|
49 |
||
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
|
50 |
@synthesize window, windowID, controller, setup; |
2688 | 51 |
|
52 |
/* convenience method */ |
|
53 |
+(SDLUIKitDelegate *)sharedAppDelegate { |
|
54 |
/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */ |
|
55 |
return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
|
56 |
} |
|
57 |
||
2696 | 58 |
-(void) dealloc { |
59 |
[setup release]; |
|
60 |
[controller release]; |
|
61 |
[window release]; |
|
62 |
[super dealloc]; |
|
63 |
} |
|
64 |
||
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
|
65 |
-(IBAction) startSDLgame { |
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
|
66 |
|
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
|
67 |
[setup startThread:@"engineProtocol"]; |
2696 | 68 |
[setup loadSettingsFromFile:@"settings.plist" forKey:@"systemSettings"]; |
69 |
||
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
70 |
// remove the current view to free resources |
2698 | 71 |
[UIView beginAnimations:@"removing main controller" context:NULL]; |
72 |
[UIView setAnimationDuration:1]; |
|
73 |
controller.view.alpha = 0; |
|
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
74 |
[UIView commitAnimations]; |
2698 | 75 |
[controller.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
76 |
||
2691 | 77 |
NSLog(@"Game is launching..."); |
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
78 |
|
2698 | 79 |
// direct execution or thread? check the one that gives most fps |
80 |
// library or call SDL_main? pascal quits at the end of the main |
|
81 |
Game(); |
|
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
|
82 |
|
2698 | 83 |
NSLog(@"Game is exting..."); |
84 |
||
85 |
[[window viewWithTag:54867] removeFromSuperview]; |
|
86 |
[setup unloadSettings]; |
|
87 |
||
88 |
[window addSubview:controller.view]; |
|
89 |
[window makeKeyAndVisible]; |
|
90 |
||
91 |
[UIView beginAnimations:@"inserting main controller" context:NULL]; |
|
92 |
[UIView setAnimationDuration:1]; |
|
93 |
controller.view.alpha = 1; |
|
94 |
[UIView commitAnimations]; |
|
2688 | 95 |
} |
96 |
||
97 |
// override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
|
98 |
-(void) applicationDidFinishLaunching:(UIApplication *)application { |
|
99 |
[application setStatusBarHidden:YES animated:NO]; |
|
100 |
||
2696 | 101 |
setup = [[GameSetup alloc] init]; |
2688 | 102 |
/* Set working directory to resource path */ |
103 |
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
|
2696 | 104 |
|
2688 | 105 |
[window addSubview:controller.view]; |
106 |
[window makeKeyAndVisible]; |
|
107 |
} |
|
108 |
||
109 |
-(void) applicationWillTerminate:(UIApplication *)application { |
|
110 |
SDL_SendQuit(); |
|
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
111 |
/* hack to prevent automatic termination. See SDL_uikitevents.m for details */ |
2688 | 112 |
// have to remove this otherwise game goes on when pushing the home button |
113 |
//longjmp(*(jump_env()), 1); |
|
114 |
} |
|
115 |
||
2698 | 116 |
-(void) applicationWillResignActive:(UIApplication*)application { |
2688 | 117 |
// NSLog(@"%@", NSStringFromSelector(_cmd)); |
118 |
SDL_SendWindowEvent(self.windowID, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
|
119 |
} |
|
120 |
||
2698 | 121 |
-(void) applicationDidBecomeActive:(UIApplication*)application { |
2688 | 122 |
// NSLog(@"%@", NSStringFromSelector(_cmd)); |
123 |
SDL_SendWindowEvent(self.windowID, SDL_WINDOWEVENT_RESTORED, 0, 0); |
|
124 |
} |
|
125 |
||
126 |
/* |
|
127 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
128 |
NSLog(@"Rotating..."); |
|
129 |
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); |
|
130 |
} |
|
131 |
*/ |
|
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
|
132 |
|
2698 | 133 |
-(NSString *)dataFilePath: (NSString *)fileName { |
2696 | 134 |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
135 |
NSString *documentsDirectory = [paths objectAtIndex:0]; |
|
136 |
return [documentsDirectory stringByAppendingPathComponent:fileName]; |
|
2688 | 137 |
} |
138 |
||
139 |
@end |