# HG changeset patch # User koda # Date 1271958192 0 # Node ID e5403e2bf02c2f3612c5bc9e56ab8f9f5bf1ed20 # Parent bcd6d76db4f7c5edf350d711a18f4d8811f05a15 no more hardcoded teams, team selection is real \o/ custom buttons rock removed difficult errlib from openalbridge diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/DetailViewController.m --- a/cocoaTouch/DetailViewController.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/DetailViewController.m Thu Apr 22 17:43:12 2010 +0000 @@ -92,7 +92,7 @@ #pragma mark Table view delegate -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row = [indexPath row]; - UIViewController *nextController; + UIViewController *nextController = nil; switch (row) { case 0: diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/GameConfigViewController.h --- a/cocoaTouch/GameConfigViewController.h Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/GameConfigViewController.h Thu Apr 22 17:43:12 2010 +0000 @@ -30,5 +30,5 @@ @property (nonatomic,retain) IBOutlet UIBarButtonItem *startButton; -(IBAction) buttonPressed:(id) sender; - +-(void) startGame; @end diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/GameConfigViewController.m --- a/cocoaTouch/GameConfigViewController.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/GameConfigViewController.m Thu Apr 22 17:43:12 2010 +0000 @@ -27,19 +27,29 @@ [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; break; case 1: - [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; - [self performSelector:@selector(startSDLgame) + [self performSelector:@selector(startGame) withObject:nil - afterDelay:0.4]; + afterDelay:0.25]; break; } } --(void) startSDLgame { - [[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; +-(void) startGame { + 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",@"") + 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]; + } } -// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -(void) viewDidLoad { teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; activeController = teamConfigViewController; diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/GameSetup.h --- a/cocoaTouch/GameSetup.h Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/GameSetup.h Thu Apr 22 17:43:12 2010 +0000 @@ -11,20 +11,20 @@ @interface GameSetup : NSObject { NSDictionary *systemSettings; - NSMutableArray *teams; + NSArray *teamsConfig; NSInteger ipcPort; TCPsocket sd, csd; // Socket descriptor, Client socket descriptor } @property (nonatomic, retain) NSDictionary *systemSettings; -@property (nonatomic, retain) NSArray *teams; +@property (nonatomic, retain) NSArray *teamsConfig; -(void) engineProtocol; -(void) startThread: (NSString *)selector; -(int) sendToEngine: (NSString *)string; --(void) sendTeamData:(NSDictionary *)teamData withPlayingHogs:(int) playingHogs; --(void) initTeam:(NSArray *)teamLists; +-(void) sendTeamData:(NSString *)fileName withPlayingHogs:(NSInteger) playingHogs ofColor:(NSNumber *)color; +-(void) sendAmmoData:(NSDictionary *)ammoData forTeams: (NSInteger)numberPlaying; -(const char **)getSettings; diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/GameSetup.m --- a/cocoaTouch/GameSetup.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/GameSetup.m Thu Apr 22 17:43:12 2010 +0000 @@ -20,25 +20,25 @@ @implementation GameSetup -@synthesize systemSettings, teams; +@synthesize systemSettings, teamsConfig; -(id) init { if (self = [super init]) { srandom(time(NULL)); ipcPort = (random() % 64541) + 1025; - systemSettings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; //should check it exists - return self; - } else - return nil; + self.systemSettings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; //should check it exists + self.teamsConfig = [[NSArray alloc] initWithContentsOfFile:GAMECONFIG_FILE()]; + } + return self; } -(NSString *)description { - return [NSString stringWithFormat:@"ipcport: %d\nsockets: %d,%d\n teams: %@\n systemSettings: %@",ipcPort,sd,csd,teams,systemSettings]; + return [NSString stringWithFormat:@"ipcport: %d\nsockets: %d,%d\n teams: %@\n systemSettings: %@",ipcPort,sd,csd,teamsConfig,systemSettings]; } -(void) dealloc { - [teams release]; + [teamsConfig release]; [systemSettings release]; [super dealloc]; } @@ -57,47 +57,12 @@ return SDLNet_TCP_Send(csd, [string UTF8String], length); } --(void) initTeam:(NSArray *)teamLists { - teams = [[NSMutableArray alloc] initWithObjects:nil]; - - for (NSString *teamString in teamLists) { - //NSString *teamFile = [[NSString alloc] initWithFormat:@"%@.plist", teamString]; - - //NSDictionary *theTeam = [[NSDictionary alloc] initWithContentsOfFile:filePath]; - //[teams addObject:theTeam]; - //[theTeam release]; - } +-(void) sendTeamData:(NSString *)fileName withPlayingHogs:(NSInteger) playingHogs ofColor:(NSNumber *)color{ + NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@", TEAMS_DIRECTORY(), fileName]; + NSDictionary *teamData = [[NSDictionary alloc] initWithContentsOfFile:teamFile]; + [teamFile release]; - NSDictionary *hogA1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Snow Leopard",@"hogname",@"NoHat",@"hat",nil]; - NSDictionary *hogA2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Leopard",@"hogname",@"NoHat",@"hat",nil]; - NSArray *hedgehogs1 = [[NSArray alloc] initWithObjects:hogA1,hogA2,nil]; - [hogA1 release]; - [hogA2 release]; - - NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash",@"System Cats",@"teamname", - @"star",@"grave",@"Earth",@"fort",@"Classic",@"voicepack",@"hedgewars",@"flag",hedgehogs1,@"hedgehogs", - nil]; - [hedgehogs1 release]; - [teams addObject:firstTeam]; - [firstTeam release]; - - NSDictionary *hogB1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Raichu",@"hogname",@"Bunny",@"hat",nil]; - NSDictionary *hogB2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Pikachu",@"hogname",@"Bunny",@"hat",nil]; - NSArray *hedgehogs2 = [[NSArray alloc] initWithObjects:hogB1,hogB2,nil]; - [hogB1 release]; - [hogB2 release]; - NSDictionary *secondTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4100897",@"color",@"0",@"hash",@"Poke-MAN",@"teamname", - @"Badger",@"grave",@"UFO",@"fort",@"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs2,@"hedgehogs", - nil]; - [hedgehogs2 release]; - [teams addObject:secondTeam]; - [secondTeam release]; -} - --(void) sendTeamData:(NSDictionary *)teamData withPlayingHogs:(int) playingHogs{ - int i; - - NSString *teamHashColorAndName = [[NSString alloc] initWithFormat:@"eaddteam %@ %@ %@", [teamData objectForKey:@"hash"], [teamData objectForKey:@"color"], [teamData objectForKey:@"teamname"]]; + NSString *teamHashColorAndName = [[NSString alloc] initWithFormat:@"eaddteam %@ %@ %@", [teamData objectForKey:@"hash"], [color stringValue], [teamData objectForKey:@"teamname"]]; [self sendToEngine: teamHashColorAndName]; [teamHashColorAndName release]; @@ -118,7 +83,7 @@ [flag release]; NSArray *hogs = [teamData objectForKey:@"hedgehogs"]; - for (i = 0; i < playingHogs; i++) { + for (int i = 0; i < playingHogs; i++) { NSDictionary *hog = [hogs objectAtIndex:i]; NSString *hogLevelHealthAndName = [[NSString alloc] initWithFormat:@"eaddhh %@ %@ %@", [hog objectForKey:@"level"], [hog objectForKey:@"health"], [hog objectForKey:@"hogname"]]; @@ -128,10 +93,12 @@ NSString *hogHat = [[NSString alloc] initWithFormat:@"ehat %@", [hog objectForKey:@"hat"]]; [self sendToEngine: hogHat]; [hogHat release]; - } + } + + [teamData release]; } --(void) sendAmmoData:(NSDictionary *)ammoData { +-(void) sendAmmoData:(NSDictionary *)ammoData forTeams: (NSInteger)numberPlaying { NSString *ammloadt = [[NSString alloc] initWithFormat:@"eammloadt %@", [ammoData objectForKey:@"ammostore_initialqt"]]; [self sendToEngine: ammloadt]; [ammloadt release]; @@ -150,8 +117,8 @@ // sent twice so it applies to both teams NSString *ammstore = [[NSString alloc] initWithString:@"eammstore"]; - [self sendToEngine: ammstore]; - [self sendToEngine: ammstore]; + for (int i = 0; i < numberPlaying; i++) + [self sendToEngine: ammstore]; [ammstore release]; } @@ -202,10 +169,6 @@ if ('C' == buffer[0]) { NSLog(@"engineProtocol - sending game config"); - NSArray *teamlist = [[NSArray alloc] initWithObjects:@"this",@"is",@"test",nil]; - [self initTeam:teamlist]; - [teamlist release]; - // send config data data /* seed is arbitrary string @@ -235,8 +198,10 @@ // theme info [self sendToEngine:@"etheme Compost"]; - for (NSDictionary *teamData in teams) { - [self sendTeamData:teamData withPlayingHogs:2]; + for (NSDictionary *teamData in self.teamsConfig) { + [self sendTeamData:[teamData objectForKey:@"team"] + withPlayingHogs:[[teamData objectForKey:@"number"] intValue] + ofColor:[teamData objectForKey:@"color"]]; NSLog(@"teamData sent"); } @@ -245,10 +210,10 @@ @"0405040541600655546554464776576666666155501",@"ammostore_probability", @"0000000000000205500000040007004000000000200",@"ammostore_delay", @"1311110312111111123114111111111111111211101",@"ammostore_crate", nil]; - [self sendAmmoData: ammoData]; + [self sendAmmoData:ammoData forTeams:[self.teamsConfig count]]; [ammoData release]; - clientQuit = NO; + clientQuit = NO; } else { NSLog(@"engineProtocolThread - wrong message or client closed connection"); clientQuit = YES; @@ -355,7 +320,7 @@ // prevents using an empty nickname NSString *username; - NSString *originalUsername = [systemSettings objectForKey:@"username"]; + NSString *originalUsername = [self.systemSettings objectForKey:@"username"]; if ([originalUsername length] == 0) { username = [[NSString alloc] initWithFormat:@"MobileUser-%@",ipcString]; } else { @@ -364,10 +329,10 @@ gameArgs[0] = [username UTF8String]; //UserNick gameArgs[1] = [ipcString UTF8String]; //ipcPort - gameArgs[2] = [[[systemSettings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled - gameArgs[3] = [[[systemSettings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled + gameArgs[2] = [[[self.systemSettings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled + gameArgs[3] = [[[self.systemSettings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled gameArgs[4] = [localeString UTF8String]; //cLocaleFName - gameArgs[5] = [[[systemSettings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage + gameArgs[5] = [[[self.systemSettings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage gameArgs[6] = [wSize UTF8String]; //cScreenHeight gameArgs[7] = [hSize UTF8String]; //cScreenWidth diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/GravesViewController.m --- a/cocoaTouch/GravesViewController.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/GravesViewController.m Thu Apr 22 17:43:12 2010 +0000 @@ -143,7 +143,7 @@ #pragma mark - #pragma mark Table view delegate -- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { +-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { int newRow = [indexPath row]; int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/MainMenuViewController.m --- a/cocoaTouch/MainMenuViewController.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/MainMenuViewController.m Thu Apr 22 17:43:12 2010 +0000 @@ -65,7 +65,6 @@ [indicator startAnimating]; [alert addSubview:indicator]; [indicator release]; - [alert release]; // create a team createTeamNamed(@"Default Team"); @@ -84,6 +83,7 @@ // ok let the user take control [alert dismissWithClickedButtonIndex:0 animated:YES]; + [alert release]; [pool release]; [NSThread exit]; diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/MasterViewController.m --- a/cocoaTouch/MasterViewController.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/MasterViewController.m Thu Apr 22 17:43:12 2010 +0000 @@ -97,7 +97,7 @@ -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { int newRow = [indexPath row]; int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; - UIViewController *nextController; + UIViewController *nextController = nil; if (newRow != oldRow) { [self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES]; diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/OverlayViewController.h --- a/cocoaTouch/OverlayViewController.h Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/OverlayViewController.h Thu Apr 22 17:43:12 2010 +0000 @@ -24,7 +24,6 @@ CGPoint gestureStartPoint; } -@property (nonatomic,retain) NSTimer *dimTimer; @property (nonatomic,retain) id popoverController; @property (nonatomic,retain) PopoverMenuViewController *popupMenu; diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/OverlayViewController.m --- a/cocoaTouch/OverlayViewController.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/OverlayViewController.m Thu Apr 22 17:43:12 2010 +0000 @@ -15,7 +15,7 @@ #import "CommodityFunctions.h" @implementation OverlayViewController -@synthesize dimTimer, popoverController, popupMenu; +@synthesize popoverController, popupMenu; -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { @@ -294,14 +294,14 @@ } -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - int minimumGestureLength; + CGFloat minimumGestureLength; int logCoeff; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { - minimumGestureLength = 5; + minimumGestureLength = 5.0f; logCoeff = 19; } else { - minimumGestureLength = 3; + minimumGestureLength = 3.0f; logCoeff = 3; } @@ -318,7 +318,7 @@ if (deltaX >= minimumGestureLength) { NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); - if (currentPosition.x > gestureStartPoint.x ) { + if (currentPosition.x > gestureStartPoint.x) { HW_cursorLeft(logCoeff*log(deltaX)); } else { HW_cursorRight(logCoeff*log(deltaX)); @@ -327,7 +327,7 @@ } if (deltaY >= minimumGestureLength) { NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); - if (currentPosition.y < gestureStartPoint.y ) { + if (currentPosition.y < gestureStartPoint.y) { HW_cursorDown(logCoeff*log(deltaY)); } else { HW_cursorUp(logCoeff*log(deltaY)); diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/SingleTeamViewController.m --- a/cocoaTouch/SingleTeamViewController.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/SingleTeamViewController.m Thu Apr 22 17:43:12 2010 +0000 @@ -217,13 +217,12 @@ static NSString *CellIdentifier2 = @"Cell2"; NSArray *hogArray; - UITableViewCell *cell; + UITableViewCell *cell = nil; NSInteger row = [indexPath row]; UIImage *accessoryImage; switch ([indexPath section]) { case 0: - cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/TeamConfigViewController.h --- a/cocoaTouch/TeamConfigViewController.h Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/TeamConfigViewController.h Thu Apr 22 17:43:12 2010 +0000 @@ -11,8 +11,12 @@ @interface TeamConfigViewController : UITableViewController { NSMutableArray *listOfTeams; + NSMutableArray *listOfSelectedTeams; + NSIndexPath *lastIndexPath; } @property (nonatomic, retain) NSMutableArray *listOfTeams; +@property (nonatomic, retain) NSMutableArray *listOfSelectedTeams; +@property (nonatomic,retain) NSIndexPath *lastIndexPath; @end diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/TeamConfigViewController.m --- a/cocoaTouch/TeamConfigViewController.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/TeamConfigViewController.m Thu Apr 22 17:43:12 2010 +0000 @@ -12,10 +12,11 @@ #import "SquareButtonView.h" @implementation TeamConfigViewController -@synthesize listOfTeams; +@synthesize listOfTeams, listOfSelectedTeams; #define NUMBERBUTTON_TAG 123456 #define SQUAREBUTTON_TAG 654321 +#define LABEL_TAG 456123 #pragma mark - #pragma mark View lifecycle @@ -27,15 +28,27 @@ } - -(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; + unsigned int colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 }; NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; - NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; + NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; + for (int i = 0; i < [contentsOfDir count]; i++) { + NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: + [contentsOfDir objectAtIndex:i],@"team", + [NSNumber numberWithInt:4],@"number", + [NSNumber numberWithInt:colors[i%6]],@"color",nil]; + [array addObject:dict]; + [dict release]; + } self.listOfTeams = array; [array release]; + NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; + self.listOfSelectedTeams = emptyArray; + [emptyArray release]; + [self.tableView reloadData]; NSLog(@"%@",listOfTeams); } @@ -65,35 +78,74 @@ #pragma mark - #pragma mark Table view data source -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { - return 1; + return 2; } -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [listOfTeams count]; + if (section == 0) + return [listOfSelectedTeams count] ; + else + return [listOfTeams count]; } +-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { + if (section == 0) + return NSLocalizedString(@"Playing Teams",@""); + else + return NSLocalizedString(@"Available Teams",@""); +} // Customize the appearance of table view cells. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - static NSString *CellIdentifier = @"Cell"; + static NSString *CellIdentifier0 = @"Cell0"; + static NSString *CellIdentifier1 = @"Cell1"; + NSInteger section = [indexPath section]; + UITableViewCell *cell; - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; - if (cell == nil) { - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; + if (section == 0) { + cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0]; + if (cell == nil) { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; + + UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)]; + numberButton.tag = NUMBERBUTTON_TAG; + [cell addSubview:numberButton]; + [numberButton release]; + + SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)]; + squareButton.tag = SQUAREBUTTON_TAG; + [cell addSubview:squareButton]; + [squareButton release]; + + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12+88+7+36+7, 10, 250, 25)]; + label.textAlignment = UITextAlignmentLeft; + label.backgroundColor = [UIColor clearColor]; + label.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2]; + label.tag = LABEL_TAG; + [cell.contentView addSubview:label]; + [label release]; + } - UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)]; - numberButton.tag = NUMBERBUTTON_TAG; - [cell addSubview:numberButton]; - [numberButton release]; + NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; + + UILabel *cellLabel = (UILabel *)[cell viewWithTag:LABEL_TAG]; + cellLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; + + HogButtonView *numberButton = (HogButtonView *)[cell viewWithTag:NUMBERBUTTON_TAG]; + [numberButton drawManyHogs:[[selectedRow objectForKey:@"number"] intValue]]; + numberButton.ownerDictionary = selectedRow; - SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)]; - squareButton.tag = SQUAREBUTTON_TAG; - [cell addSubview:squareButton]; - [squareButton release]; + SquareButtonView *squareButton = (SquareButtonView *)[cell viewWithTag:SQUAREBUTTON_TAG]; + [squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; + squareButton.ownerDictionary = selectedRow; + } else { + cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; + if (cell == nil) + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; + + cell.textLabel.text = [[[listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; } - - cell.textLabel.text = [[listOfTeams objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; - + return cell; } @@ -128,7 +180,6 @@ } */ - /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { @@ -137,25 +188,25 @@ } */ - #pragma mark - #pragma mark Table view delegate +-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + NSInteger row = [indexPath row]; + NSInteger section = [indexPath section]; -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - // Navigation logic may go here. Create and push another view controller. - /* - <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; - // ... - // Pass the selected object to the new view controller. - [self.navigationController pushViewController:detailViewController animated:YES]; - [detailViewController release]; - */ + if (section == 0) { + [self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; + [self.listOfSelectedTeams removeObjectAtIndex:row]; + } else { + [self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]]; + [self.listOfTeams removeObjectAtIndex:row]; + } + [self.tableView reloadData]; } #pragma mark - #pragma mark Memory management - -(void) didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/VoicesViewController.m --- a/cocoaTouch/VoicesViewController.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/VoicesViewController.m Thu Apr 22 17:43:12 2010 +0000 @@ -26,7 +26,7 @@ [super viewDidLoad]; srandom(time(NULL)); - openal_init(1, 1); + openal_init(1); voiceBeingPlayed = -1; // load all the voices names and store them into voiceArray diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/otherSrc/CommodityFunctions.h --- a/cocoaTouch/otherSrc/CommodityFunctions.h Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/otherSrc/CommodityFunctions.h Thu Apr 22 17:43:12 2010 +0000 @@ -13,6 +13,8 @@ #define SETTINGS_FILE() [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) \ objectAtIndex:0] stringByAppendingString:@"/settings.plist"] +#define GAMECONFIG_FILE() [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) \ + objectAtIndex:0] stringByAppendingString:@"/gameconfig.plist"] #define TEAMS_DIRECTORY() [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) \ objectAtIndex:0] stringByAppendingString:@"/Teams/"] diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/otherSrc/HogButtonView.h --- a/cocoaTouch/otherSrc/HogButtonView.h Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/otherSrc/HogButtonView.h Thu Apr 22 17:43:12 2010 +0000 @@ -12,12 +12,14 @@ @interface HogButtonView : UIButton { NSInteger numberOfHogs; UIImage *singleHog; + NSMutableDictionary *ownerDictionary; } @property (nonatomic,retain) UIImage *singleHog; +@property (nonatomic) NSInteger numberOfHogs; +@property (nonatomic,retain) NSMutableDictionary *ownerDictionary; --(void) drawManyHogs; - --(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; +-(void) drawManyHogs:(NSInteger) hogs; +-(void) addOne; @end diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/otherSrc/HogButtonView.m --- a/cocoaTouch/otherSrc/HogButtonView.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/otherSrc/HogButtonView.m Thu Apr 22 17:43:12 2010 +0000 @@ -11,11 +11,10 @@ #import "UIImageExtra.h" @implementation HogButtonView -@synthesize singleHog; +@synthesize singleHog, numberOfHogs, ownerDictionary; -(id) initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { - numberOfHogs = 4; self.backgroundColor = [UIColor clearColor]; NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()]; @@ -24,49 +23,42 @@ self.singleHog = normalHogSprite; [normalHogSprite release]; - - [self drawManyHogs]; + [self addTarget:self action:@selector(addOne) forControlEvents:UIControlEventTouchUpInside]; } return self; } --(void) drawManyHogs { - UIImage *teamHogs = [[UIImage alloc] init]; - for (int i = 0; i < numberOfHogs; i++) { - teamHogs = [singleHog mergeWith:teamHogs - atPoint:CGPointMake(8, 0) - atSize:CGSizeMake(88, 32)]; - } - [self setImage:teamHogs forState:UIControlStateNormal]; +-(void) addOne { + self.highlighted = NO; + NSInteger number = self.numberOfHogs; + number++; + [self drawManyHogs:number]; } --(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - UITouch *touch = [touches anyObject]; - - switch ([touch tapCount]) { - case 1: - if (numberOfHogs < MAX_HOGS) { - numberOfHogs++; - } else { +-(void) drawManyHogs:(NSInteger) hogs { + if (numberOfHogs != hogs) { + if (hogs <= MAX_HOGS && hogs >= 1) + numberOfHogs = hogs; + else { + if (hogs > MAX_HOGS) numberOfHogs = 1; - } - break; - case 2: - if (numberOfHogs > 2) { - numberOfHogs--; - numberOfHogs--; - } else { + else numberOfHogs = MAX_HOGS; - } - break; - default: - break; - } - NSLog(@"numberOfHogs: %d", numberOfHogs); - [self drawManyHogs]; + } + [ownerDictionary setObject:[NSNumber numberWithInt:numberOfHogs] forKey:@"number"]; + + UIImage *teamHogs = [[[UIImage alloc] init] autorelease]; + for (int i = 0; i < numberOfHogs; i++) { + teamHogs = [singleHog mergeWith:teamHogs + atPoint:CGPointMake(8, 0) + atSize:CGSizeMake(88, 32)]; + } + [self setImage:teamHogs forState:UIControlStateNormal]; + } } -(void) dealloc { + [ownerDictionary release]; [singleHog release]; [super dealloc]; } diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/otherSrc/SquareButtonView.h --- a/cocoaTouch/otherSrc/SquareButtonView.h Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/otherSrc/SquareButtonView.h Thu Apr 22 17:43:12 2010 +0000 @@ -13,10 +13,14 @@ NSInteger colorIndex; NSUInteger selectedColor; NSArray *colorArray; + NSMutableDictionary *ownerDictionary; } @property (nonatomic,retain) NSArray *colorArray; +@property (nonatomic) NSUInteger selectedColor; +@property (nonatomic,retain) NSMutableDictionary *ownerDictionary; -(void) nextColor; +-(void) selectColor:(NSUInteger) color; @end diff -r bcd6d76db4f7 -r e5403e2bf02c cocoaTouch/otherSrc/SquareButtonView.m --- a/cocoaTouch/otherSrc/SquareButtonView.m Wed Apr 21 21:38:07 2010 +0000 +++ b/cocoaTouch/otherSrc/SquareButtonView.m Thu Apr 22 17:43:12 2010 +0000 @@ -12,14 +12,21 @@ #import "QuartzCore/QuartzCore.h" @implementation SquareButtonView -@synthesize colorArray; +@synthesize colorArray, selectedColor, ownerDictionary; -(id) initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { colorIndex = -1; - + selectedColor = 0; + // list of allowed colors - NSArray *colors = [[NSArray alloc] initWithObjects:[NSNumber numberWithUnsignedInt:4421353], [NSNumber numberWithInt:4100897], nil]; + NSArray *colors = [[NSArray alloc] initWithObjects: [NSNumber numberWithUnsignedInt:4421353], // bluette + [NSNumber numberWithUnsignedInt:4100897], // greeeen + [NSNumber numberWithUnsignedInt:10632635], // violett + [NSNumber numberWithUnsignedInt:16749353], // oranngy + [NSNumber numberWithUnsignedInt:14483456], // reddish + [NSNumber numberWithUnsignedInt:7566195], // graaaay + nil]; self.colorArray = colors; [colors release]; @@ -42,31 +49,42 @@ colorIndex++; if (colorIndex >= [colorArray count]) colorIndex = 0; - + NSUInteger color = [[self.colorArray objectAtIndex:colorIndex] unsignedIntValue]; - selectedColor = color; + [self selectColor:color]; - UIGraphicsBeginImageContext(self.frame.size); - CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextSetRGBFillColor(context, ((color & 0x00FF0000) >> 16)/255.0f, ((color & 0x0000FF00) >> 8)/255.0f, (color & 0x000000FF)/255.0f, 1.0f); - CGContextFillRect(context, CGRectMake(1.1, 1.1, self.frame.size.width-2.2, self.frame.size.height-2.2)); - - UIImageView *resultingImage = [[UIImageView alloc] initWithImage: UIGraphicsGetImageFromCurrentImageContext()]; - UIGraphicsEndImageContext(); - - [self setImage:resultingImage.image forState:UIControlStateNormal]; - [resultingImage release]; + [ownerDictionary setObject:[NSNumber numberWithInt:color] forKey:@"color"]; +} + +-(void) selectColor:(NSUInteger) color { + if (color != selectedColor) { + selectedColor = color; + + UIGraphicsBeginImageContext(self.frame.size); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextSetRGBFillColor(context, ((color & 0x00FF0000) >> 16)/255.0f, + ((color & 0x0000FF00) >> 8)/255.0f, + (color & 0x000000FF)/255.0f, + 1.0f); + CGContextFillRect(context, CGRectMake(1.1, 1.1, self.frame.size.width-2.2, self.frame.size.height-2.2)); + + UIImageView *resultingImage = [[UIImageView alloc] initWithImage: UIGraphicsGetImageFromCurrentImageContext()]; + UIGraphicsEndImageContext(); + + [self setImage:resultingImage.image forState:UIControlStateNormal]; + [resultingImage release]; + + } /* self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f green:((color & 0x0000FF00) >> 8)/255.0f blue: (color & 0x000000FF)/255.0f alpha:1.0f]; */ - NSLog(@"index:%d, color:%d, %@",colorIndex, color, self.backgroundColor); } - -(void) dealloc { + [ownerDictionary release]; [colorArray release]; [super dealloc]; } diff -r bcd6d76db4f7 -r e5403e2bf02c misc/openalbridge/errlib.c --- a/misc/openalbridge/errlib.c Wed Apr 21 21:38:07 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - - module: errlib.c - - purpose: library of error functions - - reference: Stevens, Unix network programming (2ed), p.922 - - */ - -#include "errlib.h" - - -#define MAXLINE 4095 - -int daemon_proc = 0; /* set to 0 if stdout/stderr available, else set to 1 */ - -static void err_doit (int errnoflag, int level, const char *fmt, va_list ap) { - int errno_save = errno, n; - char buf[MAXLINE+1]; - - vsnprintf (buf, MAXLINE, fmt, ap); - n = strlen(buf); - if (errnoflag) - snprintf (buf+n, MAXLINE-n, ": %s", strerror(errno_save)); - strcat (buf, "\n"); - - if (daemon_proc) - syslog (level, buf); - else { - fflush (stdout); - fprintf (stderr, "%s", buf); - fflush (stderr); - } - - return; -} - -void err_ret (const char *fmt, ...) { - va_list ap; - - va_start (ap, fmt); - err_doit (1, LOG_INFO, fmt, ap); - va_end (ap); - return; -} - -void err_sys (const char *fmt, ...) { - va_list ap; - - va_start (ap, fmt); - err_doit (1, LOG_ERR, fmt, ap); - va_end (ap); - exit (1); -} - -void err_msg (const char *fmt, ...) { - va_list ap; - - va_start (ap, fmt); - err_doit (0, LOG_INFO, fmt, ap); - va_end (ap); - return; -} - -void err_quit (const char *fmt, ...) { - va_list ap; - - va_start (ap, fmt); - err_doit (0, LOG_ERR, fmt, ap); - va_end (ap); - exit (1); -} - -void err_dump (const char *fmt, ...) { - va_list ap; - - va_start (ap, fmt); - err_doit (1, LOG_ERR, fmt, ap); - va_end (ap); - abort(); -} diff -r bcd6d76db4f7 -r e5403e2bf02c misc/openalbridge/errlib.h --- a/misc/openalbridge/errlib.h Wed Apr 21 21:38:07 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - - module: errlib.h - - purpose: definitions of function sin errlib.c - - reference: Stevens, Unix network programming (2ed), p.922 - - */ - -#ifndef _ERRLIB_H -#define _ERRLIB_H - -#include "globals.h" - -extern int daemon_proc; - -void err_msg (const char *fmt, ...); -void err_quit (const char *fmt, ...); -void err_ret (const char *fmt, ...); -void err_sys (const char *fmt, ...); -void err_dump (const char *fmt, ...); - -#endif /*_ERRLIB_H*/ - -/* - suggested error string ( PROG ) LEVEL - TEXT : ERRNO - - errno? closeprog? log level - err_msg no no LOG_INFO - err_quit no exit(1) LOG_ERR - err_ret si no LOG_INFO - err_sys si exit(1) LOG_ERR - err_dump si abort( ) LOG_ERR - */ diff -r bcd6d76db4f7 -r e5403e2bf02c misc/openalbridge/globals.h --- a/misc/openalbridge/globals.h Wed Apr 21 21:38:07 2010 +0000 +++ b/misc/openalbridge/globals.h Thu Apr 22 17:43:12 2010 +0000 @@ -21,24 +21,15 @@ #include #include -#include -#include -#include -#include +#include "al.h" #ifndef _WIN32 #include #include #else #include -#define syslog(x,y) fprintf(stderr,y) -#define LOG_INFO 6 -#define LOG_ERR 3 #endif -#include "al.h" -#include "errlib.h" - // control debug verbosity #ifdef TRACE @@ -83,9 +74,9 @@ #ifdef HAVE_BYTESWAP_H #include #else -#define bswap_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8)) -#define bswap_32(x) ((((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | \ -(((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24) ) +#define bswap_16(x) (((x & 0xFF00) >> 8) | ((x & 0x00FF) << 8)) +#define bswap_32(x) (((x & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | \ + ((x & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24) ) #endif /* HAVE_BYTESWAP_H */ /* swap numbers accordingly to architecture automatically */ @@ -102,10 +93,9 @@ #endif /*file format defines*/ -#define OGG_FILE_FORMAT 0x4F676753 -#define WAV_FILE_FORMAT 0x52494646 -#define WAV_HEADER_SUBCHUNK2ID 0x64617461 +#define OGG_FILE_FORMAT 0x4F676753 +#define WAV_FILE_FORMAT 0x52494646 +#define WAV_HEADER_SUBCHUNK2ID 0x64617461 -char *prog = "OpenAL subsystem"; #endif /*_OALB_GLOBALS_H*/ diff -r bcd6d76db4f7 -r e5403e2bf02c misc/openalbridge/loaders.c --- a/misc/openalbridge/loaders.c Wed Apr 21 21:38:07 2010 +0000 +++ b/misc/openalbridge/loaders.c Thu Apr 22 17:43:12 2010 +0000 @@ -21,6 +21,7 @@ #include "vorbis/vorbisfile.h" #include "openalbridge_t.h" + int load_wavpcm (const char *filename, ALenum *format, char ** data, ALsizei *bitsize, ALsizei *freq) { WAV_header_t WAVHeader; FILE *wavfile; @@ -78,10 +79,9 @@ } if (t <= 0) { - /*eof*/ - errno = EILSEQ; - err_ret("(%s) ERROR - wrong WAV header", prog); - return AL_FALSE; + // eof + fprintf(stderr,"(Bridge Error) - wrong WAV header"); + return -1; } } while (1); @@ -102,7 +102,7 @@ fclose(wavfile); #ifdef DEBUG - err_msg("(%s) INFO - WAV data loaded", prog); + fprintf(stderr,"(Bridge Info) - WAV data loaded"); #endif /*set parameters for OpenAL*/ @@ -114,9 +114,8 @@ if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 16) *format = AL_FORMAT_MONO16; else { - errno = EILSEQ; - err_ret("(%s) ERROR - wrong WAV header [bitsample value]", prog); - return AL_FALSE; + fprintf(stderr,"(Bridge Error) - wrong WAV header [bitsample value]"); + return -2; } } } else { @@ -127,21 +126,19 @@ if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 16) *format = AL_FORMAT_STEREO16; else { - errno = EILSEQ; - err_ret("(%s) ERROR - wrong WAV header [bitsample value]", prog); - return AL_FALSE; + fprintf(stderr,"(Bridge Error) - wrong WAV header [bitsample value]"); + return -2; } } } else { - errno = EILSEQ; - err_ret("(%s) ERROR - wrong WAV header [format value]", prog); - return AL_FALSE; + fprintf(stderr,"(Bridge Error) - wrong WAV header [format value]"); + return -2; } } *bitsize = ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size); *freq = ENDIAN_LITTLE_32(WAVHeader.SampleRate); - return AL_TRUE; + return 0; } @@ -167,8 +164,7 @@ oggFile = Fopen(filename, "rb"); result = ov_open_callbacks(oggFile, &oggStream, NULL, 0, OV_CALLBACKS_DEFAULT); if (result < 0) { - errno = EINVAL; - err_ret("(%s) ERROR - ov_fopen() failed with %X", prog, result); + fprintf(stderr,"(Bridge Error) - ov_open_callbacks() failed with %X", result); ov_clear(&oggStream); return -1; } @@ -203,10 +199,9 @@ if (vorbisInfo->channels == 2) *format = AL_FORMAT_STEREO16; else { - errno = EILSEQ; - err_ret("(%s) ERROR - wrong OGG header [channel %d]", prog, vorbisInfo->channels); + fprintf(stderr,"(Bridge Error) - wrong OGG header [channel %d]", vorbisInfo->channels); ov_clear(&oggStream); - return -1; + return -2; } } @@ -225,10 +220,9 @@ if (result == 0) break; else { - errno = EILSEQ; - err_ret("(%s) ERROR - End of file from OGG stream", prog); + fprintf(stderr,"(Bridge Error) - End of file from OGG stream"); ov_clear(&oggStream); - return -1; + return -3; } } } diff -r bcd6d76db4f7 -r e5403e2bf02c misc/openalbridge/openalbridge.c --- a/misc/openalbridge/openalbridge.c Wed Apr 21 21:38:07 2010 +0000 +++ b/misc/openalbridge/openalbridge.c Thu Apr 22 17:43:12 2010 +0000 @@ -18,8 +18,9 @@ #include "openalbridge.h" #include "globals.h" +#include "al.h" +#include "alc.h" #include "wrappers.h" -#include "alc.h" #include "loaders.h" @@ -30,75 +31,74 @@ /*index for Sources and Buffers*/ ALuint globalindex, globalsize, increment; -ALboolean openalReady = AL_FALSE; +ALboolean isBridgeReady = AL_FALSE; ALfloat old_gain; -int openal_init(int memorysize) { +int openal_init (int memorysize) { /*Initialize an OpenAL contex and allocate memory space for data and buffers*/ ALCcontext *context; ALCdevice *device; - + // set the memory dimentsion and the increment width when reallocating if (memorysize <= 0) globalsize = 50; else globalsize = memorysize; increment = globalsize; - + // reuse old context but keep the new value for increment - if (openalReady == AL_TRUE) { - err_msg("(%s) WARN - already initialized", prog); + if (isBridgeReady == AL_TRUE) { + fprintf(stderr,"(Bridge Warning) - already initialized"); return 0; } - + // open hardware device if present device = alcOpenDevice(NULL); - + if (device == NULL) { - errno = ENODEV; - err_ret("(%s) WARN - failed to open sound device, using software renderer", prog); + fprintf(stderr,"(Bridge Warning) - failed to open sound device, using software renderer"); device = alcOpenDevice("Generic Software"); if (device == NULL) { - err_ret("(%s) ERROR - failed to open sound software device, sound will be disabled", prog); + fprintf(stderr,"(Bridge Error) - failed to open sound software device, sound will be disabled"); return -1; } } - - err_msg("(%s) INFO - Output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); - + + fprintf(stderr,"(Bridge Info) - Output device: %s", alcGetString(device, ALC_DEVICE_SPECIFIER)); + context = alcCreateContext(device, NULL); alcMakeContextCurrent(context); alcProcessContext(context); - + if (AL_NO_ERROR != alGetError()) { - err_msg("(%s) ERROR - Failed to create a new contex",prog); + fprintf(stderr,"(Bridge Error) - Failed to create a new contex"); alcMakeContextCurrent(NULL); alcDestroyContext(context); alcCloseDevice(device); return -2; } - + // allocate memory space for buffers and sources Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); - + // set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation // Position, Velocity and Orientation of the listener ALfloat ListenerPos[] = {0.0, 0.0, 0.0}; ALfloat ListenerVel[] = {0.0, 0.0, 0.0}; ALfloat ListenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; - + alListenerf (AL_GAIN, 1.0f ); alListenerfv(AL_POSITION, ListenerPos); alListenerfv(AL_VELOCITY, ListenerVel); alListenerfv(AL_ORIENTATION, ListenerOri); - + if (AL_NO_ERROR != alGetError()) { - err_msg("(%s) ERROR - Failed to set Listener properties",prog); + fprintf(stderr,"(Bridge Error) - Failed to set Listener properties"); return -3; } - openalReady = AL_TRUE; - + isBridgeReady = AL_TRUE; + alGetError(); // clear any AL errors beforehand return AL_TRUE; } @@ -107,36 +107,35 @@ /*Stop all sounds, deallocate all memory and close OpenAL */ ALCcontext *context; ALCdevice *device; - - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); + + if (isBridgeReady == AL_FALSE) { + fprintf(stderr,"(Bridge Warning) - OpenAL not initialized"); return; } - + alSourceStopv (globalsize, Sources); alDeleteSources (globalsize, Sources); alDeleteBuffers (globalsize, Buffers); - + free(Sources); free(Buffers); - + context = alcGetCurrentContext(); device = alcGetContextsDevice(context); - + alcMakeContextCurrent(NULL); alcDestroyContext(context); alcCloseDevice(device); - - openalReady = AL_FALSE; - - err_msg("(%s) INFO - closed", prog); - + + isBridgeReady = AL_FALSE; + + fprintf(stderr,"(Bridge Info) - closed"); + return; } -ALboolean openal_ready(void) { - return openalReady; +ALboolean openal_ready (void) { + return isBridgeReady; } @@ -144,12 +143,12 @@ /*expands allocated memory when loading more sound files than expected*/ int oldsize = globalsize; globalsize += increment; - - err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize); - + + fprintf(stderr,"(Bridge Info) - Realloc in process from %d to %d\n", oldsize, globalsize); + Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); - + return; } @@ -164,46 +163,46 @@ uint32_t fileformat; ALenum error; FILE *fp; - - if (openalReady == AL_FALSE) { - err_msg("(%s) WARN - not initialized", prog); + + if (isBridgeReady == AL_FALSE) { + fprintf(stderr,"(Bridge Warning) - not initialized"); return -1; } - + /*when the buffers are all used, we can expand memory to accept new files*/ if (globalindex == globalsize) helper_realloc(); - + /*detect the file format, as written in the first 4 bytes of the header*/ fp = Fopen (filename, "rb"); - + if (fp == NULL) return -2; - + error = fread (&fileformat, sizeof(uint32_t), 1, fp); fclose (fp); - + if (error < 0) { - err_msg("(%s) ERROR - File %s is too short", prog, filename); + fprintf(stderr,"(Bridge Error) - File %s is too short", filename); return -3; } - + /*prepare the buffer to receive data*/ alGenBuffers(1, &Buffers[globalindex]); - + if (AL_NO_ERROR != alGetError()) { - err_msg("(%s) ERROR - Failed to allocate memory for buffers",prog); + fprintf(stderr,"(Bridge Error) - Failed to allocate memory for buffers"); return -4; } - + /*prepare the source to emit sound*/ alGenSources(1, &Sources[globalindex]); - + if (AL_NO_ERROR != alGetError()) { - err_msg("(%s) ERROR - Failed to allocate memory for sources",prog); + fprintf(stderr,"(Bridge Error) - Failed to allocate memory for sources"); return -5; } - + switch (ENDIAN_BIG_32(fileformat)) { case OGG_FILE_FORMAT: error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); @@ -212,21 +211,26 @@ error = load_wavpcm (filename, &format, &data, &bitsize, &freq); break; default: - err_msg ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat)); + fprintf(stderr,"(Bridge Error) - File format (%08X) not supported", ENDIAN_BIG_32(fileformat)); return -6; break; } - - + + if (error != 0) { + fprintf(stderr,"(Bridge Error) - error loading file %s", filename); + free(data); + return -7; + } + //copy pcm data in one buffer and free it alBufferData(Buffers[globalindex], format, data, bitsize, freq); free(data); - + if (AL_NO_ERROR != alGetError()) { - err_msg("(%s) ERROR - Failed to write data to buffers",prog); - return -6; + fprintf(stderr,"(Bridge Error) - Failed to write data to buffers"); + return -8; } - + /*set source properties that it will use when it's in playback*/ alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] ); alSourcef (Sources[globalindex], AL_PITCH, 1.0f ); @@ -234,14 +238,14 @@ alSourcefv(Sources[globalindex], AL_POSITION, SourcePos ); alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel ); alSourcei (Sources[globalindex], AL_LOOPING, 0 ); - + if (AL_NO_ERROR != alGetError()) { - err_msg("(%s) ERROR - Failed to set Source properties",prog); - return -7; + fprintf(stderr,"(Bridge Error) - Failed to set Source properties"); + return -9; } - + alGetError(); /* clear any AL errors beforehand */ - + /*returns the index of the source you just loaded, increments it and exits*/ return globalindex++; } @@ -253,7 +257,7 @@ void openal_pausesound (uint32_t index) { - if (openalReady == AL_TRUE && index < globalsize) + if (isBridgeReady == AL_TRUE && index < globalsize) alSourcePause(Sources[index]); } @@ -264,63 +268,63 @@ void openal_freesound (uint32_t index){ - if (openalReady == AL_TRUE && index < globalsize) + if (isBridgeReady == AL_TRUE && index < globalsize) alSourceStop(Sources[index]); - // STUB + // STUB } void openal_playsound_loop (unsigned int index, char loops) { -if (openalReady == AL_TRUE && index < globalsize) { + if (isBridgeReady == AL_TRUE && index < globalsize) { alSourcePlay(Sources[index]); - if (loops != 0) + if (loops != 0) openal_toggleloop(index); } } -void openal_stopsound_free (unsigned int index, char freesource) { - if (openalReady == AL_TRUE && index < globalsize) { +void openal_stopsound_free (unsigned int index, char freesource) { + if (isBridgeReady == AL_TRUE && index < globalsize) { alSourceStop(Sources[index]); - if (freesource != 0) - openal_freesound(index); + if (freesource != 0) + openal_freesound(index); } } void openal_toggleloop (uint32_t index) { ALint loop; - - if (openalReady == AL_TRUE && index < globalsize) { + + if (isBridgeReady == AL_TRUE && index < globalsize) { alGetSourcei (Sources[index], AL_LOOPING, &loop); alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); } - + } void openal_setvolume (uint32_t index, float gain) { - if (openalReady == AL_TRUE && index < globalsize) + if (isBridgeReady == AL_TRUE && index < globalsize) alSourcef (Sources[index], AL_GAIN, gain); } void openal_setglobalvolume (float gain) { - if (openalReady == AL_TRUE) + if (isBridgeReady == AL_TRUE) alListenerf (AL_GAIN, gain); } void openal_togglemute () { ALfloat gain; - - if (openalReady == AL_TRUE) { + + if (isBridgeReady == AL_TRUE) { alGetListenerf (AL_GAIN, &gain); if (gain > 0) { - old_gain = gain; + old_gain = gain; gain = 0; - } else + } else gain = old_gain; - - alListenerf (AL_GAIN, gain); -} + + alListenerf (AL_GAIN, gain); + } } // Fade in or out by calling a helper thread @@ -331,13 +335,13 @@ HANDLE Thread; #endif fade_t *fade; - - if (openalReady == AL_TRUE && index < globalsize) { + + if (isBridgeReady == AL_TRUE && index < globalsize) { fade = (fade_t*) Malloc(sizeof(fade_t)); fade->index = index; fade->quantity = quantity; fade->type = direction; - + #ifndef _WIN32 pthread_create(&thread, NULL, (void *)helper_fade, (void *)fade); pthread_detach(thread); @@ -357,6 +361,6 @@ void openal_setposition (uint32_t index, float x, float y, float z) { - if (openalReady == AL_TRUE && index < globalsize) + if (isBridgeReady == AL_TRUE && index < globalsize) alSource3f(Sources[index], AL_POSITION, x, y, z);; } diff -r bcd6d76db4f7 -r e5403e2bf02c misc/openalbridge/wrappers.c --- a/misc/openalbridge/wrappers.c Wed Apr 21 21:38:07 2010 +0000 +++ b/misc/openalbridge/wrappers.c Thu Apr 22 17:43:12 2010 +0000 @@ -24,9 +24,11 @@ void *Malloc (size_t nbytes) { void *aptr; - if ((aptr = malloc(nbytes)) == NULL) - err_dump("(%s) FATAL - not enough memory"); - + if ((aptr = malloc(nbytes)) == NULL) { + fprintf(stderr,"(Bridge Fatal Error) - not enough memory"); + abort(); + } + return aptr; } @@ -34,8 +36,10 @@ void *Realloc (void *aptr, size_t nbytes) { aptr = realloc(aptr, nbytes); - if (aptr == NULL) - err_dump("(%s) FATAL - not enough memory"); + if (aptr == NULL) { + fprintf(stderr,"(Bridge Fatal Error) - not enough memory"); + abort(); + } return aptr; } @@ -46,7 +50,7 @@ fp = fopen(fname,mode); if (fp == NULL) - err_ret("(%s) ERROR - can't open file %s in mode '%s'", prog, fname, mode); + fprintf(stderr,"(Bridge Error) - can't open file %s in mode '%s'", fname, mode); return fp; } @@ -97,7 +101,7 @@ } if (AL_NO_ERROR != alGetError()) - err_msg("(%s) WARN - Failed to set fade-out effect",prog); + fprintf(stderr,"(Bridge Warning) - Failed to set fade-out effect"); // stop that sound and reset its volume alSourceStop (Sources[index]); @@ -105,7 +109,7 @@ } if (AL_NO_ERROR != alGetError()) - err_msg("(%s) WARN - Failed to set fade effect",prog); + fprintf(stderr,"(Bridge Warning) - Failed to set fade effect"); #ifndef _WIN32 pthread_exit(NULL); diff -r bcd6d76db4f7 -r e5403e2bf02c project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj/project.pbxproj --- a/project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj/project.pbxproj Wed Apr 21 21:38:07 2010 +0000 +++ b/project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj/project.pbxproj Thu Apr 22 17:43:12 2010 +0000 @@ -129,8 +129,7 @@ 61A11AD61168DB3700359010 /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A11AD51168DB3700359010 /* DetailViewController.m */; }; 61A11AE11168DC6E00359010 /* SingleTeamViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A11AE01168DC6E00359010 /* SingleTeamViewController.m */; }; 61A11AE41168DC9400359010 /* HogHatViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A11AE31168DC9400359010 /* HogHatViewController.m */; }; - 61C325431179A336001E70B1 /* errlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 61C325391179A336001E70B1 /* errlib.c */; }; - 61C325441179A336001E70B1 /* errlib.h in Headers */ = {isa = PBXBuildFile; fileRef = 61C3253A1179A336001E70B1 /* errlib.h */; }; + 61AA7ACA117FCC8200FDDD4D /* openalbridge_t.h in Headers */ = {isa = PBXBuildFile; fileRef = 61AA7AC9117FCC8200FDDD4D /* openalbridge_t.h */; }; 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 */; }; @@ -354,9 +353,8 @@ 61A11AE01168DC6E00359010 /* SingleTeamViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SingleTeamViewController.m; path = ../../cocoaTouch/SingleTeamViewController.m; sourceTree = SOURCE_ROOT; }; 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; }; 61C3251D1179A300001E70B1 /* libopenalbridge.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libopenalbridge.a; sourceTree = BUILT_PRODUCTS_DIR; }; - 61C325391179A336001E70B1 /* errlib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = errlib.c; path = ../../misc/openalbridge/errlib.c; sourceTree = SOURCE_ROOT; }; - 61C3253A1179A336001E70B1 /* errlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = errlib.h; path = ../../misc/openalbridge/errlib.h; sourceTree = SOURCE_ROOT; }; 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; }; 61C3253D1179A336001E70B1 /* loaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = loaders.h; path = ../../misc/openalbridge/loaders.h; sourceTree = SOURCE_ROOT; }; @@ -722,8 +720,7 @@ 61C325371179A325001E70B1 /* openalbridge */ = { isa = PBXGroup; children = ( - 61C325391179A336001E70B1 /* errlib.c */, - 61C3253A1179A336001E70B1 /* errlib.h */, + 61AA7AC9117FCC8200FDDD4D /* openalbridge_t.h */, 61C3253B1179A336001E70B1 /* globals.h */, 61C3253C1179A336001E70B1 /* loaders.c */, 61C3253D1179A336001E70B1 /* loaders.h */, @@ -784,11 +781,11 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 61C325441179A336001E70B1 /* errlib.h in Headers */, 61C325451179A336001E70B1 /* globals.h in Headers */, 61C325471179A336001E70B1 /* loaders.h in Headers */, 61C325491179A336001E70B1 /* openalbridge.h in Headers */, 61C3254B1179A336001E70B1 /* wrappers.h in Headers */, + 61AA7ACA117FCC8200FDDD4D /* openalbridge_t.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1096,7 +1093,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 61C325431179A336001E70B1 /* errlib.c in Sources */, 61C325461179A336001E70B1 /* loaders.c in Sources */, 61C325481179A336001E70B1 /* openalbridge.c in Sources */, 61C3254A1179A336001E70B1 /* wrappers.c in Sources */,