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 |
|
|
23 |
#import "SDL_uikitappdelegate.h"
|
|
24 |
#import "SDL_uikitopenglview.h"
|
|
25 |
#import "SDL_events_c.h"
|
|
26 |
#import "jumphack.h"
|
|
27 |
#import "SDL_video.h"
|
|
28 |
|
|
29 |
#ifdef main
|
|
30 |
#undef main
|
|
31 |
#endif
|
|
32 |
|
|
33 |
extern int SDL_main(int argc, char *argv[]);
|
|
34 |
static int forward_argc;
|
|
35 |
static char **forward_argv;
|
|
36 |
|
|
37 |
int main (int argc, char **argv) {
|
|
38 |
int i;
|
|
39 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
40 |
|
|
41 |
/* store arguments */
|
|
42 |
forward_argc = argc;
|
|
43 |
forward_argv = (char **)malloc(argc * sizeof(char *));
|
|
44 |
for (i = 0; i < argc; i++) {
|
|
45 |
forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
|
|
46 |
strcpy(forward_argv[i], argv[i]);
|
|
47 |
}
|
|
48 |
|
|
49 |
/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
|
|
50 |
UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate");
|
|
51 |
|
|
52 |
[pool release];
|
|
53 |
}
|
|
54 |
|
|
55 |
@implementation SDLUIKitDelegate
|
|
56 |
|
|
57 |
@synthesize window, windowID, controller;
|
|
58 |
|
|
59 |
/* convenience method */
|
|
60 |
+(SDLUIKitDelegate *)sharedAppDelegate {
|
|
61 |
/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
|
|
62 |
return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
|
|
63 |
}
|
|
64 |
|
|
65 |
- (void) startSDLgame {
|
|
66 |
|
|
67 |
/* run the user's application, passing argc and argv */
|
|
68 |
NSLog(@"Game is launching");
|
|
69 |
SDL_main(forward_argc, forward_argv);
|
|
70 |
// can't reach here yet
|
|
71 |
NSLog(@"Game exited");
|
|
72 |
|
|
73 |
//[self performSelector:@selector(makeNewView) withObject:nil afterDelay:0.0];
|
|
74 |
/* exit, passing the return status from the user's application */
|
|
75 |
//exit(exit_status);
|
|
76 |
}
|
|
77 |
|
|
78 |
// override the direct execution of SDL_main to allow us to implement the frontend (even using a nib)
|
|
79 |
-(void) applicationDidFinishLaunching:(UIApplication *)application {
|
|
80 |
[application setStatusBarHidden:YES animated:NO];
|
|
81 |
|
|
82 |
/* Set working directory to resource path */
|
|
83 |
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
|
2689
|
84 |
//#import "SoundEffect.h"
|
|
85 |
// SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]];
|
|
86 |
// SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]];
|
2688
|
87 |
|
|
88 |
[window addSubview:controller.view];
|
|
89 |
[window makeKeyAndVisible];
|
|
90 |
}
|
|
91 |
|
|
92 |
-(void) applicationWillTerminate:(UIApplication *)application {
|
|
93 |
/* free the memory we used to hold copies of argc and argv */
|
|
94 |
int i;
|
|
95 |
for (i=0; i < forward_argc; i++) {
|
|
96 |
free(forward_argv[i]);
|
|
97 |
}
|
|
98 |
free(forward_argv);
|
|
99 |
SDL_SendQuit();
|
|
100 |
/* hack to prevent automatic termination. See SDL_uikitevents.m for details */
|
|
101 |
// have to remove this otherwise game goes on when pushing the home button
|
|
102 |
//longjmp(*(jump_env()), 1);
|
|
103 |
|
|
104 |
NSLog(@"Closing App...");
|
|
105 |
}
|
|
106 |
|
|
107 |
-(void) applicationWillResignActive:(UIApplication*)application
|
|
108 |
{
|
|
109 |
// NSLog(@"%@", NSStringFromSelector(_cmd));
|
|
110 |
SDL_SendWindowEvent(self.windowID, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
|
111 |
}
|
|
112 |
|
|
113 |
-(void) applicationDidBecomeActive:(UIApplication*)application
|
|
114 |
{
|
|
115 |
// NSLog(@"%@", NSStringFromSelector(_cmd));
|
|
116 |
SDL_SendWindowEvent(self.windowID, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
|
117 |
}
|
|
118 |
|
|
119 |
/*
|
|
120 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
|
|
121 |
NSLog(@"Rotating...");
|
|
122 |
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
|
|
123 |
}
|
|
124 |
*/
|
|
125 |
|
|
126 |
-(void) dealloc {
|
|
127 |
[controller release];
|
|
128 |
[window release];
|
|
129 |
[super dealloc];
|
|
130 |
}
|
|
131 |
|
|
132 |
@end
|