25 #import "StatsPageViewController.h" |
25 #import "StatsPageViewController.h" |
26 #import "AudioManagerController.h" |
26 #import "AudioManagerController.h" |
27 #import "ObjcExports.h" |
27 #import "ObjcExports.h" |
28 |
28 |
29 @implementation GameInterfaceBridge |
29 @implementation GameInterfaceBridge |
30 @synthesize ipcPort; |
|
31 |
30 |
32 -(id) initWithController:(id) viewController { |
31 -(id) initWithController:(id) viewController { |
33 if (self = [super init]) { |
32 if (self = [super init]) { |
34 self.ipcPort = [HWUtils randomPort]; |
|
35 } |
33 } |
36 return self; |
34 return self; |
37 } |
35 } |
38 |
36 |
39 -(void) dealloc { |
37 -(void) dealloc { |
40 [super dealloc]; |
38 [super dealloc]; |
41 } |
39 } |
42 |
40 |
43 #pragma mark - |
41 #pragma mark - |
44 // main routine for calling the actual game engine |
42 // main routine for calling the actual game engine |
45 -(void) engineLaunch:(NSString *)path { |
43 -(void) engineLaunchOn:(NSInteger) ipcPort withArgument:(NSString *)path { |
46 const char *gameArgs[11]; |
44 const char *gameArgs[11]; |
47 CGFloat width, height; |
45 CGFloat width, height; |
48 CGFloat screenScale = [[UIScreen mainScreen] safeScale]; |
46 CGFloat screenScale = [[UIScreen mainScreen] safeScale]; |
49 NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort]; |
47 NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",ipcPort]; |
50 NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
48 NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
51 NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
49 NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
52 |
50 |
53 if (IS_DUALHEAD()) { |
51 if (IS_DUALHEAD()) { |
54 CGRect screenBounds = [[[UIScreen screens] objectAtIndex:1] bounds]; |
52 CGRect screenBounds = [[[UIScreen screens] objectAtIndex:1] bounds]; |
102 [localeString release]; |
100 [localeString release]; |
103 [ipcString release]; |
101 [ipcString release]; |
104 |
102 |
105 [HWUtils setGameStatus:gsLoading]; |
103 [HWUtils setGameStatus:gsLoading]; |
106 |
104 |
107 // this is the pascal fuction that starts the game |
105 // this is the pascal function that starts the game |
108 Game(gameArgs); |
106 Game(gameArgs); |
109 } |
107 } |
110 |
108 |
111 // prepares the controllers for hosting a game |
109 // prepares the controllers for hosting a game |
112 -(void) prepareEngineOn:(NSString *)pathOrNil withOptions:(NSDictionary *)optionsOrNil { |
110 -(void) prepareEngineOn:(NSString *)pathOrNil withOptions:(NSDictionary *)optionsOrNil { |
113 EngineProtocolNetwork *proto = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort]; |
111 EngineProtocolNetwork *proto = [[EngineProtocolNetwork alloc] init]; |
114 [proto spawnThread:pathOrNil withOptions:optionsOrNil]; |
112 NSInteger ipcPort = [proto spawnThread:pathOrNil withOptions:optionsOrNil]; |
115 |
113 |
116 CGRect theFrame = [[UIScreen mainScreen] bounds]; |
114 CGRect theFrame = [[UIScreen mainScreen] bounds]; |
117 UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow]; |
115 UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow]; |
118 // we add a black view hiding the background |
116 // we add a black view hiding the background |
119 UIView *blackView = [[UIView alloc] initWithFrame:theFrame]; |
117 UIView *blackView = [[UIView alloc] initWithFrame:theFrame]; |
137 [userDefaults synchronize]; |
135 [userDefaults synchronize]; |
138 |
136 |
139 [AudioManagerController pauseBackgroundMusic]; |
137 [AudioManagerController pauseBackgroundMusic]; |
140 |
138 |
141 // SYSTEMS ARE GO!! |
139 // SYSTEMS ARE GO!! |
142 [self engineLaunch:pathOrNil]; |
140 [self engineLaunchOn:ipcPort withArgument:pathOrNil]; |
143 |
141 |
144 // remove completed games notification |
142 // remove completed games notification |
145 [userDefaults setObject:@"" forKey:@"savedGamePath"]; |
143 [userDefaults setObject:@"" forKey:@"savedGamePath"]; |
146 [userDefaults synchronize]; |
144 [userDefaults synchronize]; |
147 |
145 |