cocoaTouch/GameSetup.m
author koda
Sat, 16 Jan 2010 06:48:56 +0000
changeset 2697 75880595a9f1
parent 2696 41aa7b56c17b
child 2698 90585aba87ad
permissions -rw-r--r--
code cleanup and opengles optimizations
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
     1
//
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
     2
//  gameSetup.m
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
     3
//  hwengine
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
     4
//
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
     5
//  Created by Vittorio on 10/01/10.
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
     7
//
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
     8
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
     9
#import "GameSetup.h"
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    10
#import "SDL_uikitappdelegate.h"
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    11
#import "SDL_net.h"
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    12
#import "PascalImports.h"
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    13
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    14
#define BUFFER_SIZE 256
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    15
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    16
@implementation GameSetup
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    17
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
    18
@synthesize localeString, systemSettings;
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    19
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    20
-(id) init {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    21
	self = [super init];
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
    22
	self.localeString = [[[NSLocale currentLocale] localeIdentifier] stringByAppendingString:@".txt"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
    23
	self.systemSettings = nil;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
    24
	engineProtocolStarted = NO;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
    25
	ipcPort = 51342;
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    26
	return self;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    27
}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    28
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    29
-(void) dealloc {
2697
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
    30
	if (systemSettings) [self.systemSettings release];
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    31
	[self.localeString autorelease];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    32
	[super dealloc];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    33
}
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    34
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    35
#pragma mark -
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    36
#pragma mark Thread/Network relevant code
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    37
-(void) startThread: (NSString *) selector {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    38
	SEL usage = NSSelectorFromString(selector);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    39
	
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    40
	// do not start the server thread because the port is already bound
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    41
	if (NO == engineProtocolStarted) {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    42
		engineProtocolStarted = YES;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    43
		[NSThread detachNewThreadSelector:usage toTarget:self withObject:nil];
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    44
	}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    45
}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    46
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    47
-(int) sendToEngine: (NSString *)string {
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    48
	Uint8 length = [string length];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    49
	
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    50
	SDLNet_TCP_Send(csd, &length , 1);
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    51
	return SDLNet_TCP_Send(csd, [string UTF8String], length);
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    52
}
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    53
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    54
-(void) engineProtocol {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    55
	IPaddress ip;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    56
	int idx, eProto;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    57
	BOOL serverQuit, clientQuit;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    58
	char buffer[BUFFER_SIZE], string[BUFFER_SIZE];
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    59
	Uint8 msgSize;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    60
	Uint16 gameTicks;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    61
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    62
	
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    63
	if (SDLNet_Init() < 0) {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    64
		fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    65
		exit(EXIT_FAILURE);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    66
	}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    67
	
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    68
	/* Resolving the host using NULL make network interface to listen */
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
    69
	if (SDLNet_ResolveHost(&ip, NULL, ipcPort) < 0) {
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    70
		fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    71
		exit(EXIT_FAILURE);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    72
	}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    73
	
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    74
	/* Open a connection with the IP provided (listen on the host's port) */
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    75
	if (!(sd = SDLNet_TCP_Open(&ip))) {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    76
		fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    77
		exit(EXIT_FAILURE);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    78
	}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    79
	
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    80
	NSLog(@"engineProtocol - Waiting for a client");
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    81
	
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    82
	serverQuit = NO;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    83
	while (!serverQuit) {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    84
		
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    85
		/* This check the sd if there is a pending connection.
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    86
		 * If there is one, accept that, and open a new socket for communicating */
2697
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
    87
		csd = SDLNet_TCP_Accept(sd);
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
    88
		if (NULL != csd) {
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    89
			
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    90
			NSLog(@"engineProtocol - Client found");
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    91
			
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    92
			//first byte of the command alwayas contain the size of the command
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    93
			SDLNet_TCP_Recv(csd, &msgSize, sizeof(Uint8));
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    94
			
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    95
			SDLNet_TCP_Recv(csd, buffer, msgSize);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    96
			gameTicks = SDLNet_Read16(&buffer[msgSize - 2]);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    97
			//NSLog(@"engineProtocol - %d: received [%s]", gameTicks, buffer);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    98
			
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
    99
			if ('C' == buffer[0]) {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   100
				NSLog(@"engineProtocol - sending game config");
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   101
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   102
				// send config data data
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   103
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   104
				// local game
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   105
				[self sendToEngine:@"TL"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   106
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   107
				// seed info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   108
				[self sendToEngine:@"eseed {232c1b42-7d39-4ee6-adf8-4240e1f1efb8}"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   109
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   110
				// various flags
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   111
				[self sendToEngine:@"e$gmflags 256"]; 
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   112
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   113
				// various flags
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   114
				[self sendToEngine:@"e$damagepct 100"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   115
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   116
				// various flags
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   117
				[self sendToEngine:@"e$turntime 45000"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   118
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   119
				// various flags
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   120
				[self sendToEngine:@"e$minestime 3000"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   121
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   122
				// various flags
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   123
				[self sendToEngine:@"e$landadds 4"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   124
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   125
				// various flags
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   126
				[self sendToEngine:@"e$sd_turns 15"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   127
												
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   128
				// various flags
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   129
				[self sendToEngine:@"e$casefreq 5"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   130
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   131
				// various flags
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   132
				[self sendToEngine:@"e$template_filter 1"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   133
								
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   134
				// theme info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   135
				[self sendToEngine:@"etheme Freeway"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   136
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   137
				// team 1 info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   138
				[self sendToEngine:@"eaddteam 4421353 System Cats"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   139
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   140
				// team 1 grave info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   141
				[self sendToEngine:@"egrave star"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   142
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   143
				// team 1 fort info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   144
				[self sendToEngine:@"efort  Earth"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   145
								
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   146
				// team 1 voicepack info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   147
				[self sendToEngine:@"evoicepack Classic"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   148
				
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   149
				// team 1 binds (skipped)			
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   150
				// team 1 members info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   151
				[self sendToEngine:@"eaddhh 0 100 Snow Leopard"];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   152
				[self sendToEngine:@"ehat NoHat"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   153
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   154
				// team 1 ammostore
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   155
				[self sendToEngine:@"eammstore 93919294221991210322351110012010000002110404000441400444645644444774776112211144"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   156
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   157
				// team 2 info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   158
				[self sendToEngine:@"eaddteam 4100897 Poke-MAN"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   159
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   160
				// team 2 grave info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   161
				[self sendToEngine:@"egrave Badger"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   162
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   163
				// team 2 fort info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   164
				[self sendToEngine:@"efort UFO"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   165
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   166
				// team 2 voicepack info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   167
				[self sendToEngine:@"evoicepack Classic"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   168
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   169
				// team 2 binds (skipped)
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   170
				// team 2 members info
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   171
				[self sendToEngine:@"eaddhh 0 100 Raichu"];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   172
				[self sendToEngine:@"ehat Bunny"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   173
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   174
				// team 2 ammostore
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   175
				[self sendToEngine:@"eammstore 93919294221991210322351110012010000002110404000441400444645644444774776112211144"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   176
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   177
				clientQuit = NO;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   178
			} else {
2697
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
   179
				NSLog(@"engineProtocolThread - wrong message or client closed connection");
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   180
				clientQuit = YES;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   181
			}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   182
			
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   183
			while (!clientQuit){
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   184
				/* Now we can communicate with the client using csd socket
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   185
				 * sd will remain opened waiting other connections */
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   186
				idx = 0;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   187
				msgSize = 0;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   188
				memset(buffer, 0, BUFFER_SIZE);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   189
				memset(string, 0, BUFFER_SIZE);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   190
				if (SDLNet_TCP_Recv(csd, &msgSize, sizeof(Uint8)) <= 0)
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   191
					clientQuit = YES;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   192
				if (SDLNet_TCP_Recv(csd, buffer, msgSize) <=0)
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   193
					clientQuit = YES;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   194
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   195
				gameTicks = SDLNet_Read16(&buffer[msgSize - 2]);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   196
				//NSLog(@"engineProtocolThread - %d: received [%s]", gameTicks, buffer);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   197
				
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   198
				switch (buffer[0]) {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   199
					case '?':
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   200
						NSLog(@"Ping? Pong!");
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   201
						[self sendToEngine:@"!"];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   202
						break;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   203
					case 'E':
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   204
						NSLog(@"ERROR - last console line: [%s]", buffer);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   205
						clientQuit = YES;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   206
						break;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   207
					case 'e':
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   208
						sscanf(buffer, "%*s %d", &eProto);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   209
						if (HW_protoVer() == eProto) {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   210
							NSLog(@"Setting protocol version %s", buffer);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   211
						} else {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   212
							NSLog(@"ERROR - wrong protocol number: [%s] - expecting %d", buffer, eProto);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   213
							clientQuit = YES;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   214
						}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   215
						break;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   216
					case 'i':
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   217
						switch (buffer[1]) {
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   218
							case 'r':
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   219
								NSLog(@"Winning team: %s", &buffer[2]);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   220
								break;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   221
							case 'k':
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   222
								NSLog(@"Best Hedgehog: %s", &buffer[2]);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   223
								break;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   224
						}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   225
						break;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   226
					default:
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   227
						// empty packet or just statistics
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   228
						break;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   229
					// missing case for exiting right away
2697
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
   230
				}
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   231
			}
2697
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
   232
			NSLog(@"Client Exited");
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
   233
			// wait a little to let the client close cleanly
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
   234
			sleep(5);
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
   235
			// Close the client socket
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
   236
			SDLNet_TCP_Close(csd);
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   237
		}
2697
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
   238
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   239
	}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   240
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   241
	SDLNet_TCP_Close(sd);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   242
	SDLNet_Quit();
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   243
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   244
	[pool release];
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   245
	[NSThread exit];
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   246
}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   247
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   248
#pragma mark -
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   249
#pragma mark Settings setup methods
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   250
-(void) loadSettingsFromFile:(NSString *)fileName forKey:(NSString *)objName {
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   251
	NSString *filePath = [SDLUIKitDelegate dataFilePath:fileName];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   252
	
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   253
	if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {	
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   254
		NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:filePath];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   255
		[self setValue:dict forKey:objName];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   256
		[dict release];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   257
	} else {
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   258
		//TODO create it
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   259
		[NSException raise:@"File NOT found" format:@"The file %@ was not found at %@", fileName, filePath];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   260
	}
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   261
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   262
}
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   263
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   264
-(void) unloadSettings {
2697
75880595a9f1 code cleanup and opengles optimizations
koda
parents: 2696
diff changeset
   265
	[systemSettings dealloc];
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   266
}
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   267
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   268
-(void) setArgsForLocalPlay {
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   269
	NSString *portNumber = [[NSString alloc] initWithFormat:@"%d", ipcPort];
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   270
	//NSString *username = [[NSString alloc] initWithString:[systemSettings objectForKey:@"username"]];
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   271
	/*for (NSString *theString in [NSLocale ISOLanguageCodes]) {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   272
		NSLog(theString);
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   273
	}*/
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   274
	
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   275
	memset(forward_argv, 0, forward_argc);
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   276
	
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   277
	forward_argc = 18;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   278
	forward_argv = (char **)realloc(forward_argv, forward_argc * sizeof(char *));
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   279
	//forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   280
	forward_argv[ 1] = forward_argv[0];					// (UNUSED)
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   281
	forward_argv[ 2] = "320";							// cScreenWidth
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   282
	forward_argv[ 3] = "480";							// cScreenHeight
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   283
	forward_argv[ 4] = "16";							// cBitsStr
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   284
	forward_argv[ 5] = [portNumber UTF8String];			// ipcPort;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   285
	forward_argv[ 6] = "1";								// cFullScreen (NO EFFECT)
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   286
	forward_argv[ 7] = [[systemSettings objectForKey:@"effects"] UTF8String];	// isSoundEnabled
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   287
	forward_argv[ 8] = "1";								// cVSyncInUse (UNUSED)
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   288
	forward_argv[ 9] = [localeString UTF8String];		// cLocaleFName
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   289
	forward_argv[10] = [[systemSettings objectForKey:@"volume"] UTF8String];	// cInitVolume
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   290
	forward_argv[11] = "8";								// cTimerInterval
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   291
	forward_argv[12] = "Data";							// PathPrefix
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   292
	forward_argv[13] = "1";								// cShowFPS (TOSET?)
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   293
	forward_argv[14] = [[systemSettings objectForKey:@"alternate"] UTF8String];	// cAltDamage (TOSET)
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   294
	forward_argv[15] = "Koda";				// UserNick (DecodeBase64(ParamStr(15)) FTW) <- TODO
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   295
	forward_argv[16] = [[systemSettings objectForKey:@"music"] UTF8String];		// isMusicEnabled
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   296
	forward_argv[17] = "0";								// cReducedQuality
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   297
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   298
	[portNumber release];
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   299
	return;
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   300
}
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   301
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   302
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   303
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2693
diff changeset
   304
2693
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   305
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   306
3207e0eacd43 GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff changeset
   307
@end