# HG changeset patch # User koda # Date 1272162642 0 # Node ID 37ac593e9027297839769e38aa65478175e00258 # Parent e5403e2bf02c2f3612c5bc9e56ab8f9f5bf1ed20 wow all these files only for land preview and seed generation diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/GameConfigViewController.h --- a/cocoaTouch/GameConfigViewController.h Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/GameConfigViewController.h Sun Apr 25 02:30:42 2010 +0000 @@ -9,6 +9,7 @@ #import @class TeamConfigViewController; +@class MapConfigViewController; @interface GameConfigViewController : UIViewController { UITableView *availableTeamsTableView; @@ -19,6 +20,7 @@ UIBarButtonItem *startButton; UIViewController *activeController; + MapConfigViewController *mapConfigViewController; TeamConfigViewController *teamConfigViewController; } @@ -30,5 +32,7 @@ @property (nonatomic,retain) IBOutlet UIBarButtonItem *startButton; -(IBAction) buttonPressed:(id) sender; +-(IBAction) segmentPressed:(id) sender; -(void) startGame; + @end diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/GameConfigViewController.m --- a/cocoaTouch/GameConfigViewController.m Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/GameConfigViewController.m Sun Apr 25 02:30:42 2010 +0000 @@ -9,6 +9,7 @@ #import "GameConfigViewController.h" #import "SDL_uikitappdelegate.h" #import "CommodityFunctions.h" +#import "MapConfigViewController.h" #import "TeamConfigViewController.h" @implementation GameConfigViewController @@ -24,41 +25,98 @@ UIButton *theButton = (UIButton *)sender; switch (theButton.tag) { case 0: - [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; + [[self parentViewController] dismissModalViewControllerAnimated:YES]; break; case 1: [self performSelector:@selector(startGame) withObject:nil afterDelay:0.25]; break; + } } +-(IBAction) segmentPressed:(id) sender { + UISegmentedControl *theSegment = (UISegmentedControl *)sender; + NSLog(@"%d", theSegment.selectedSegmentIndex); + switch (theSegment.selectedSegmentIndex) { + case 0: + // this init here is just aestetic as this controller was already set up in viewDidLoad + if (mapConfigViewController == nil) { + mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; + [mapConfigViewController viewWillAppear:NO]; + } + activeController = mapConfigViewController; + break; + case 1: + if (teamConfigViewController == nil) { + teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; + // this message is compulsory otherwise the team table won't be loaded at all + [teamConfigViewController viewWillAppear:NO]; + } + activeController = teamConfigViewController; + break; + case 2: + + break; + } + + [self.view addSubview:activeController.view]; +} + -(void) startGame { + // play only if there is more than one team if ([teamConfigViewController.listOfSelectedTeams count] < 2) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"") - message:NSLocalizedString(@"You need to select at least two teams to play a Game",@"") + message:NSLocalizedString(@"You need to select at least two teams to play a game",@"") delegate:nil cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") otherButtonTitles:nil]; [alert show]; [alert release]; - } else { - [teamConfigViewController.listOfSelectedTeams writeToFile:GAMECONFIG_FILE() atomically:YES]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; - [[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; + return; } + + // play if there's room for enough hogs in the selected map + int hogs = 0; + for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams) + hogs += [[teamData objectForKey:@"number"] intValue]; + + if (hogs > mapConfigViewController.maxHogs) { + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many hogs",@"") + message:NSLocalizedString(@"The map you selected is too small for that many hogs",@"") + delegate:nil + cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") + otherButtonTitles:nil]; + [alert show]; + [alert release]; + return; + } + NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command", + teamConfigViewController.listOfSelectedTeams,@"teams_list",nil]; + [dict writeToFile:GAMECONFIG_FILE() atomically:YES]; + [dict release]; + [[self parentViewController] dismissModalViewControllerAnimated:YES]; + [[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; } -(void) viewDidLoad { - teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; - activeController = teamConfigViewController; + mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; + activeController = mapConfigViewController; - [self.view insertSubview:teamConfigViewController.view atIndex:0]; + [self.view insertSubview:mapConfigViewController.view atIndex:0]; [super viewDidLoad]; } +-(void) viewWillAppear:(BOOL)animated { + [mapConfigViewController viewWillAppear:animated]; + [teamConfigViewController viewWillAppear:animated]; + // ADD other controllers here + + [super viewWillAppear:animated]; +} + -(void) didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; @@ -67,7 +125,9 @@ -(void) viewDidUnload { + NSLog(@"unloading"); activeController = nil; + mapConfigViewController = nil; teamConfigViewController = nil; self.availableTeamsTableView = nil; self.weaponsButton = nil; @@ -81,6 +141,7 @@ -(void) dealloc { [activeController release]; + [mapConfigViewController release]; [teamConfigViewController release]; [availableTeamsTableView release]; [weaponsButton release]; @@ -91,24 +152,4 @@ [super dealloc]; } --(void) viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - [activeController viewWillAppear:animated]; -} - --(void) viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - [activeController viewWillDisappear:animated]; -} - --(void) viewDidAppear:(BOOL)animated { - [super viewDidLoad]; - [activeController viewDidAppear:animated]; -} - --(void) viewDidDisappear:(BOOL)animated { - [super viewDidUnload]; - [activeController viewDidDisappear:animated]; -} - @end diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/GameSetup.h --- a/cocoaTouch/GameSetup.h Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/GameSetup.h Sun Apr 25 02:30:42 2010 +0000 @@ -11,14 +11,14 @@ @interface GameSetup : NSObject { NSDictionary *systemSettings; - NSArray *teamsConfig; + NSDictionary *gameConfig; NSInteger ipcPort; TCPsocket sd, csd; // Socket descriptor, Client socket descriptor } @property (nonatomic, retain) NSDictionary *systemSettings; -@property (nonatomic, retain) NSArray *teamsConfig; +@property (nonatomic, retain) NSDictionary *gameConfig; -(void) engineProtocol; -(void) startThread: (NSString *)selector; diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/GameSetup.m --- a/cocoaTouch/GameSetup.m Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/GameSetup.m Sun Apr 25 02:30:42 2010 +0000 @@ -20,25 +20,30 @@ @implementation GameSetup -@synthesize systemSettings, teamsConfig; +@synthesize systemSettings, gameConfig; -(id) init { if (self = [super init]) { srandom(time(NULL)); - ipcPort = (random() % 64541) + 1025; + ipcPort = randomPort(); - self.systemSettings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; //should check it exists - self.teamsConfig = [[NSArray alloc] initWithContentsOfFile:GAMECONFIG_FILE()]; + NSDictionary *dictSett = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; //should check it exists + self.systemSettings = dictSett; + [dictSett release]; + + NSDictionary *dictGame = [[NSDictionary alloc] initWithContentsOfFile:GAMECONFIG_FILE()]; + self.gameConfig = dictGame; + [dictGame release]; } return self; } -(NSString *)description { - return [NSString stringWithFormat:@"ipcport: %d\nsockets: %d,%d\n teams: %@\n systemSettings: %@",ipcPort,sd,csd,teamsConfig,systemSettings]; + return [NSString stringWithFormat:@"ipcport: %d\nsockets: %d,%d\n teams: %@\n systemSettings: %@",ipcPort,sd,csd,gameConfig,systemSettings]; } -(void) dealloc { - [teamsConfig release]; + [gameConfig release]; [systemSettings release]; [super dealloc]; } @@ -130,26 +135,27 @@ char buffer[BUFFER_SIZE], string[BUFFER_SIZE]; Uint8 msgSize; Uint16 gameTicks; - + + serverQuit = NO; + if (SDLNet_Init() < 0) { NSLog(@"SDLNet_Init: %s", SDLNet_GetError()); - exit(EXIT_FAILURE); + serverQuit = YES; } /* Resolving the host using NULL make network interface to listen */ if (SDLNet_ResolveHost(&ip, NULL, ipcPort) < 0) { NSLog(@"SDLNet_ResolveHost: %s\n", SDLNet_GetError()); - exit(EXIT_FAILURE); + serverQuit = YES; } /* Open a connection with the IP provided (listen on the host's port) */ if (!(sd = SDLNet_TCP_Open(&ip))) { NSLog(@"SDLNet_TCP_Open: %s %\n", SDLNet_GetError(), ipcPort); - exit(EXIT_FAILURE); + serverQuit = YES; } NSLog(@"engineProtocol - Waiting for a client on port %d", ipcPort); - serverQuit = NO; while (!serverQuit) { /* This check the sd if there is a pending connection. @@ -175,13 +181,12 @@ addteam <32charsMD5hash> addhh is 0 for human, 1-5 for bots (5 is the most stupid) - ammostore is one byte/number for each ammocount then one for each probability or so */ // local game [self sendToEngine:@"TL"]; // seed info - [self sendToEngine:@"eseed {232c1b42-7d39-4ee6-adf8-4240e1f1efb8}"]; + [self sendToEngine:[self.gameConfig objectForKey:@"seed_command"]]; // various flags [self sendToEngine:@"e$gmflags 256"]; @@ -198,7 +203,8 @@ // theme info [self sendToEngine:@"etheme Compost"]; - for (NSDictionary *teamData in self.teamsConfig) { + NSArray *teamsConfig = [self.gameConfig objectForKey:@"teams_list"]; + for (NSDictionary *teamData in teamsConfig) { [self sendTeamData:[teamData objectForKey:@"team"] withPlayingHogs:[[teamData objectForKey:@"number"] intValue] ofColor:[teamData objectForKey:@"color"]]; @@ -210,7 +216,7 @@ @"0405040541600655546554464776576666666155501",@"ammostore_probability", @"0000000000000205500000040007004000000000200",@"ammostore_delay", @"1311110312111111123114111111111111111211101",@"ammostore_crate", nil]; - [self sendAmmoData:ammoData forTeams:[self.teamsConfig count]]; + [self sendAmmoData:ammoData forTeams:[teamsConfig count]]; [ammoData release]; clientQuit = NO; diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/MapConfigViewController.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cocoaTouch/MapConfigViewController.h Sun Apr 25 02:30:42 2010 +0000 @@ -0,0 +1,28 @@ +// +// MapConfigViewController.h +// HedgewarsMobile +// +// Created by Vittorio on 22/04/10. +// Copyright 2010 __MyCompanyName__. All rights reserved. +// + +#import +#import "SDL_net.h" + +@interface MapConfigViewController : UIViewController { + TCPsocket sd, csd; + NSInteger maxHogs; + unsigned char map[128*32]; + + UIButton *previewButton; + NSString *seedCommand; +} + +@property (nonatomic) NSInteger maxHogs; +@property (nonatomic,retain) UIButton *previewButton; +@property (nonatomic,retain) NSString *seedCommand; + +-(IBAction) updatePreview; +-(void) engineProtocol:(NSInteger) port; + +@end diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/MapConfigViewController.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cocoaTouch/MapConfigViewController.m Sun Apr 25 02:30:42 2010 +0000 @@ -0,0 +1,189 @@ +// +// MapConfigViewController.m +// HedgewarsMobile +// +// Created by Vittorio on 22/04/10. +// Copyright 2010 __MyCompanyName__. All rights reserved. +// + +#import "MapConfigViewController.h" +#import "PascalImports.h" +#import "CommodityFunctions.h" +#import "UIImageExtra.h" +#import "SDL_net.h" +#import + +@implementation MapConfigViewController +@synthesize previewButton, maxHogs, seedCommand; + + +-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return rotationManager(interfaceOrientation); +} + +#pragma mark - +#pragma mark Preview Handling +-(int) sendToEngine: (NSString *)string { + unsigned char length = [string length]; + + SDLNet_TCP_Send(csd, &length , 1); + return SDLNet_TCP_Send(csd, [string UTF8String], length); +} + +-(void) engineProtocol:(NSInteger) port { + IPaddress ip; + BOOL clientQuit, serverQuit; + + serverQuit = NO; + clientQuit =NO; + if (SDLNet_Init() < 0) { + NSLog(@"SDLNet_Init: %s", SDLNet_GetError()); + serverQuit = YES; + } + + /* Resolving the host using NULL make network interface to listen */ + if (SDLNet_ResolveHost(&ip, NULL, port) < 0) { + NSLog(@"SDLNet_ResolveHost: %s\n", SDLNet_GetError()); + serverQuit = YES; + } + + /* Open a connection with the IP provided (listen on the host's port) */ + if (!(sd = SDLNet_TCP_Open(&ip))) { + NSLog(@"SDLNet_TCP_Open: %s %\n", SDLNet_GetError(), port); + serverQuit = YES; + } + + NSLog(@"engineProtocol - Waiting for a client on port %d", port); + while (!serverQuit) { + /* This check the sd if there is a pending connection. + * If there is one, accept that, and open a new socket for communicating */ + csd = SDLNet_TCP_Accept(sd); + if (NULL != csd) { + NSLog(@"engineProtocol - Client found"); + + [self sendToEngine:self.seedCommand]; + [self sendToEngine:@"e$template_filter 1"]; + [self sendToEngine:@"e$mapgen 0"]; + [self sendToEngine:@"e$maze_size 1"]; + [self sendToEngine:@"!"]; + + memset(map, 0, 128*32); + SDLNet_TCP_Recv(csd, map, 128*32); + SDLNet_TCP_Recv(csd, &maxHogs, sizeof(Uint8)); + + SDLNet_TCP_Close(csd); + serverQuit = YES; + } + } + + SDLNet_TCP_Close(sd); + SDLNet_Quit(); +} + + +-(void) updatePreview { + pthread_t thread_id; + + // generate a seed + char randomStr[36]; + for (int i = 0; i<36; i++) { + randomStr[i] = random()%255; + } + NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%s}", randomStr]; + self.seedCommand = seedCmd; + [seedCmd release]; + + // select the port for IPC + int port = randomPort(); + pthread_create(&thread_id, NULL, (void *)GenLandPreview, (void *)port); + [self engineProtocol:port]; + + // draw the buffer (1 pixel per component, 0= transparent 1= color) + int xc = 0; + int yc = 0; + UIGraphicsBeginImageContext(CGSizeMake(256,128)); + CGContextRef context = UIGraphicsGetCurrentContext(); + UIGraphicsPushContext(context); + for (int x = 0; x < 32*128; x++) { + unsigned char byte = map[x]; + for (int z = 0; z < 8; z++) { + // select the color + if ((byte & 0x00000001) != 0) + CGContextSetRGBFillColor(context, 0.5, 0.5, 0.7, 1.0); + else + CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0); + + // draw pixel + CGContextFillRect(context,CGRectMake(xc,yc,1,1)); + // move coordinates + xc = (xc+1)%256; + if (xc == 0) yc++; + + // shift to next bit + byte = byte >> 1; + } + } + UIGraphicsPopContext(); + UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + /* + CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray(); + CGContextRef bitmapImage = CGBitmapContextCreate(mapExp, 128, 32, 8, 128, colorspace, kCGImageAlphaNone); + CGColorSpaceRelease(colorspace); + + CGImageRef previewCGImage = CGBitmapContextCreateImage(bitmapImage); + UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage]; + CGImageRelease(previewCGImage); + */ + + // set the image in the button + [self.previewButton setImage:image forState:UIControlStateNormal]; +} + +#pragma mark - +#pragma mark view management +-(void) viewDidLoad { + srandom(time(NULL)); + [super viewDidLoad]; + + CGSize screenSize = [[UIScreen mainScreen] bounds].size; + self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); + + UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + button.frame = CGRectMake(32, 32, 256, 128); + [button addTarget:self action:@selector(updatePreview) forControlEvents:UIControlEventTouchUpInside]; + self.previewButton = button; + [button release]; + [self.view addSubview:self.previewButton]; +} + +-(void) viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + [self updatePreview]; +} + +-(void) didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + // Release any cached data, images, etc that aren't in use. +} + +#pragma mark - +#pragma mark memory +-(void) viewDidUnload { + self.previewButton = nil; + self.seedCommand = nil; + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +-(void) dealloc { + [previewButton release]; + [seedCommand release]; + [super dealloc]; +} + + +@end diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m --- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m Sun Apr 25 02:30:42 2010 +0000 @@ -123,7 +123,7 @@ [uiwindow addSubview:viewController.view]; // Set working directory to resource path - [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; + [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] resourcePath]]; [uiwindow makeKeyAndVisible]; [uiwindow layoutSubviews]; diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/SingleTeamViewController.m --- a/cocoaTouch/SingleTeamViewController.m Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/SingleTeamViewController.m Sun Apr 25 02:30:42 2010 +0000 @@ -342,7 +342,7 @@ -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row = [indexPath row]; NSInteger section = [indexPath section]; - UITableViewController *nextController; + UITableViewController *nextController = nil; UITableViewCell *cell; if (2 == section) { diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/SplitViewRootController.m --- a/cocoaTouch/SplitViewRootController.m Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/SplitViewRootController.m Sun Apr 25 02:30:42 2010 +0000 @@ -64,7 +64,6 @@ [self.view addSubview:detailedNavController.view]; } - [super viewDidLoad]; } diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/TeamConfigViewController.m --- a/cocoaTouch/TeamConfigViewController.m Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/TeamConfigViewController.m Sun Apr 25 02:30:42 2010 +0000 @@ -27,7 +27,6 @@ self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); } - -(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; @@ -50,7 +49,6 @@ [emptyArray release]; [self.tableView reloadData]; - NSLog(@"%@",listOfTeams); } /* @@ -69,7 +67,6 @@ } */ - -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return rotationManager(interfaceOrientation); } diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/otherSrc/CommodityFunctions.h --- a/cocoaTouch/otherSrc/CommodityFunctions.h Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/otherSrc/CommodityFunctions.h Sun Apr 25 02:30:42 2010 +0000 @@ -29,4 +29,4 @@ void createTeamNamed (NSString *nameWithoutExt); BOOL rotationManager (UIInterfaceOrientation interfaceOrientation); - +NSInteger randomPort(); diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/otherSrc/CommodityFunctions.m --- a/cocoaTouch/otherSrc/CommodityFunctions.m Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/otherSrc/CommodityFunctions.m Sun Apr 25 02:30:42 2010 +0000 @@ -49,3 +49,9 @@ return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } + +NSInteger randomPort() { + return (random() % 64541) + 1025; +} + + diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/otherSrc/PascalImports.h --- a/cocoaTouch/otherSrc/PascalImports.h Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/otherSrc/PascalImports.h Sun Apr 25 02:30:42 2010 +0000 @@ -19,6 +19,7 @@ */ void Game(const char *args[]); + void GenLandPreview(); void HW_versionInfo(short int*, char**); diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/xib/GameConfigViewController-iPhone.xib --- a/cocoaTouch/xib/GameConfigViewController-iPhone.xib Thu Apr 22 17:43:12 2010 +0000 +++ b/cocoaTouch/xib/GameConfigViewController-iPhone.xib Sun Apr 25 02:30:42 2010 +0000 @@ -12,7 +12,7 @@ YES - + YES @@ -50,7 +50,7 @@ 292 - {{85, 8}, {269, 30}} + {{97, 8}, {245, 30}} NO IBCocoaTouchFramework @@ -59,9 +59,9 @@ 0 YES + Map Teams - Weapons - Schemes + Details YES @@ -168,6 +168,15 @@ 23 + + + segmentPressed: + + + 13 + + 29 + @@ -292,7 +301,7 @@ - 24 + 29 @@ -301,15 +310,23 @@ GameConfigViewController UIViewController - buttonPressed: - id + YES + + YES + buttonPressed: + segmentPressed: + + + YES + id + id + YES YES availableTeamsTableView - backButton mapButton randomButton schemesButton @@ -322,8 +339,7 @@ UIButton UIButton UIButton - UIButton - UIButton + UIBarButtonItem UIButton diff -r e5403e2bf02c -r 37ac593e9027 cocoaTouch/xib/MapConfigViewController-iPhone.xib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cocoaTouch/xib/MapConfigViewController-iPhone.xib Sun Apr 25 02:30:42 2010 +0000 @@ -0,0 +1,488 @@ + + + + 800 + 10D573 + 762 + 1038.29 + 460.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 87 + + + YES + + + + YES + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + YES + + YES + + + YES + + + + YES + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + YES + + + 290 + {{240, 60}, {240, 216}} + + IBCocoaTouchFramework + YES + + + + 292 + {{240, 9}, {240, 44}} + + NO + IBCocoaTouchFramework + 3 + 0 + + YES + Map + Random + Maze + + + YES + + + + + + YES + + + + + + YES + {0, 0} + {0, 0} + {0, 0} + + + YES + + + + + + + + 292 + {{18.5, 234}, {150, 23}} + + NO + IBCocoaTouchFramework + 0 + 0 + 0.05000000074505806 + 0.05000000074505806 + + + {480, 276} + + + 3 + MQA + + + + 3 + + IBCocoaTouchFramework + + + + + YES + + + view + + + + 3 + + + + + YES + + 0 + + + + + + 1 + + + YES + + + + + + + + -1 + + + File's Owner + + + -2 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + + + YES + + YES + -1.CustomClassName + -2.CustomClassName + 1.IBEditorWindowLastContentRect + 1.IBPluginDependency + 6.IBPluginDependency + 7.IBPluginDependency + 8.IBPluginDependency + + + YES + MapConfigViewController + UIResponder + {{556, 572}, {480, 320}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + YES + + + YES + + + + + YES + + + YES + + + + 8 + + + + YES + + MapConfigViewController + UIViewController + + IBProjectSource + ../../cocoaTouch/MapConfigViewController.h + + + + + YES + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSNetServices.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSPort.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSStream.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSXMLParser.h + + + + NSObject + + IBFrameworkSource + QuartzCore.framework/Headers/CAAnimation.h + + + + NSObject + + IBFrameworkSource + QuartzCore.framework/Headers/CALayer.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIAccessibility.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UINibLoading.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIResponder.h + + + + UIControl + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIControl.h + + + + UIPickerView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIPickerView.h + + + + UIResponder + NSObject + + + + UISearchBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UISearchBar.h + + + + UISearchDisplayController + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UISearchDisplayController.h + + + + UISegmentedControl + UIControl + + IBFrameworkSource + UIKit.framework/Headers/UISegmentedControl.h + + + + UISlider + UIControl + + IBFrameworkSource + UIKit.framework/Headers/UISlider.h + + + + UIView + + IBFrameworkSource + UIKit.framework/Headers/UITextField.h + + + + UIView + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIView.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UINavigationController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UIPopoverController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UISplitViewController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UITabBarController.h + + + + UIViewController + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIViewController.h + + + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 + + + YES + ../project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj + 3 + 87 + + diff -r e5403e2bf02c -r 37ac593e9027 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Thu Apr 22 17:43:12 2010 +0000 +++ b/hedgewars/hwengine.pas Sun Apr 25 02:30:42 2010 +0000 @@ -324,6 +324,8 @@ procedure initEverything; begin + Randomize(); + uConsts.initModule; uMisc.initModule; uConsole.initModule; // MUST happen after uMisc @@ -395,21 +397,27 @@ end; ///////////////////////// -procedure GenLandPreview; +procedure GenLandPreview{$IFDEF IPHONEOS}(port: LongInt){$ENDIF}; {$IFDEF HWLIBRARY}cdecl; export;{$ENDIF} var Preview: TPreview; - h: byte; begin +{$IFDEF IPHONEOS} + initEverything(); + WriteLnToConsole('Preview connecting on port ' + inttostr(port)); + ipcPort:= port; +{$ENDIF} InitIPC; IPCWaitPongEvent; TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); - Preview:= GenPreview; + Preview:= GenPreview(); WriteLnToConsole('Sending preview...'); SendIPCRaw(@Preview, sizeof(Preview)); - h:= MaxHedgehogs; - SendIPCRaw(@h, sizeof(h)); + SendIPCRaw(@MaxHedgehogs, sizeof(byte)); WriteLnToConsole('Preview sent, disconnect'); CloseIPC(); +{$IFDEF IPHONEOS} + freeEverything(); +{$ENDIF} end; {$IFNDEF HWLIBRARY} @@ -580,7 +588,6 @@ WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); GetParams(); - Randomize(); if GameType = gmtLandPreview then GenLandPreview() else if GameType = gmtSyntax then DisplayUsage() diff -r e5403e2bf02c -r 37ac593e9027 hedgewars/uLand.pas --- a/hedgewars/uLand.pas Thu Apr 22 17:43:12 2010 +0000 +++ b/hedgewars/uLand.pas Sun Apr 25 02:30:42 2010 +0000 @@ -723,10 +723,10 @@ while (tries < 5) and not found_cell do begin - if when_seen(x + dir.x, y + dir.y) = current_step then //we're seeing ourselves, try another direction + if when_seen(x + dir.x, y + dir.y) = current_step then //we are seeing ourselves, try another direction begin //we have already seen the target cell, decide if we should remove the wall anyway - //(or put a wall there if maze_inverted, but we're not doing that right now) + //(or put a wall there if maze_inverted, but we are not doing that right now) if not maze_inverted and (GetRandom(braidness) = 0) then //or just warn that inverted+braid+indestructible terrain != good idea begin @@ -762,7 +762,7 @@ dir := DIR_S; end end - else if when_seen(x + dir.x, y + dir.y) = -1 then //cell wasn't seen yet, go there + else if when_seen(x + dir.x, y + dir.y) = -1 then //cell was not seen yet, go there begin case dir.y of -1: xwalls[x, y-1] := false; @@ -779,7 +779,7 @@ came_from[current_step, came_from_pos[current_step]].y := y; found_cell := true; end - else //we're seeing someone else, quit + else //we are seeing someone else, quit begin step_done[current_step] := true; found_cell := true; @@ -1284,26 +1284,28 @@ var x, y, xx, yy, t, bit: LongInt; Preview: TPreview; begin -WriteLnToConsole('Generating preview...'); -case cMapGen of - 0: GenBlank(EdgeTemplates[SelectTemplate]); - 1: GenMaze; -end; + WriteLnToConsole('Generating preview...'); + case cMapGen of + 0: GenBlank(EdgeTemplates[SelectTemplate]); + 1: GenMaze; + end; -for y:= 0 to 127 do - for x:= 0 to 31 do + for y:= 0 to 127 do + for x:= 0 to 31 do begin - Preview[y, x]:= 0; - for bit:= 0 to 7 do + Preview[y, x]:= 0; + for bit:= 0 to 7 do begin - t:= 0; - for yy:= y * (LAND_HEIGHT div 128) to y * (LAND_HEIGHT div 128) + 7 do - for xx:= x * (LAND_WIDTH div 32) + bit * 8 to x * (LAND_WIDTH div 32) + bit * 8 + 7 do - if Land[yy, xx] <> 0 then inc(t); - if t > 8 then Preview[y, x]:= Preview[y, x] or ($80 shr bit) - end + t:= 0; + for yy:= y * (LAND_HEIGHT div 128) to y * (LAND_HEIGHT div 128) + 7 do + for xx:= x * (LAND_WIDTH div 32) + bit * 8 to x * (LAND_WIDTH div 32) + bit * 8 + 7 do + if Land[yy, xx] <> 0 then inc(t); + if t > 8 then + Preview[y, x]:= Preview[y, x] or ($80 shr bit); + end; end; -GenPreview:= Preview + + GenPreview:= Preview end; procedure initModule; diff -r e5403e2bf02c -r 37ac593e9027 hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Thu Apr 22 17:43:12 2010 +0000 +++ b/hedgewars/uMisc.pas Sun Apr 25 02:30:42 2010 +0000 @@ -661,9 +661,9 @@ endian:= independent; {$ELSE} endian:= (((independent and $FF000000) shr 24) or - ((independent and $00FF0000) shr 8) or - ((independent and $0000FF00) shl 8) or - ((independent and $000000FF) shl 24)) + ((independent and $00FF0000) shr 8) or + ((independent and $0000FF00) shl 8) or + ((independent and $000000FF) shl 24)) {$ENDIF} end; diff -r e5403e2bf02c -r 37ac593e9027 project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj/project.pbxproj --- a/project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj/project.pbxproj Thu Apr 22 17:43:12 2010 +0000 +++ b/project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj/project.pbxproj Sun Apr 25 02:30:42 2010 +0000 @@ -40,6 +40,7 @@ 61370676117B32EF004EE44A /* GameConfigViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61370674117B32EF004EE44A /* GameConfigViewController.m */; }; 6151347E116C2803001F16D1 /* Icon-iPad.png in Resources */ = {isa = PBXBuildFile; fileRef = 6151347D116C2803001F16D1 /* Icon-iPad.png */; }; 615134B1116C2C5F001F16D1 /* OverlayViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 615134B0116C2C5F001F16D1 /* OverlayViewController.xib */; }; + 615A92911183E31C006CA772 /* MapConfigViewController-iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 615A92901183E31C006CA772 /* MapConfigViewController-iPhone.xib */; }; 61798816114AA34C00BA94A9 /* hwengine.pas in Sources */ = {isa = PBXBuildFile; fileRef = 617987E7114AA34C00BA94A9 /* hwengine.pas */; }; 61798818114AA34C00BA94A9 /* hwLibrary.pas in Sources */ = {isa = PBXBuildFile; fileRef = 617987E9114AA34C00BA94A9 /* hwLibrary.pas */; }; 6179881B114AA34C00BA94A9 /* PascalExports.pas in Sources */ = {isa = PBXBuildFile; fileRef = 617987EC114AA34C00BA94A9 /* PascalExports.pas */; }; @@ -130,6 +131,7 @@ 61A11AE11168DC6E00359010 /* SingleTeamViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A11AE01168DC6E00359010 /* SingleTeamViewController.m */; }; 61A11AE41168DC9400359010 /* HogHatViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A11AE31168DC9400359010 /* HogHatViewController.m */; }; 61AA7ACA117FCC8200FDDD4D /* openalbridge_t.h in Headers */ = {isa = PBXBuildFile; fileRef = 61AA7AC9117FCC8200FDDD4D /* openalbridge_t.h */; }; + 61B22E0F1180FBF400B2FCE0 /* MapConfigViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B22E0D1180FBF400B2FCE0 /* MapConfigViewController.m */; }; 61C325451179A336001E70B1 /* globals.h in Headers */ = {isa = PBXBuildFile; fileRef = 61C3253B1179A336001E70B1 /* globals.h */; }; 61C325461179A336001E70B1 /* loaders.c in Sources */ = {isa = PBXBuildFile; fileRef = 61C3253C1179A336001E70B1 /* loaders.c */; }; 61C325471179A336001E70B1 /* loaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 61C3253D1179A336001E70B1 /* loaders.h */; }; @@ -242,6 +244,7 @@ 61370674117B32EF004EE44A /* GameConfigViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GameConfigViewController.m; path = ../../cocoaTouch/GameConfigViewController.m; sourceTree = SOURCE_ROOT; }; 6151347D116C2803001F16D1 /* Icon-iPad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-iPad.png"; path = "../../cocoaTouch/resources/Icon-iPad.png"; sourceTree = SOURCE_ROOT; }; 615134B0116C2C5F001F16D1 /* OverlayViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = OverlayViewController.xib; path = ../../cocoaTouch/xib/OverlayViewController.xib; sourceTree = SOURCE_ROOT; }; + 615A92901183E31C006CA772 /* MapConfigViewController-iPhone.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MapConfigViewController-iPhone.xib"; path = "../../cocoaTouch/xib/MapConfigViewController-iPhone.xib"; sourceTree = SOURCE_ROOT; }; 617987E1114AA34C00BA94A9 /* CCHandlers.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = CCHandlers.inc; path = ../../hedgewars/CCHandlers.inc; sourceTree = SOURCE_ROOT; }; 617987E4114AA34C00BA94A9 /* GSHandlers.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = GSHandlers.inc; path = ../../hedgewars/GSHandlers.inc; sourceTree = SOURCE_ROOT; }; 617987E5114AA34C00BA94A9 /* HHHandlers.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = HHHandlers.inc; path = ../../hedgewars/HHHandlers.inc; sourceTree = SOURCE_ROOT; }; @@ -354,6 +357,8 @@ 61A11AE21168DC9400359010 /* HogHatViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HogHatViewController.h; path = ../../cocoaTouch/HogHatViewController.h; sourceTree = SOURCE_ROOT; }; 61A11AE31168DC9400359010 /* HogHatViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HogHatViewController.m; path = ../../cocoaTouch/HogHatViewController.m; sourceTree = SOURCE_ROOT; }; 61AA7AC9117FCC8200FDDD4D /* openalbridge_t.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = openalbridge_t.h; path = ../../misc/openalbridge/openalbridge_t.h; sourceTree = SOURCE_ROOT; }; + 61B22E0C1180FBF400B2FCE0 /* MapConfigViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MapConfigViewController.h; path = ../../cocoaTouch/MapConfigViewController.h; sourceTree = SOURCE_ROOT; }; + 61B22E0D1180FBF400B2FCE0 /* MapConfigViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MapConfigViewController.m; path = ../../cocoaTouch/MapConfigViewController.m; sourceTree = SOURCE_ROOT; }; 61C3251D1179A300001E70B1 /* libopenalbridge.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libopenalbridge.a; sourceTree = BUILT_PRODUCTS_DIR; }; 61C3253B1179A336001E70B1 /* globals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = globals.h; path = ../../misc/openalbridge/globals.h; sourceTree = SOURCE_ROOT; }; 61C3253C1179A336001E70B1 /* loaders.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = loaders.c; path = ../../misc/openalbridge/loaders.c; sourceTree = SOURCE_ROOT; }; @@ -521,6 +526,7 @@ 6100DB1711544E8400F455E0 /* XIB */ = { isa = PBXGroup; children = ( + 615A92901183E31C006CA772 /* MapConfigViewController-iPhone.xib */, 611E127C117BACC60044B62F /* GameConfigViewController-iPad.xib */, 61A118C911683C7600359010 /* MainMenuViewController-iPad.xib */, 611E127E117BACCD0044B62F /* GameConfigViewController-iPhone.xib */, @@ -559,6 +565,8 @@ children = ( 61370673117B32EF004EE44A /* GameConfigViewController.h */, 61370674117B32EF004EE44A /* GameConfigViewController.m */, + 61B22E0C1180FBF400B2FCE0 /* MapConfigViewController.h */, + 61B22E0D1180FBF400B2FCE0 /* MapConfigViewController.m */, 61272422117E17CF005B90CF /* TeamConfigViewController.h */, 61272423117E17CF005B90CF /* TeamConfigViewController.m */, ); @@ -967,6 +975,7 @@ 611E127D117BACC60044B62F /* GameConfigViewController-iPad.xib in Resources */, 611E127F117BACCD0044B62F /* GameConfigViewController-iPhone.xib in Resources */, 611E12FF117BBBDA0044B62F /* Entitlements-Development.plist in Resources */, + 615A92911183E31C006CA772 /* MapConfigViewController-iPhone.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1086,6 +1095,7 @@ 61272424117E17CF005B90CF /* TeamConfigViewController.m in Sources */, 612724D3117E28AF005B90CF /* HogButtonView.m in Sources */, 61CF4971117E702F00BF05B7 /* SquareButtonView.m in Sources */, + 61B22E0F1180FBF400B2FCE0 /* MapConfigViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1161,7 +1171,7 @@ CODE_SIGN_ENTITLEMENTS = "Entitlements-Distribution.plist"; CODE_SIGN_IDENTITY = "iPhone Distribution"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; - FPC_COMMON_OPTIONS = "-dIPHONEOS -Cs2000000 -vwi -B -Sgix -dLOWRES"; + FPC_COMMON_OPTIONS = "-dIPHONEOS -Cs2000000 -vwi -B -Sgix"; FPC_COMPILER_BINARY_DIR = /usr/local/lib/fpc/2.5.1; FPC_MAIN_FILE = "$(PROJECT_DIR)/../../hedgewars/hwLibrary.pas"; FPC_RTL_UNITS_BASE = /usr/local/lib/fpc; @@ -1365,7 +1375,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer: Vittorio Giovara (DC2BRETXAC)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Vittorio Giovara (DC2BRETXAC)"; DEBUG_INFORMATION_FORMAT = stabs; - FPC_COMMON_OPTIONS = "-dIPHONEOS -Cs2000000 -vwi -B -Sgix -dLOWRES"; + FPC_COMMON_OPTIONS = "-dIPHONEOS -Cs2000000 -vwi -B -Sgix"; FPC_COMPILER_BINARY_DIR = /usr/local/lib/fpc/2.5.1; FPC_MAIN_FILE = "$(PROJECT_DIR)/../../hedgewars/hwLibrary.pas"; FPC_RTL_UNITS_BASE = /usr/local/lib/fpc; @@ -1404,7 +1414,7 @@ ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; CODE_SIGN_IDENTITY = "iPhone Developer: Vittorio Giovara (DC2BRETXAC)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Vittorio Giovara (DC2BRETXAC)"; - FPC_COMMON_OPTIONS = "-dIPHONEOS -Cs2000000 -vwi -B -Sgix -dLOWRES"; + FPC_COMMON_OPTIONS = "-dIPHONEOS -Cs2000000 -vwi -B -Sgix"; FPC_COMPILER_BINARY_DIR = /usr/local/lib/fpc/2.5.1; FPC_MAIN_FILE = "$(PROJECT_DIR)/../../hedgewars/hwLibrary.pas"; FPC_RTL_UNITS_BASE = /usr/local/lib/fpc;