34 #ifdef main |
34 #ifdef main |
35 #undef main |
35 #undef main |
36 #endif |
36 #endif |
37 |
37 |
38 int main (int argc, char *argv[]) { |
38 int main (int argc, char *argv[]) { |
39 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
39 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
40 int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
40 int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
41 [pool release]; |
41 [pool release]; |
42 return retVal; |
42 return retVal; |
43 } |
43 } |
44 |
44 |
45 @implementation SDLUIKitDelegate |
45 @implementation SDLUIKitDelegate |
46 |
|
47 @synthesize uiwindow, window, viewController, overlayController; |
46 @synthesize uiwindow, window, viewController, overlayController; |
48 |
47 |
49 // convenience method |
48 // convenience method |
50 +(SDLUIKitDelegate *)sharedAppDelegate { |
49 +(SDLUIKitDelegate *)sharedAppDelegate { |
51 // the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method |
50 // the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method |
66 [super dealloc]; |
66 [super dealloc]; |
67 } |
67 } |
68 |
68 |
69 #pragma mark - |
69 #pragma mark - |
70 #pragma mark Custom stuff |
70 #pragma mark Custom stuff |
71 -(void) showMenuAfterwards { |
|
72 // draws the controller overlay after the sdl window has taken control |
|
73 [uiwindow bringSubviewToFront:overlayController.view]; |
|
74 |
|
75 [UIView beginAnimations:@"showing overlay" context:NULL]; |
|
76 [UIView setAnimationDuration:1]; |
|
77 self. overlayController.view.alpha = 1; |
|
78 [UIView commitAnimations]; |
|
79 } |
|
80 |
|
81 -(IBAction) startSDLgame { |
71 -(IBAction) startSDLgame { |
82 NSAutoreleasePool *internal_pool = [[NSAutoreleasePool alloc] init]; |
|
83 |
|
84 GameSetup *setup = [[GameSetup alloc] init]; |
72 GameSetup *setup = [[GameSetup alloc] init]; |
85 [setup startThread:@"engineProtocol"]; |
73 [setup startThread:@"engineProtocol"]; |
86 |
74 |
87 // remove the current view to free resources |
75 [viewController disappear]; |
88 [UIView beginAnimations:@"removing main controller" context:NULL]; |
76 [viewController.view removeFromSuperview]; |
89 [UIView setAnimationDuration:1]; |
77 |
90 self.viewController.mainView.alpha = 0; |
|
91 [UIView commitAnimations]; |
|
92 |
|
93 NSLog(@"...Game is launching..."); |
|
94 const char **gameArgs = [setup getSettings]; |
78 const char **gameArgs = [setup getSettings]; |
95 [setup release]; |
79 [setup release]; |
96 |
80 |
97 // overlay with controls |
81 // overlay with controls, become visible after 2 seconds |
98 overlayController = [[overlayViewController alloc] initWithNibName:@"overlayViewController" bundle:nil]; |
82 overlayController = [[overlayViewController alloc] initWithNibName:@"overlayViewController" bundle:nil]; |
99 overlayController.view.alpha = 0; |
83 [uiwindow addSubview:overlayController.view]; |
100 [uiwindow addSubview: overlayController.view]; |
84 [NSTimer scheduledTimerWithTimeInterval:2 target:overlayController selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO]; |
101 [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO]; |
|
102 |
85 |
103 Game(gameArgs); // this is the pascal fuction that starts the game |
86 Game(gameArgs); // this is the pascal fuction that starts the game |
104 |
87 |
105 // let's clean memory |
88 // let's clean memory |
106 free(gameArgs); |
89 free(gameArgs); |
107 [overlayController.view removeFromSuperview]; |
90 [overlayController.view removeFromSuperview]; |
108 [overlayController release]; |
91 [overlayController release]; |
109 |
92 |
110 NSLog(@"...Game is exting..."); |
93 [uiwindow addSubview:viewController.view]; |
111 |
|
112 [uiwindow addSubview: viewController.view]; |
|
113 [uiwindow makeKeyAndVisible]; |
94 [uiwindow makeKeyAndVisible]; |
114 |
95 |
115 [UIView beginAnimations:@"inserting main controller" context:NULL]; |
96 [viewController appear]; |
116 [UIView setAnimationDuration:1]; |
|
117 self.viewController.mainView.alpha = 1; |
|
118 [UIView commitAnimations]; |
|
119 |
|
120 [internal_pool release]; |
|
121 } |
97 } |
122 |
98 |
123 -(NSString *)dataFilePath: (NSString *)fileName { |
99 -(NSString *)dataFilePath: (NSString *)fileName { |
124 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
100 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
125 NSString *documentsDirectory = [paths objectAtIndex:0]; |
101 NSString *documentsDirectory = [paths objectAtIndex:0]; |