--- a/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m Sun Apr 17 22:38:24 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m Mon Apr 18 02:45:51 2011 +0200
@@ -63,8 +63,9 @@
#pragma mark Spawner functions
-(void) spawnThread:(NSString *)onSaveFile withOptions:(NSDictionary *)dictionary {
self.stream = [[NSOutputStream alloc] initToFileAtPath:onSaveFile append:YES];
+ [self.stream open];
- [NSThread detachNewThreadSelector:@selector(engineProtocol)
+ [NSThread detachNewThreadSelector:@selector(engineProtocol:)
toTarget:self
withObject:dictionary];
}
@@ -210,10 +211,8 @@
#pragma mark -
#pragma mark Network relevant code
-(void) dumpRawData:(const char *)buffer ofSize:(uint8_t) length {
- [self.stream open];
[self.stream write:&length maxLength:1];
[self.stream write:(const uint8_t *)buffer maxLength:length];
- [self.stream close];
}
// wrapper that computes the length of the message and then sends the command string, saving the command on a file
@@ -407,6 +406,7 @@
}
}
DLog(@"Engine exited, ending thread");
+ [self.stream close];
// Close the client socket
SDLNet_TCP_Close(csd);
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Sun Apr 17 22:38:24 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Mon Apr 18 02:45:51 2011 +0200
@@ -24,7 +24,7 @@
#import "TeamConfigViewController.h"
#import "SchemeWeaponConfigViewController.h"
#import "HelpPageViewController.h"
-#import "StatsPageViewController.h"
+#import "GameInterfaceBridge.h"
#import "CommodityFunctions.h"
#import "UIImageExtra.h"
#import "PascalImports.h"
@@ -227,14 +227,13 @@
[NSNumber numberWithInt:self.interfaceOrientation],@"orientation",
nil];
- NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys:
- gameDictionary,@"game_dictionary",
- [NSNumber numberWithBool:NO],@"netgame",
- @"",@"savefile",
- nil];
+ GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self];
+
+ [bridge startLocalGame:gameDictionary];
+ [bridge release];
// also modify SavedGamesViewController.m
- StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped];
+ /* StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped];
statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)])
statsPage.modalPresentationStyle = UIModalPresentationPageSheet;
@@ -257,7 +256,7 @@
[statsPage viewWillAppear:YES];
}
- [statsPage release];
+ [statsPage release];*/
}
-(void) loadNiceHogs {
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h Sun Apr 17 22:38:24 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h Mon Apr 18 02:45:51 2011 +0200
@@ -23,6 +23,7 @@
#import "EngineProtocolNetwork.h"
typedef enum {gtNone, gtLocal, gtSave, gtNet} TGameType;
+typedef enum {gsNone, gsInGame, gsEnded, gsInterrupted} TGameStatus;
@class OverlayViewController;
@@ -36,6 +37,7 @@
NSInteger ipcPort; // Port on which engine will listen
TGameType gameType;
+ TGameStatus gameStatus;
}
@property (nonatomic,retain) UIViewController *parentController;
@@ -47,6 +49,7 @@
@property (assign) NSInteger ipcPort;
@property (assign) TGameType gameType;
+@property (assign) TGameStatus gameStatus;
-(id) initWithController:(id) viewController;
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Sun Apr 17 22:38:24 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Mon Apr 18 02:45:51 2011 +0200
@@ -25,12 +25,13 @@
#import "OverlayViewController.h"
@implementation GameInterfaceBridge
-@synthesize parentController, systemSettings, savePath, overlayController, ipcPort, gameType, engineProtocol;
+@synthesize parentController, systemSettings, savePath, overlayController, engineProtocol, ipcPort, gameType, gameStatus;
-(id) initWithController:(id) viewController {
if (self = [super init]) {
self.ipcPort = randomPort();
self.gameType = gtNone;
+ self.gameStatus = gsNone;
self.savePath = nil;
self.parentController = (UIViewController *)viewController;
@@ -66,7 +67,7 @@
// main routine for calling the actual game engine
-(void) startGameEngine {
- const char *gameArgs[10];
+ const char *gameArgs[11];
NSInteger width, height, orientation;
NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort];
NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]];
@@ -127,35 +128,46 @@
[ipcString release];
// this is the pascal fuction that starts the game, wrapped around isInGame
+ self.gameStatus = gsInGame;
[HedgewarsAppDelegate sharedAppDelegate].isInGame = YES;
Game(gameArgs);
[HedgewarsAppDelegate sharedAppDelegate].isInGame = NO;
+ if (self.gameStatus != gsEnded)
+ self.gameStatus = gsInterrupted;
}
// prepares the controllers for hosting a game
-(void) prepareEngineLaunch {
- self.parentController.view.opaque = YES;
- self.parentController.view.backgroundColor = [UIColor blackColor];
- self.parentController.view.alpha = 0;
-
- [UIView beginAnimations:@"fade out to black" context:NULL];
- [UIView setAnimationDuration:1];
- self.parentController.view.alpha = 1;
- [UIView commitAnimations];
-
NSDictionary *overlayOptions = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:self.parentController.interfaceOrientation],@"orientation",
[self.systemSettings objectForKey:@"menu"],@"menu",
nil];
- [self performSelector:@selector(displayOverlayLater:) withObject:overlayOptions afterDelay:1];
+ [self performSelector:@selector(displayOverlayLater:) withObject:overlayOptions afterDelay:4];
[overlayOptions release];
[self startGameEngine];
+ CGRect theFrame = CGRectMake(0, 0, self.parentController.view.frame.size.height, self.parentController.view.frame.size.width);
+ UIView *blackView = [[UIView alloc] initWithFrame:theFrame];
+ [self.parentController.view addSubview:blackView];
+ blackView.opaque = YES;
+ blackView.backgroundColor = [UIColor blackColor];
+ blackView.alpha = 1;
+
[UIView beginAnimations:@"fade in" context:NULL];
[UIView setAnimationDuration:1];
- self.parentController.view.alpha = 0;
+ blackView.alpha = 0;
[UIView commitAnimations];
+ [blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
+ [blackView release];
+ NSError *error = nil;
+ // can remove the savefile if the replay has ended
+ if (self.gameType == gtSave && self.gameStatus == gsEnded)
+ [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:&error];
+ DLog(@"%@",error);
+
+ if (IS_DUALHEAD())
+ [self.overlayController removeOverlay];
}
// set up variables for a local game
@@ -183,11 +195,9 @@
-(void) gameHasEndedWithStats:(NSArray *)stats {
DLog(@"%@",stats);
+ self.gameStatus = gsEnded;
[self.overlayController removeOverlay];
- // can remove the file if the replay has ended
- if (self.gameType == gtSave)
- [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:NULL];
}
@end
--- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m Sun Apr 17 22:38:24 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m Mon Apr 18 02:45:51 2011 +0200
@@ -88,8 +88,8 @@
[self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
}
- HW_chatEnd();
- SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
+// HW_chatEnd();
+// SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
if (shouldTakeScreenshot) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please wait"
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sun Apr 17 22:38:24 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Mon Apr 18 02:45:51 2011 +0200
@@ -252,7 +252,6 @@
[self.popupMenu performSelectorOnMainThread:@selector(dismiss) withObject:nil waitUntilDone:YES];
[self.popoverController performSelectorOnMainThread:@selector(dismissPopoverAnimated:) withObject:nil waitUntilDone:YES];
[self.view performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:YES];
- HW_terminate(NO);
}
-(void) didReceiveMemoryWarning {
@@ -265,7 +264,7 @@
if (IS_IPAD())
if (((UIPopoverController *)self.popoverController).contentViewController.view.superview == nil)
self.popoverController = nil;
-
+
MSG_MEMCLEAN();
[super didReceiveMemoryWarning];
}
--- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Sun Apr 17 22:38:24 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Mon Apr 18 02:45:51 2011 +0200
@@ -20,7 +20,7 @@
#import "SavedGamesViewController.h"
-#import "StatsPageViewController.h"
+#import "GameInterfaceBridge.h"
#import "CommodityFunctions.h"
@implementation SavedGamesViewController
@@ -208,16 +208,14 @@
[self updateTable];
[(EditableCellView *)[self.tableView cellForRowAtIndexPath:indexPath] save:nil];
-
- NSString *filePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:[indexPath row]]];
-
- NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys:
- filePath,@"savefile",
- [NSNumber numberWithBool:NO],@"netgame",
- [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:self.interfaceOrientation] forKey:@"orientation"],@"game_dictionary",
- nil];
+
+ GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self];
- // also modify GameConfigViewController.m
+ NSString *filePath = [[NSString alloc] initWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:[indexPath row]]];
+ [bridge startSaveGame:filePath];
+ [filePath release];
+ [bridge release];
+ /* // also modify GameConfigViewController.m
StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped];
statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)])
@@ -241,7 +239,7 @@
statsPage.statsArray = stats;
[statsPage.tableView reloadData];
[statsPage viewWillAppear:YES];
- }
+ }*/
// reload needed because when ending game the entry remains there
[self.tableView reloadData];
}