author | koda |
Thu, 17 Jun 2010 19:57:51 +0200 | |
changeset 3513 | f589230fa21b |
parent 3495 | a6b4f351d400 |
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 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
23 |
@synthesize systemSettings, gameConfig; |
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]) { |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
27 |
ipcPort = randomPort(); |
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
28 |
|
3373 | 29 |
// should check they exist and throw and exection if not |
30 |
NSDictionary *dictSett = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
31 |
self.systemSettings = dictSett; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
32 |
[dictSett release]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
33 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
34 |
NSDictionary *dictGame = [[NSDictionary alloc] initWithContentsOfFile:GAMECONFIG_FILE()]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
35 |
self.gameConfig = dictGame; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
36 |
[dictGame release]; |
3364 | 37 |
} |
38 |
return self; |
|
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
|
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 |
|
3221 | 41 |
-(NSString *)description { |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
42 |
return [NSString stringWithFormat:@"ipcport: %d\nsockets: %d,%d\n teams: %@\n systemSettings: %@",ipcPort,sd,csd,gameConfig,systemSettings]; |
3221 | 43 |
} |
44 |
||
2696 | 45 |
-(void) dealloc { |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
46 |
[gameConfig release]; |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
47 |
[systemSettings release]; |
2696 | 48 |
[super dealloc]; |
49 |
} |
|
50 |
||
51 |
#pragma mark - |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
52 |
#pragma mark Provider functions |
3479 | 53 |
// unpacks team data from the selected team.plist to a sequence of engine commands |
54 |
-(void) provideTeamData:(NSString *)teamName forHogs:(NSInteger) numberOfPlayingHogs withHealth:(NSInteger) initialHealth ofColor:(NSNumber *)teamColor { |
|
55 |
/* |
|
56 |
addteam <32charsMD5hash> <color> <team name> |
|
57 |
addhh <level> <health> <hedgehog name> |
|
58 |
<level> is 0 for human, 1-5 for bots (5 is the most stupid) |
|
59 |
*/ |
|
60 |
||
61 |
NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@", TEAMS_DIRECTORY(), teamName]; |
|
3364 | 62 |
NSDictionary *teamData = [[NSDictionary alloc] initWithContentsOfFile:teamFile]; |
63 |
[teamFile release]; |
|
3199 | 64 |
|
3479 | 65 |
NSString *teamHashColorAndName = [[NSString alloc] initWithFormat:@"eaddteam %@ %@ %@", |
66 |
[teamData objectForKey:@"hash"], [teamColor stringValue], [teamData objectForKey:@"teamname"]]; |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
67 |
[self sendToEngine: teamHashColorAndName]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
68 |
[teamHashColorAndName release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
69 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
70 |
NSString *grave = [[NSString alloc] initWithFormat:@"egrave %@", [teamData objectForKey:@"grave"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
71 |
[self sendToEngine: grave]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
72 |
[grave release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
73 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
74 |
NSString *fort = [[NSString alloc] initWithFormat:@"efort %@", [teamData objectForKey:@"fort"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
75 |
[self sendToEngine: fort]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
76 |
[fort release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
77 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
78 |
NSString *voicepack = [[NSString alloc] initWithFormat:@"evoicepack %@", [teamData objectForKey:@"voicepack"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
79 |
[self sendToEngine: voicepack]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
80 |
[voicepack release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
81 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
82 |
NSString *flag = [[NSString alloc] initWithFormat:@"eflag %@", [teamData objectForKey:@"flag"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
83 |
[self sendToEngine: flag]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
84 |
[flag release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
85 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
86 |
NSArray *hogs = [teamData objectForKey:@"hedgehogs"]; |
3479 | 87 |
for (int i = 0; i < numberOfPlayingHogs; i++) { |
3199 | 88 |
NSDictionary *hog = [hogs objectAtIndex:i]; |
89 |
||
3479 | 90 |
NSString *hogLevelHealthAndName = [[NSString alloc] initWithFormat:@"eaddhh %@ %d %@", |
91 |
[hog objectForKey:@"level"], initialHealth, [hog objectForKey:@"hogname"]]; |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
92 |
[self sendToEngine: hogLevelHealthAndName]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
93 |
[hogLevelHealthAndName release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
94 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
95 |
NSString *hogHat = [[NSString alloc] initWithFormat:@"ehat %@", [hog objectForKey:@"hat"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
96 |
[self sendToEngine: hogHat]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
97 |
[hogHat release]; |
3364 | 98 |
} |
99 |
||
100 |
[teamData release]; |
|
3349 | 101 |
} |
102 |
||
3479 | 103 |
// unpacks ammostore data from the selected ammo.plist to a sequence of engine commands |
104 |
-(void) provideAmmoData:(NSString *)ammostoreName forPlayingTeams:(NSInteger) numberOfTeams { |
|
105 |
||
106 |
//NSDictionary *ammoData = [[NSDictionary alloc] initWithContentsOfFile:ammoDataFile]; |
|
107 |
NSDictionary *ammoData = [[NSDictionary alloc] initWithObjectsAndKeys: |
|
108 |
@"9391929422199121032235111001201000000211190911",@"ammostore_initialqt", |
|
109 |
@"0405040541600655546554464776576666666155501000",@"ammostore_probability", |
|
110 |
@"0000000000000205500000040007004000000000200000",@"ammostore_delay", |
|
111 |
@"1311110312111111123114111111111111111211101111",@"ammostore_crate", nil]; |
|
112 |
||
113 |
||
3349 | 114 |
NSString *ammloadt = [[NSString alloc] initWithFormat:@"eammloadt %@", [ammoData objectForKey:@"ammostore_initialqt"]]; |
115 |
[self sendToEngine: ammloadt]; |
|
116 |
[ammloadt release]; |
|
117 |
||
3479 | 118 |
NSString *ammprob = [[NSString alloc] initWithFormat:@"eammprob %@", [ammoData objectForKey:@"ammostore_probability"]]; |
119 |
[self sendToEngine: ammprob]; |
|
120 |
[ammprob release]; |
|
121 |
||
122 |
NSString *ammdelay = [[NSString alloc] initWithFormat:@"eammdelay %@", [ammoData objectForKey:@"ammostore_delay"]]; |
|
3349 | 123 |
[self sendToEngine: ammdelay]; |
124 |
[ammdelay release]; |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
125 |
|
3349 | 126 |
NSString *ammreinf = [[NSString alloc] initWithFormat:@"eammreinf %@", [ammoData objectForKey:@"ammostore_crate"]]; |
127 |
[self sendToEngine: ammreinf]; |
|
128 |
[ammreinf release]; |
|
129 |
||
130 |
// sent twice so it applies to both teams |
|
131 |
NSString *ammstore = [[NSString alloc] initWithString:@"eammstore"]; |
|
3479 | 132 |
for (int i = 0; i < numberOfTeams; i++) |
3364 | 133 |
[self sendToEngine: ammstore]; |
3349 | 134 |
[ammstore release]; |
3479 | 135 |
|
136 |
[ammoData release]; |
|
137 |
} |
|
138 |
||
139 |
// unpacks scheme data from the selected scheme.plist to a sequence of engine commands |
|
140 |
-(NSInteger) provideScheme:(NSString *)schemeName { |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
141 |
NSString *schemePath = [[NSString alloc] initWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),schemeName]; |
3479 | 142 |
NSArray *scheme = [[NSArray alloc] initWithContentsOfFile:schemePath]; |
3487 | 143 |
[schemePath release]; |
3479 | 144 |
int result = 0; |
145 |
int i = 0; |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
146 |
|
3479 | 147 |
if ([[scheme objectAtIndex:i++] boolValue]) |
148 |
result |= 0x01; |
|
149 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
150 |
result |= 0x10; |
|
151 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
152 |
result |= 0x04; |
|
153 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
154 |
result |= 0x08; |
|
155 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
156 |
result |= 0x20; |
|
157 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
158 |
result |= 0x40; |
|
159 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
160 |
result |= 0x80; |
|
161 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
162 |
result |= 0x100; |
|
163 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
164 |
result |= 0x200; |
|
165 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
166 |
result |= 0x400; |
|
167 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
168 |
result |= 0x800; |
|
169 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
170 |
result |= 0x2000; |
|
171 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
172 |
result |= 0x4000; |
|
173 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
174 |
result |= 0x8000; |
|
175 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
176 |
result |= 0x10000; |
|
177 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
178 |
result |= 0x20000; |
|
179 |
if ([[scheme objectAtIndex:i++] boolValue]) |
|
180 |
result |= 0x80000; |
|
181 |
||
182 |
NSString *flags = [[NSString alloc] initWithFormat:@"e$gmflags %d",result]; |
|
183 |
[self sendToEngine:flags]; |
|
184 |
[flags release]; |
|
185 |
||
186 |
NSString *dmgMod = [[NSString alloc] initWithFormat:@"e$damagepct %d",[[scheme objectAtIndex:i++] intValue]]; |
|
187 |
[self sendToEngine:dmgMod]; |
|
188 |
[dmgMod release]; |
|
189 |
||
190 |
NSString *turnTime = [[NSString alloc] initWithFormat:@"e$turntime %d",[[scheme objectAtIndex:i++] intValue] * 1000]; |
|
191 |
[self sendToEngine:turnTime]; |
|
192 |
[turnTime release]; |
|
193 |
||
194 |
result = [[scheme objectAtIndex:i++] intValue]; // initial health |
|
195 |
||
196 |
NSString *sdTime = [[NSString alloc] initWithFormat:@"e$sd_turns %d",[[scheme objectAtIndex:i++] intValue]]; |
|
197 |
[self sendToEngine:sdTime]; |
|
198 |
[sdTime release]; |
|
199 |
||
200 |
NSString *crateDrops = [[NSString alloc] initWithFormat:@"e$casefreq %d",[[scheme objectAtIndex:i++] intValue]]; |
|
201 |
[self sendToEngine:crateDrops]; |
|
202 |
[crateDrops release]; |
|
203 |
||
204 |
NSString *minesTime = [[NSString alloc] initWithFormat:@"e$minestime %d",[[scheme objectAtIndex:i++] intValue] * 1000]; |
|
205 |
[self sendToEngine:minesTime]; |
|
206 |
[minesTime release]; |
|
207 |
||
208 |
NSString *minesNumber = [[NSString alloc] initWithFormat:@"e$landadds %d",[[scheme objectAtIndex:i++] intValue]]; |
|
209 |
[self sendToEngine:minesNumber]; |
|
210 |
[minesNumber release]; |
|
211 |
||
212 |
NSString *dudMines = [[NSString alloc] initWithFormat:@"e$minedudpct %d",[[scheme objectAtIndex:i++] intValue]]; |
|
213 |
[self sendToEngine:dudMines]; |
|
214 |
[dudMines release]; |
|
215 |
||
216 |
NSString *explosives = [[NSString alloc] initWithFormat:@"e$explosives %d",[[scheme objectAtIndex:i++] intValue]]; |
|
217 |
[self sendToEngine:explosives]; |
|
218 |
[explosives release]; |
|
219 |
||
3487 | 220 |
[scheme release]; |
3479 | 221 |
return result; |
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
222 |
} |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
223 |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
224 |
#pragma mark - |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
225 |
#pragma mark Thread/Network relevant code |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
226 |
// select one of GameSetup method and execute it in a seprate thread |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
227 |
-(void) startThread: (NSString *) selector { |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
228 |
SEL usage = NSSelectorFromString(selector); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
229 |
[NSThread detachNewThreadSelector:usage toTarget:self withObject:nil]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
230 |
} |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
231 |
|
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
232 |
// wrapper that computes the length of the message and then sends the command string |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
233 |
-(int) sendToEngine: (NSString *)string { |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
234 |
uint8_t length = [string length]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
235 |
|
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
236 |
SDLNet_TCP_Send(csd, &length , 1); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
237 |
return SDLNet_TCP_Send(csd, [string UTF8String], length); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
238 |
} |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
239 |
|
3373 | 240 |
// method that handles net setup with engine and keeps connection alive |
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
|
241 |
-(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
|
242 |
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
|
243 |
IPaddress ip; |
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2702
diff
changeset
|
244 |
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
|
245 |
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
|
246 |
char buffer[BUFFER_SIZE], string[BUFFER_SIZE]; |
3479 | 247 |
uint8_t msgSize; |
248 |
uint16_t gameTicks; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
249 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
250 |
serverQuit = NO; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
251 |
|
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 |
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
|
253 |
NSLog(@"SDLNet_Init: %s", SDLNet_GetError()); |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
254 |
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
|
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 |
|
3373 | 257 |
// 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
|
258 |
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
|
259 |
NSLog(@"SDLNet_ResolveHost: %s\n", SDLNet_GetError()); |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
260 |
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
|
261 |
} |
3207e0eacd43
GameSetup is now 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 |
|
3373 | 263 |
// Open a connection with the IP provided (listen on the host's port) |
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
|
264 |
if (!(sd = SDLNet_TCP_Open(&ip))) { |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
265 |
NSLog(@"SDLNet_TCP_Open: %s %\n", SDLNet_GetError(), ipcPort); |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
266 |
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
|
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 |
|
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
|
269 |
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
|
270 |
while (!serverQuit) { |
3373 | 271 |
// This check the sd if there is a pending connection. |
272 |
// If there is one, accept that, and open a new socket for communicating |
|
2697 | 273 |
csd = SDLNet_TCP_Accept(sd); |
274 |
if (NULL != csd) { |
|
3373 | 275 |
// Now we can communicate with the client using csd socket |
276 |
// sd will remain opened waiting other connections |
|
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
|
277 |
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
|
278 |
|
3207e0eacd43
GameSetup is now 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 |
//first byte of the command alwayas contain the size of the command |
3479 | 280 |
SDLNet_TCP_Recv(csd, &msgSize, sizeof(uint8_t)); |
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
|
281 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
282 |
SDLNet_TCP_Recv(csd, buffer, msgSize); |
3373 | 283 |
gameTicks = SDLNet_Read16 (&buffer[msgSize - 2]); |
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
|
284 |
//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
|
285 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
286 |
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
|
287 |
NSLog(@"engineProtocol - sending game config"); |
3199 | 288 |
|
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
|
289 |
// local game |
2696 | 290 |
[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
|
291 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
292 |
// seed info |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
293 |
[self sendToEngine:[self.gameConfig objectForKey:@"seed_command"]]; |
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
|
294 |
|
3479 | 295 |
// scheme (returns initial health) |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3495
diff
changeset
|
296 |
NSInteger health = [self provideScheme:[self.gameConfig objectForKey:@"scheme"]]; |
2753 | 297 |
|
2698 | 298 |
// dimension of the map |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
299 |
[self sendToEngine:[self.gameConfig objectForKey:@"templatefilter_command"]]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
300 |
[self sendToEngine:[self.gameConfig objectForKey:@"mapgen_command"]]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
301 |
[self sendToEngine:[self.gameConfig objectForKey:@"mazesize_command"]]; |
3373 | 302 |
|
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
|
303 |
// theme info |
3373 | 304 |
[self sendToEngine:[self.gameConfig objectForKey:@"theme_command"]]; |
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 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
306 |
NSArray *teamsConfig = [self.gameConfig objectForKey:@"teams_list"]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
307 |
for (NSDictionary *teamData in teamsConfig) { |
3479 | 308 |
[self provideTeamData:[teamData objectForKey:@"team"] |
309 |
forHogs:[[teamData objectForKey:@"number"] intValue] |
|
310 |
withHealth:health |
|
311 |
ofColor:[teamData objectForKey:@"color"]]; |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
312 |
} |
3349 | 313 |
|
3479 | 314 |
[self provideAmmoData:nil forPlayingTeams:[teamsConfig count]]; |
3349 | 315 |
|
3364 | 316 |
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
|
317 |
} else { |
2697 | 318 |
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
|
319 |
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
|
320 |
} |
3207e0eacd43
GameSetup is now 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 |
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
|
323 |
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
|
324 |
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
|
325 |
memset(string, 0, BUFFER_SIZE); |
3479 | 326 |
if (SDLNet_TCP_Recv(csd, &msgSize, sizeof(uint8_t)) <= 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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
331 |
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
|
332 |
//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
|
333 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
334 |
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
|
335 |
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
|
336 |
NSLog(@"Ping? Pong!"); |
2696 | 337 |
[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
|
338 |
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
|
339 |
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
|
340 |
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
|
341 |
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
|
342 |
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
|
343 |
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
|
344 |
sscanf(buffer, "%*s %d", &eProto); |
3328
fe87c2242984
fix the save of the team and rearrange hat/name modification
koda
parents:
3312
diff
changeset
|
345 |
short int netProto = 0; |
2799 | 346 |
char *versionStr; |
3199 | 347 |
|
3006 | 348 |
HW_versionInfo(&netProto, &versionStr); |
2799 | 349 |
if (netProto == eProto) { |
350 |
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
|
351 |
} 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
|
352 |
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
|
353 |
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
|
354 |
} |
3199 | 355 |
|
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
|
356 |
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
|
357 |
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
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
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
|
365 |
} |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
366 |
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
|
367 |
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
|
368 |
// 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
|
369 |
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
|
370 |
// missing case for exiting right away |
2697 | 371 |
} |
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
|
372 |
} |
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
|
373 |
NSLog(@"Engine exited, closing server"); |
2697 | 374 |
// 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
|
375 |
[NSThread sleepForTimeInterval:2]; |
2697 | 376 |
// Close the client socket |
377 |
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
|
378 |
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
|
379 |
} |
3207e0eacd43
GameSetup is now 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 |
} |
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
|
381 |
|
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
|
382 |
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
|
383 |
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
|
384 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
385 |
[[NSFileManager defaultManager] removeItemAtPath:GAMECONFIG_FILE() error:NULL]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
386 |
|
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
|
387 |
[pool release]; |
3490 | 388 |
//Invoking this method should be avoided as it does not give your thread a chance to clean up any resources it allocated during its execution. |
389 |
//[NSThread exit]; |
|
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
|
390 |
} |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
391 |
|
2696 | 392 |
#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
|
393 |
#pragma mark Setting methods |
3373 | 394 |
// returns an array of c-strings that are read by engine at startup |
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
|
395 |
-(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
|
396 |
NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", ipcPort]; |
3006 | 397 |
NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
3021 | 398 |
CGRect screenBounds = [[UIScreen mainScreen] bounds]; |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
399 |
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
|
400 |
NSString *hSize = [[NSString alloc] initWithFormat:@"%d", (int) screenBounds.size.height]; |
3495
a6b4f351d400
now engine can be optionally built as library, there's an example wrapper of how to use it
koda
parents:
3490
diff
changeset
|
401 |
const char **gameArgs = (const char**) malloc(sizeof(char *) * 9); |
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
402 |
|
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
403 |
/* |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
404 |
size_t size; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
405 |
// 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
|
406 |
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
|
407 |
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
|
408 |
// 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
|
409 |
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
|
410 |
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
|
411 |
free(name); |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
412 |
|
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
413 |
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
|
414 |
|
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
415 |
// 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
|
416 |
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
|
417 |
gameArgs[8] = "1"; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
418 |
else |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
419 |
gameArgs[8] = "0"; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
420 |
[machine release]; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
421 |
*/ |
3021 | 422 |
|
3312 | 423 |
// prevents using an empty nickname |
424 |
NSString *username; |
|
3364 | 425 |
NSString *originalUsername = [self.systemSettings objectForKey:@"username"]; |
3373 | 426 |
if ([originalUsername length] == 0) |
3312 | 427 |
username = [[NSString alloc] initWithFormat:@"MobileUser-%@",ipcString]; |
3373 | 428 |
else |
3312 | 429 |
username = [[NSString alloc] initWithString:originalUsername]; |
430 |
||
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
431 |
gameArgs[0] = [username UTF8String]; //UserNick |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
432 |
gameArgs[1] = [ipcString UTF8String]; //ipcPort |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
433 |
gameArgs[2] = [[[self.systemSettings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
434 |
gameArgs[3] = [[[self.systemSettings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
435 |
gameArgs[4] = [localeString UTF8String]; //cLocaleFName |
3364 | 436 |
gameArgs[5] = [[[self.systemSettings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
437 |
gameArgs[6] = [wSize UTF8String]; //cScreenHeight |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
438 |
gameArgs[7] = [hSize UTF8String]; //cScreenWidth |
3495
a6b4f351d400
now engine can be optionally built as library, there's an example wrapper of how to use it
koda
parents:
3490
diff
changeset
|
439 |
gameArgs[8] = NULL; //recordFileName |
3021 | 440 |
|
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
441 |
[wSize release]; |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
442 |
[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
|
443 |
[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
|
444 |
[ipcString release]; |
3312 | 445 |
[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
|
446 |
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
|
447 |
} |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
448 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
449 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
450 |
@end |