36 |
36 |
37 #ifdef main |
37 #ifdef main |
38 #undef main |
38 #undef main |
39 #endif |
39 #endif |
40 |
40 |
41 int main(int argc, char *argv[]) { |
41 int main (int argc, char *argv[]) { |
42 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
42 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
43 int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
43 int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate"); |
44 [pool release]; |
44 [pool release]; |
45 return retVal; |
45 return retVal; |
46 } |
46 } |
47 |
47 |
48 @implementation SDLUIKitDelegate |
48 @implementation SDLUIKitDelegate |
49 |
49 |
50 @synthesize window, windowID, controller, setup; |
50 @synthesize window, windowID, controller; |
51 |
51 |
52 /* convenience method */ |
52 /* convenience method */ |
53 +(SDLUIKitDelegate *)sharedAppDelegate { |
53 +(SDLUIKitDelegate *)sharedAppDelegate { |
54 /* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */ |
54 /* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */ |
55 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
55 return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; |
56 } |
56 } |
57 |
57 |
58 -(void) dealloc { |
58 -(void) dealloc { |
59 [setup release]; |
|
60 [controller release]; |
59 [controller release]; |
61 [window release]; |
60 [window release]; |
62 [super dealloc]; |
61 [super dealloc]; |
63 } |
62 } |
64 |
63 |
65 -(IBAction) startSDLgame { |
64 -(IBAction) startSDLgame { |
|
65 NSAutoreleasePool *internal_pool = [[NSAutoreleasePool alloc] init]; |
|
66 |
|
67 GameSetup *setup = [[GameSetup alloc] init]; |
66 [setup startThread:@"engineProtocol"]; |
68 [setup startThread:@"engineProtocol"]; |
67 [setup loadSettingsFromFile:@"settings.plist" forKey:@"systemSettings"]; |
|
68 |
69 |
69 // remove the current view to free resources |
70 // remove the current view to free resources |
70 [UIView beginAnimations:@"removing main controller" context:NULL]; |
71 [UIView beginAnimations:@"removing main controller" context:NULL]; |
71 [UIView setAnimationDuration:1]; |
72 [UIView setAnimationDuration:1]; |
72 controller.view.alpha = 0; |
73 controller.view.alpha = 0; |
73 [UIView commitAnimations]; |
74 [UIView commitAnimations]; |
74 [controller.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
75 [controller.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
75 |
76 |
76 NSLog(@"Game is launching..."); |
77 NSLog(@"Game is launching..."); |
77 |
78 const char **gameArgs = [setup getSettings]; |
78 NSAutoreleasePool *internal_pool = [[NSAutoreleasePool alloc] init]; |
79 |
79 |
|
80 // direct execution or thread? check the one that gives most fps |
80 // direct execution or thread? check the one that gives most fps |
81 // library or call SDL_main? pascal quits at the end of the main |
81 // library or call SDL_main? pascal quits at the end of the main |
82 Game(); |
82 Game(gameArgs); |
83 |
83 |
84 [internal_pool drain]; |
84 free(gameArgs); |
85 NSLog(@"Game is exting..."); |
85 NSLog(@"Game is exting..."); |
86 |
86 |
87 [[window viewWithTag:54867] removeFromSuperview]; |
87 [[window viewWithTag:54867] removeFromSuperview]; |
88 [setup unloadSettings]; |
88 [setup release]; |
89 |
89 |
90 [window addSubview:controller.view]; |
90 [window addSubview:controller.view]; |
91 [window makeKeyAndVisible]; |
91 [window makeKeyAndVisible]; |
92 |
92 |
93 [UIView beginAnimations:@"inserting main controller" context:NULL]; |
93 [UIView beginAnimations:@"inserting main controller" context:NULL]; |
94 [UIView setAnimationDuration:1]; |
94 [UIView setAnimationDuration:1]; |
95 controller.view.alpha = 1; |
95 controller.view.alpha = 1; |
96 [UIView commitAnimations]; |
96 [UIView commitAnimations]; |
|
97 |
|
98 [internal_pool release]; |
|
99 } |
|
100 |
|
101 -(BOOL) checkFirstRun { |
|
102 BOOL isFirstRun = NO; |
|
103 |
|
104 NSString *filePath = [self dataFilePath:@"settings.plist"]; |
|
105 if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) { |
|
106 isFirstRun = YES; |
|
107 // file not present, let's create it |
|
108 NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
|
109 |
|
110 [saveDict setObject:@"" forKey:@"username"]; |
|
111 [saveDict setObject:@"" forKey:@"password"]; |
|
112 [saveDict setObject:@"1" forKey:@"music"]; |
|
113 [saveDict setObject:@"1" forKey:@"sounds"]; |
|
114 [saveDict setObject:@"0" forKey:@"alternate"]; |
|
115 [saveDict setObject:@"100" forKey:@"volume"]; |
|
116 |
|
117 [saveDict writeToFile:filePath atomically:YES]; |
|
118 [saveDict release]; |
|
119 } |
|
120 return isFirstRun; |
97 } |
121 } |
98 |
122 |
99 // override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
123 // override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) |
100 -(void) applicationDidFinishLaunching:(UIApplication *)application { |
124 -(void) applicationDidFinishLaunching:(UIApplication *)application { |
101 [application setStatusBarHidden:YES animated:NO]; |
125 [application setStatusBarHidden:YES animated:NO]; |
102 |
126 |
103 setup = [[GameSetup alloc] init]; |
127 [self checkFirstRun]; |
104 /* Set working directory to resource path */ |
128 /* Set working directory to resource path */ |
105 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
129 [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; |
106 |
130 |
107 [window addSubview:controller.view]; |
131 [window addSubview:controller.view]; |
108 [window makeKeyAndVisible]; |
132 [window makeKeyAndVisible]; |