diff -r a187c280dd3d -r f72cac290325 project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m --- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Mon Apr 09 03:25:17 2012 +0200 +++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Mon Apr 09 04:43:30 2012 +0200 @@ -25,7 +25,7 @@ static UIViewController *callingController; @implementation GameInterfaceBridge -@synthesize blackView, savePath, proto; +@synthesize blackView, savePath, port; #pragma mark - #pragma mark Instance methods for engine interaction @@ -35,9 +35,10 @@ [[AudioManagerController mainManager] fadeOutBackgroundMusic]; EngineProtocolNetwork *engineProtocol = [[EngineProtocolNetwork alloc] init]; - self.proto = engineProtocol; + self.port = engineProtocol.enginePort; + engineProtocol.delegate = self; + [engineProtocol spawnThread:self.savePath withOptions:optionsOrNil]; [engineProtocol release]; - [self.proto spawnThread:self.savePath withOptions:optionsOrNil]; // add a black view hiding the background UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow]; @@ -82,20 +83,6 @@ [UIView commitAnimations]; [self.blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; - // engine thread *should* be done by now - NSArray *stats = [[NSArray alloc] initWithArray:self.proto.statsArray copyItems:YES]; - if ([HWUtils gameStatus] == gsEnded && stats != nil) { - StatsPageViewController *statsPage = [[StatsPageViewController alloc] init]; - statsPage.statsArray = stats; - statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical; - if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)]) - statsPage.modalPresentationStyle = UIModalPresentationPageSheet; - - [callingController presentModalViewController:statsPage animated:YES]; - [statsPage release]; - } - [stats release]; - // can remove the savefile if the replay has ended if ([HWUtils gameType] == gtSave) [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; @@ -111,9 +98,8 @@ -(void) engineLaunch { const char *gameArgs[11]; CGFloat width, height; - NSInteger enginePort = self.proto.enginePort; CGFloat screenScale = [[UIScreen mainScreen] safeScale]; - NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",enginePort]; + NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",self.port]; NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt",[[NSLocale preferredLanguages] objectAtIndex:0]]; NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; @@ -175,11 +161,23 @@ -(void) dealloc { releaseAndNil(blackView); releaseAndNil(savePath); - releaseAndNil(proto); [super dealloc]; } #pragma mark - +#pragma mark EngineProtocolDelegate methods +-(void) gameEndedWithStatistics:(NSArray *)stats { + if (stats != nil) { + StatsPageViewController *statsPage = [[StatsPageViewController alloc] init]; + statsPage.statsArray = stats; + statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical; + + [callingController presentModalViewController:statsPage animated:YES]; + [statsPage release]; + } +} + +#pragma mark - #pragma mark Class methods for setting up the engine from outsite +(void) registerCallingController:(UIViewController *)controller { callingController = controller;