author | smxx |
Fri, 16 Apr 2010 16:04:41 +0000 | |
changeset 3350 | 5cd02aafc612 |
parent 3349 | 5571592f10a8 |
child 3356 | 3ae3fccb439e |
permissions | -rw-r--r-- |
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 |
|
3335 | 9 |
#include <sys/types.h> |
10 |
#include <sys/sysctl.h> |
|
11 |
||
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
|
12 |
#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
|
13 |
#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
|
14 |
#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
|
15 |
#import "PascalImports.h" |
3335 | 16 |
#import "CommodityFunctions.h" |
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
|
17 |
|
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
|
18 |
#define BUFFER_SIZE 256 |
3221 | 19 |
#define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]); |
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
|
20 |
|
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 |
@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
|
22 |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
23 |
@synthesize systemSettings, teams; |
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
|
24 |
|
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
|
25 |
-(id) init { |
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
26 |
if (self = [super init]) { |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
27 |
srandom(time(NULL)); |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
28 |
ipcPort = (random() % 64541) + 1025; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
29 |
|
3335 | 30 |
systemSettings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; //should check it exists |
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
31 |
return self; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
32 |
} else |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
33 |
return nil; |
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
|
34 |
} |
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
|
35 |
|
3221 | 36 |
-(NSString *)description { |
37 |
return [NSString stringWithFormat:@"ipcport: %d\nsockets: %d,%d\n teams: %@\n systemSettings: %@",ipcPort,sd,csd,teams,systemSettings]; |
|
38 |
} |
|
39 |
||
2696 | 40 |
-(void) dealloc { |
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
41 |
[teams release]; |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
42 |
[systemSettings release]; |
2696 | 43 |
[super dealloc]; |
44 |
} |
|
45 |
||
46 |
#pragma mark - |
|
47 |
#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
|
48 |
-(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
|
49 |
SEL usage = NSSelectorFromString(selector); |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
50 |
[NSThread detachNewThreadSelector:usage toTarget:self withObject:nil]; |
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
|
51 |
} |
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
|
52 |
|
2696 | 53 |
-(int) sendToEngine: (NSString *)string { |
3199 | 54 |
unsigned char length = [string length]; |
2696 | 55 |
|
56 |
SDLNet_TCP_Send(csd, &length , 1); |
|
57 |
return SDLNet_TCP_Send(csd, [string UTF8String], length); |
|
58 |
} |
|
59 |
||
3199 | 60 |
-(void) initTeam:(NSArray *)teamLists { |
61 |
teams = [[NSMutableArray alloc] initWithObjects:nil]; |
|
62 |
||
63 |
for (NSString *teamString in teamLists) { |
|
64 |
//NSString *teamFile = [[NSString alloc] initWithFormat:@"%@.plist", teamString]; |
|
65 |
||
66 |
//NSDictionary *theTeam = [[NSDictionary alloc] initWithContentsOfFile:filePath]; |
|
67 |
//[teams addObject:theTeam]; |
|
68 |
//[theTeam release]; |
|
69 |
} |
|
70 |
||
71 |
NSDictionary *hogA1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Snow Leopard",@"hogname",@"NoHat",@"hat",nil]; |
|
72 |
NSDictionary *hogA2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Leopard",@"hogname",@"NoHat",@"hat",nil]; |
|
73 |
NSArray *hedgehogs1 = [[NSArray alloc] initWithObjects:hogA1,hogA2,nil]; |
|
74 |
[hogA1 release]; |
|
75 |
[hogA2 release]; |
|
3349 | 76 |
|
3199 | 77 |
NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash",@"System Cats",@"teamname", |
78 |
@"star",@"grave",@"Earth",@"fort",@"Classic",@"voicepack",@"hedgewars",@"flag",hedgehogs1,@"hedgehogs", |
|
3349 | 79 |
nil]; |
3199 | 80 |
[hedgehogs1 release]; |
81 |
[teams addObject:firstTeam]; |
|
82 |
[firstTeam release]; |
|
83 |
||
84 |
NSDictionary *hogB1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Raichu",@"hogname",@"Bunny",@"hat",nil]; |
|
85 |
NSDictionary *hogB2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Pikachu",@"hogname",@"Bunny",@"hat",nil]; |
|
86 |
NSArray *hedgehogs2 = [[NSArray alloc] initWithObjects:hogB1,hogB2,nil]; |
|
87 |
[hogB1 release]; |
|
88 |
[hogB2 release]; |
|
89 |
NSDictionary *secondTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4100897",@"color",@"0",@"hash",@"Poke-MAN",@"teamname", |
|
90 |
@"Badger",@"grave",@"UFO",@"fort",@"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs2,@"hedgehogs", |
|
3349 | 91 |
nil]; |
3199 | 92 |
[hedgehogs2 release]; |
93 |
[teams addObject:secondTeam]; |
|
94 |
[secondTeam release]; |
|
95 |
} |
|
96 |
||
97 |
-(void) sendTeamData:(NSDictionary *)teamData withPlayingHogs:(int) playingHogs{ |
|
98 |
int i; |
|
99 |
||
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
100 |
NSString *teamHashColorAndName = [[NSString alloc] initWithFormat:@"eaddteam %@ %@ %@", [teamData objectForKey:@"hash"], [teamData objectForKey:@"color"], [teamData objectForKey:@"teamname"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
101 |
[self sendToEngine: teamHashColorAndName]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
102 |
[teamHashColorAndName release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
103 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
104 |
NSString *grave = [[NSString alloc] initWithFormat:@"egrave %@", [teamData objectForKey:@"grave"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
105 |
[self sendToEngine: grave]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
106 |
[grave release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
107 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
108 |
NSString *fort = [[NSString alloc] initWithFormat:@"efort %@", [teamData objectForKey:@"fort"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
109 |
[self sendToEngine: fort]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
110 |
[fort release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
111 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
112 |
NSString *voicepack = [[NSString alloc] initWithFormat:@"evoicepack %@", [teamData objectForKey:@"voicepack"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
113 |
[self sendToEngine: voicepack]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
114 |
[voicepack release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
115 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
116 |
NSString *flag = [[NSString alloc] initWithFormat:@"eflag %@", [teamData objectForKey:@"flag"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
117 |
[self sendToEngine: flag]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
118 |
[flag release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
119 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
120 |
NSArray *hogs = [teamData objectForKey:@"hedgehogs"]; |
3199 | 121 |
for (i = 0; i < playingHogs; i++) { |
122 |
NSDictionary *hog = [hogs objectAtIndex:i]; |
|
123 |
||
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
124 |
NSString *hogLevelHealthAndName = [[NSString alloc] initWithFormat:@"eaddhh %@ %@ %@", [hog objectForKey:@"level"], [hog objectForKey:@"health"], [hog objectForKey:@"hogname"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
125 |
[self sendToEngine: hogLevelHealthAndName]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
126 |
[hogLevelHealthAndName release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
127 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
128 |
NSString *hogHat = [[NSString alloc] initWithFormat:@"ehat %@", [hog objectForKey:@"hat"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
129 |
[self sendToEngine: hogHat]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
130 |
[hogHat release]; |
3349 | 131 |
} |
132 |
} |
|
133 |
||
134 |
-(void) sendAmmoData:(NSDictionary *)ammoData { |
|
135 |
NSString *ammloadt = [[NSString alloc] initWithFormat:@"eammloadt %@", [ammoData objectForKey:@"ammostore_initialqt"]]; |
|
136 |
[self sendToEngine: ammloadt]; |
|
137 |
[ammloadt release]; |
|
138 |
||
139 |
NSString *ammdelay = [[NSString alloc] initWithFormat:@"eammprob %@", [ammoData objectForKey:@"ammostore_probability"]]; |
|
140 |
[self sendToEngine: ammdelay]; |
|
141 |
[ammdelay release]; |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
142 |
|
3349 | 143 |
NSString *ammprob = [[NSString alloc] initWithFormat:@"eammdelay %@", [ammoData objectForKey:@"ammostore_delay"]]; |
144 |
[self sendToEngine: ammprob]; |
|
145 |
[ammprob release]; |
|
146 |
||
147 |
NSString *ammreinf = [[NSString alloc] initWithFormat:@"eammreinf %@", [ammoData objectForKey:@"ammostore_crate"]]; |
|
148 |
[self sendToEngine: ammreinf]; |
|
149 |
[ammreinf release]; |
|
150 |
||
151 |
// sent twice so it applies to both teams |
|
152 |
NSString *ammstore = [[NSString alloc] initWithString:@"eammstore"]; |
|
153 |
[self sendToEngine: ammstore]; |
|
154 |
[self sendToEngine: ammstore]; |
|
155 |
[ammstore release]; |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
156 |
} |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
157 |
|
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
|
158 |
-(void) engineProtocol { |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
159 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
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
|
160 |
IPaddress ip; |
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2702
diff
changeset
|
161 |
int eProto; |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
162 |
BOOL clientQuit, serverQuit; |
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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
|
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
|
167 |
if (SDLNet_Init() < 0) { |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
168 |
NSLog(@"SDLNet_Init: %s", SDLNet_GetError()); |
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
|
169 |
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
|
170 |
} |
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
|
171 |
|
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
|
172 |
/* 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
|
173 |
if (SDLNet_ResolveHost(&ip, NULL, ipcPort) < 0) { |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
174 |
NSLog(@"SDLNet_ResolveHost: %s\n", SDLNet_GetError()); |
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
|
175 |
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
|
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 |
|
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 |
/* 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
|
179 |
if (!(sd = SDLNet_TCP_Open(&ip))) { |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
180 |
NSLog(@"SDLNet_TCP_Open: %s %\n", SDLNet_GetError(), ipcPort); |
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
|
181 |
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
|
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 |
|
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
184 |
NSLog(@"engineProtocol - Waiting for a client on port %d", ipcPort); |
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
|
185 |
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
|
186 |
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
|
187 |
|
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 |
/* 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
|
189 |
* If there is one, accept that, and open a new socket for communicating */ |
2697 | 190 |
csd = SDLNet_TCP_Accept(sd); |
191 |
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
|
192 |
|
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 |
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
|
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 |
//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
|
196 |
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
|
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 |
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
|
199 |
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
|
200 |
//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
|
201 |
|
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 |
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
|
203 |
NSLog(@"engineProtocol - sending game config"); |
3199 | 204 |
|
205 |
NSArray *teamlist = [[NSArray alloc] initWithObjects:@"this",@"is",@"test",nil]; |
|
206 |
[self initTeam:teamlist]; |
|
207 |
[teamlist release]; |
|
208 |
||
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
|
209 |
// send config data data |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
210 |
/* |
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
211 |
seed is arbitrary string |
3006 | 212 |
addteam <32charsMD5hash> <color> <team name> |
2698 | 213 |
addhh <level> <health> <hedgehog name> |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
214 |
<level> is 0 for human, 1-5 for bots (5 is the most stupid) |
2734 | 215 |
ammostore is one byte/number for each ammocount then one for each probability or so |
216 |
*/ |
|
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
217 |
// local game |
2696 | 218 |
[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
|
219 |
|
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 |
// seed info |
2696 | 221 |
[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
|
222 |
|
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 |
// various flags |
2696 | 224 |
[self sendToEngine:@"e$gmflags 256"]; |
225 |
[self sendToEngine:@"e$damagepct 100"]; |
|
226 |
[self sendToEngine:@"e$turntime 45000"]; |
|
227 |
[self sendToEngine:@"e$minestime 3000"]; |
|
228 |
[self sendToEngine:@"e$landadds 4"]; |
|
229 |
[self sendToEngine:@"e$sd_turns 15"]; |
|
230 |
[self sendToEngine:@"e$casefreq 5"]; |
|
2753 | 231 |
|
2698 | 232 |
// dimension of the map |
2696 | 233 |
[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
|
234 |
|
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
|
235 |
// theme info |
2734 | 236 |
[self sendToEngine:@"etheme Compost"]; |
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 |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
238 |
for (NSDictionary *teamData in teams) { |
3199 | 239 |
[self sendTeamData:teamData withPlayingHogs:2]; |
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
240 |
NSLog(@"teamData sent"); |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
241 |
} |
3349 | 242 |
|
243 |
NSDictionary *ammoData = [[NSDictionary alloc] initWithObjectsAndKeys: |
|
244 |
@"939192942219912103223511100120100000021110",@"ammostore_initialqt", |
|
245 |
@"040504054160065554655446477657666666615550",@"ammostore_probability", |
|
246 |
@"000000000000020550000004000700400000000020",@"ammostore_delay", |
|
247 |
@"131111031211111112311411111111111111121110",@"ammostore_crate", nil]; |
|
248 |
[self sendAmmoData: ammoData]; |
|
249 |
[ammoData release]; |
|
250 |
||
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
251 |
clientQuit = NO; |
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
|
252 |
} else { |
2697 | 253 |
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
|
254 |
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
|
255 |
} |
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
|
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
|
257 |
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
|
258 |
/* 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
|
259 |
* 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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
|
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 |
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
|
269 |
//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
|
270 |
|
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
|
271 |
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
|
272 |
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
|
273 |
NSLog(@"Ping? Pong!"); |
2696 | 274 |
[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
|
275 |
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
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
sscanf(buffer, "%*s %d", &eProto); |
3328
fe87c2242984
fix the save of the team and rearrange hat/name modification
koda
parents:
3312
diff
changeset
|
282 |
short int netProto = 0; |
2799 | 283 |
char *versionStr; |
3199 | 284 |
|
3006 | 285 |
HW_versionInfo(&netProto, &versionStr); |
2799 | 286 |
if (netProto == eProto) { |
287 |
NSLog(@"Setting protocol version %d (%s)", eProto, versionStr); |
|
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 |
} 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
|
289 |
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
|
290 |
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
|
291 |
} |
3199 | 292 |
|
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
|
293 |
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
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
} |
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
|
303 |
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
|
304 |
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
|
305 |
// 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
|
306 |
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
|
307 |
// missing case for exiting right away |
2697 | 308 |
} |
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
|
309 |
} |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
310 |
NSLog(@"Engine exited, closing server"); |
2697 | 311 |
// wait a little to let the client close cleanly |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
312 |
[NSThread sleepForTimeInterval:2]; |
2697 | 313 |
// Close the client socket |
314 |
SDLNet_TCP_Close(csd); |
|
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
315 |
serverQuit = YES; |
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
|
316 |
} |
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
|
317 |
} |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
318 |
|
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
|
319 |
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
|
320 |
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
|
321 |
|
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
|
322 |
[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
|
323 |
[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
|
324 |
} |
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
|
325 |
|
2696 | 326 |
#pragma mark - |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
327 |
#pragma mark Setting methods |
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
328 |
-(const char **)getSettings { |
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
329 |
NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", ipcPort]; |
3006 | 330 |
NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
3021 | 331 |
CGRect screenBounds = [[UIScreen mainScreen] bounds]; |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
332 |
NSString *wSize = [[NSString alloc] initWithFormat:@"%d", (int) screenBounds.size.width]; |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
333 |
NSString *hSize = [[NSString alloc] initWithFormat:@"%d", (int) screenBounds.size.height]; |
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
334 |
const char **gameArgs = (const char**) malloc(sizeof(char*) * 8); |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
335 |
|
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
336 |
/* |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
337 |
size_t size; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
338 |
// Set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
339 |
sysctlbyname("hw.machine", NULL, &size, NULL, 0); |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
340 |
char *name = malloc(size); |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
341 |
// Get the platform name |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
342 |
sysctlbyname("hw.machine", name, &size, NULL, 0); |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
343 |
NSString *machine = [[NSString alloc] initWithUTF8String:name]; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
344 |
free(name); |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
345 |
|
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
346 |
const char **gameArgs = (const char**) malloc(sizeof(char*) * 9); |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
347 |
|
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
348 |
// if the machine is less than iphone 3gs or less than ipod touch 3g use reduced graphics (land array) |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
349 |
if ([machine hasPrefix:@"iPhone1"] || ([machine hasPrefix:@"iPod"] && ([machine hasSuffix:@"1,1"] || [machine hasSuffix:@"2,1"]))) |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
350 |
gameArgs[8] = "1"; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
351 |
else |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
352 |
gameArgs[8] = "0"; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
353 |
[machine release]; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
354 |
*/ |
3021 | 355 |
|
3312 | 356 |
// prevents using an empty nickname |
357 |
NSString *username; |
|
358 |
NSString *originalUsername = [systemSettings objectForKey:@"username"]; |
|
3335 | 359 |
if ([originalUsername length] == 0) { |
3312 | 360 |
username = [[NSString alloc] initWithFormat:@"MobileUser-%@",ipcString]; |
361 |
} else { |
|
362 |
username = [[NSString alloc] initWithString:originalUsername]; |
|
363 |
} |
|
364 |
||
3335 | 365 |
gameArgs[0] = [username UTF8String]; //UserNick |
366 |
gameArgs[1] = [ipcString UTF8String]; //ipcPort |
|
367 |
gameArgs[2] = [[[systemSettings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled |
|
368 |
gameArgs[3] = [[[systemSettings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled |
|
369 |
gameArgs[4] = [localeString UTF8String]; //cLocaleFName |
|
3332 | 370 |
gameArgs[5] = [[[systemSettings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage |
3335 | 371 |
gameArgs[6] = [wSize UTF8String]; //cScreenHeight |
372 |
gameArgs[7] = [hSize UTF8String]; //cScreenWidth |
|
3021 | 373 |
|
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
374 |
[wSize release]; |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
375 |
[hSize release]; |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
376 |
[localeString release]; |
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
377 |
[ipcString release]; |
3312 | 378 |
[username release]; |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
379 |
return gameArgs; |
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
|
380 |
} |
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
|
381 |
|
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
|
382 |
|
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
|
383 |
@end |