author | smxx |
Wed, 31 Mar 2010 13:41:05 +0000 | |
changeset 3205 | ada12d757574 |
parent 3199 | 1a9938a27677 |
child 3221 | 3e6586c1ab4f |
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 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
9 |
#import "GameSetup.h" |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
10 |
#import "SDL_uikitappdelegate.h" |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
11 |
#import "SDL_net.h" |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
12 |
#import "PascalImports.h" |
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
13 |
#include <sys/types.h> |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
14 |
#include <sys/sysctl.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
|
15 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
16 |
#define BUFFER_SIZE 256 |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
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 |
@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
|
19 |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
20 |
@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
|
21 |
|
3207e0eacd43
GameSetup is now 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 |
-(id) init { |
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
23 |
if (self = [super init]) { |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
24 |
srandom(time(NULL)); |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
25 |
ipcPort = (random() % 64541) + 1025; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
26 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
27 |
NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
28 |
systemSettings = [[NSDictionary alloc] initWithContentsOfFile:filePath]; //should check it exists |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
29 |
return self; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
30 |
} else |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
31 |
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
|
32 |
} |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
33 |
|
2696 | 34 |
-(void) dealloc { |
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
35 |
[teams release]; |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
36 |
[systemSettings release]; |
2696 | 37 |
[super dealloc]; |
38 |
} |
|
39 |
||
40 |
#pragma mark - |
|
41 |
#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
|
42 |
-(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
|
43 |
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
|
44 |
[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
|
45 |
} |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
46 |
|
2696 | 47 |
-(int) sendToEngine: (NSString *)string { |
3199 | 48 |
unsigned char length = [string length]; |
2696 | 49 |
|
50 |
SDLNet_TCP_Send(csd, &length , 1); |
|
51 |
return SDLNet_TCP_Send(csd, [string UTF8String], length); |
|
52 |
} |
|
53 |
||
3199 | 54 |
-(void) initTeam:(NSArray *)teamLists { |
55 |
teams = [[NSMutableArray alloc] initWithObjects:nil]; |
|
56 |
||
57 |
for (NSString *teamString in teamLists) { |
|
58 |
//NSString *teamFile = [[NSString alloc] initWithFormat:@"%@.plist", teamString]; |
|
59 |
||
60 |
//NSDictionary *theTeam = [[NSDictionary alloc] initWithContentsOfFile:filePath]; |
|
61 |
//[teams addObject:theTeam]; |
|
62 |
//[theTeam release]; |
|
63 |
} |
|
64 |
||
65 |
NSDictionary *hogA1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Snow Leopard",@"hogname",@"NoHat",@"hat",nil]; |
|
66 |
NSDictionary *hogA2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Leopard",@"hogname",@"NoHat",@"hat",nil]; |
|
67 |
NSArray *hedgehogs1 = [[NSArray alloc] initWithObjects:hogA1,hogA2,nil]; |
|
68 |
[hogA1 release]; |
|
69 |
[hogA2 release]; |
|
70 |
NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash",@"System Cats",@"teamname", |
|
71 |
@"star",@"grave",@"Earth",@"fort",@"Classic",@"voicepack",@"hedgewars",@"flag",hedgehogs1,@"hedgehogs", |
|
72 |
@"93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111", |
|
73 |
@"ammostore",nil]; |
|
74 |
[hedgehogs1 release]; |
|
75 |
[teams addObject:firstTeam]; |
|
76 |
[firstTeam release]; |
|
77 |
||
78 |
NSDictionary *hogB1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Raichu",@"hogname",@"Bunny",@"hat",nil]; |
|
79 |
NSDictionary *hogB2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Pikachu",@"hogname",@"Bunny",@"hat",nil]; |
|
80 |
NSArray *hedgehogs2 = [[NSArray alloc] initWithObjects:hogB1,hogB2,nil]; |
|
81 |
[hogB1 release]; |
|
82 |
[hogB2 release]; |
|
83 |
NSDictionary *secondTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4100897",@"color",@"0",@"hash",@"Poke-MAN",@"teamname", |
|
84 |
@"Badger",@"grave",@"UFO",@"fort",@"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs2,@"hedgehogs", |
|
85 |
@"93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111", |
|
86 |
@"ammostore",nil]; |
|
87 |
[hedgehogs2 release]; |
|
88 |
[teams addObject:secondTeam]; |
|
89 |
[secondTeam release]; |
|
90 |
} |
|
91 |
||
92 |
-(void) sendTeamData:(NSDictionary *)teamData withPlayingHogs:(int) playingHogs{ |
|
93 |
int i; |
|
94 |
||
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
95 |
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
|
96 |
[self sendToEngine: teamHashColorAndName]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
97 |
[teamHashColorAndName release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
98 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
99 |
NSString *grave = [[NSString alloc] initWithFormat:@"egrave %@", [teamData objectForKey:@"grave"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
100 |
[self sendToEngine: grave]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
101 |
[grave release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
102 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
103 |
NSString *fort = [[NSString alloc] initWithFormat:@"efort %@", [teamData objectForKey:@"fort"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
104 |
[self sendToEngine: fort]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
105 |
[fort release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
106 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
107 |
NSString *voicepack = [[NSString alloc] initWithFormat:@"evoicepack %@", [teamData objectForKey:@"voicepack"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
108 |
[self sendToEngine: voicepack]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
109 |
[voicepack release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
110 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
111 |
NSString *flag = [[NSString alloc] initWithFormat:@"eflag %@", [teamData objectForKey:@"flag"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
112 |
[self sendToEngine: flag]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
113 |
[flag release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
114 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
115 |
NSArray *hogs = [teamData objectForKey:@"hedgehogs"]; |
3199 | 116 |
for (i = 0; i < playingHogs; i++) { |
117 |
NSDictionary *hog = [hogs objectAtIndex:i]; |
|
118 |
||
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
119 |
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
|
120 |
[self sendToEngine: hogLevelHealthAndName]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
121 |
[hogLevelHealthAndName release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
122 |
|
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
123 |
NSString *hogHat = [[NSString alloc] initWithFormat:@"ehat %@", [hog objectForKey:@"hat"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
124 |
[self sendToEngine: hogHat]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
125 |
[hogHat release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
126 |
} |
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 *ammostore = [[NSString alloc] initWithFormat:@"eammstore %@", [teamData objectForKey:@"ammostore"]]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
129 |
[self sendToEngine: ammostore]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
130 |
[ammostore release]; |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
131 |
} |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
132 |
|
2693
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
133 |
-(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
|
134 |
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
|
135 |
IPaddress ip; |
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2702
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
} |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
146 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
147 |
/* 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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
} |
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
152 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
153 |
/* 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
|
154 |
if (!(sd = SDLNet_TCP_Open(&ip))) { |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
155 |
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
|
156 |
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
|
157 |
} |
3207e0eacd43
GameSetup is now 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 |
|
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 |
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
|
160 |
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
|
161 |
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
|
162 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
163 |
/* 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
|
164 |
* If there is one, accept that, and open a new socket for communicating */ |
2697 | 165 |
csd = SDLNet_TCP_Accept(sd); |
166 |
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
|
167 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
168 |
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
|
169 |
|
3207e0eacd43
GameSetup is now 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 |
//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
|
171 |
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
|
172 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
//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
|
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 |
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
|
178 |
NSLog(@"engineProtocol - sending game config"); |
3199 | 179 |
|
180 |
NSArray *teamlist = [[NSArray alloc] initWithObjects:@"this",@"is",@"test",nil]; |
|
181 |
[self initTeam:teamlist]; |
|
182 |
[teamlist release]; |
|
183 |
||
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
|
184 |
// 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
|
185 |
/* |
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
|
186 |
seed is arbitrary string |
3006 | 187 |
addteam <32charsMD5hash> <color> <team name> |
2698 | 188 |
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
|
189 |
<level> is 0 for human, 1-5 for bots (5 is the most stupid) |
2734 | 190 |
ammostore is one byte/number for each ammocount then one for each probability or so |
191 |
*/ |
|
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
|
192 |
// local game |
2696 | 193 |
[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
|
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 |
// seed info |
2696 | 196 |
[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
|
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 |
// various flags |
2696 | 199 |
[self sendToEngine:@"e$gmflags 256"]; |
200 |
[self sendToEngine:@"e$damagepct 100"]; |
|
201 |
[self sendToEngine:@"e$turntime 45000"]; |
|
202 |
[self sendToEngine:@"e$minestime 3000"]; |
|
203 |
[self sendToEngine:@"e$landadds 4"]; |
|
204 |
[self sendToEngine:@"e$sd_turns 15"]; |
|
205 |
[self sendToEngine:@"e$casefreq 5"]; |
|
2753 | 206 |
|
2698 | 207 |
// dimension of the map |
2696 | 208 |
[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
|
209 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
210 |
// theme info |
2734 | 211 |
[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
|
212 |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
213 |
for (NSDictionary *teamData in teams) { |
3199 | 214 |
[self sendTeamData:teamData withPlayingHogs:2]; |
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
215 |
NSLog(@"teamData sent"); |
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
216 |
} |
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
|
217 |
|
3170
1dbf4f8eaac0
ifrontend: predispone teams in a proper data structure
koda
parents:
3165
diff
changeset
|
218 |
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
|
219 |
} else { |
2697 | 220 |
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
|
221 |
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
|
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 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
224 |
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
|
225 |
/* 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
|
226 |
* 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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
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
|
232 |
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
|
233 |
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
|
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 |
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
|
236 |
//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
|
237 |
|
3207e0eacd43
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
koda
parents:
diff
changeset
|
238 |
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
|
239 |
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
|
240 |
NSLog(@"Ping? Pong!"); |
2696 | 241 |
[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
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
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
|
248 |
sscanf(buffer, "%*s %d", &eProto); |
2799 | 249 |
short int netProto; |
250 |
char *versionStr; |
|
3199 | 251 |
|
3006 | 252 |
HW_versionInfo(&netProto, &versionStr); |
2799 | 253 |
if (netProto == eProto) { |
254 |
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
|
255 |
} 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
|
256 |
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
|
257 |
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
|
258 |
} |
3199 | 259 |
|
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
} |
3207e0eacd43
GameSetup is now 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 |
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
|
271 |
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
|
272 |
// 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
|
273 |
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
|
274 |
// missing case for exiting right away |
2697 | 275 |
} |
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
|
276 |
} |
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
|
277 |
NSLog(@"Engine exited, closing server"); |
2697 | 278 |
// 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
|
279 |
[NSThread sleepForTimeInterval:2]; |
2697 | 280 |
// Close the client socket |
281 |
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
|
282 |
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
|
283 |
} |
3207e0eacd43
GameSetup is now 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 |
} |
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
|
285 |
|
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
|
286 |
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
|
287 |
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
|
288 |
|
3207e0eacd43
GameSetup is now 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 |
[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
|
290 |
[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
|
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 |
|
2696 | 293 |
#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
|
294 |
#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
|
295 |
-(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
|
296 |
NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", ipcPort]; |
3006 | 297 |
NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
3021 | 298 |
CGRect screenBounds = [[UIScreen mainScreen] bounds]; |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
|
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
303 |
/* |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
304 |
size_t size; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
305 |
// 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
|
306 |
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
|
307 |
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
|
308 |
// 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
|
309 |
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
|
310 |
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
|
311 |
free(name); |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
312 |
|
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
313 |
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
|
314 |
|
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
315 |
// 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
|
316 |
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
|
317 |
gameArgs[8] = "1"; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
318 |
else |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
319 |
gameArgs[8] = "0"; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
320 |
[machine release]; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3090
diff
changeset
|
321 |
*/ |
3021 | 322 |
|
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
|
323 |
gameArgs[0] = [[systemSettings objectForKey:@"username"] UTF8String]; //UserNick |
3006 | 324 |
gameArgs[1] = [ipcString UTF8String]; //ipcPort |
325 |
gameArgs[2] = [[systemSettings objectForKey:@"sounds"] UTF8String]; //isSoundEnabled |
|
326 |
gameArgs[3] = [[systemSettings objectForKey:@"music"] UTF8String]; //isMusicEnabled |
|
327 |
gameArgs[4] = [localeString UTF8String]; //cLocaleFName |
|
2743 | 328 |
gameArgs[5] = [[systemSettings objectForKey:@"alternate"] UTF8String]; //cAltDamage |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
329 |
gameArgs[6] = [wSize UTF8String]; //cScreenHeight |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
330 |
gameArgs[7] = [hSize UTF8String]; //cScreenWidth |
3021 | 331 |
|
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
332 |
[wSize release]; |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3021
diff
changeset
|
333 |
[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
|
334 |
[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
|
335 |
[ipcString 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
|
336 |
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
|
337 |
} |
3207e0eacd43
GameSetup is now 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 |
|
3207e0eacd43
GameSetup is now 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 |
|
3207e0eacd43
GameSetup is now 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 |
@end |