Remove cvector and ivector
FossilOrigin-Name: 5bbd6d8ddd29ca99ebd4b494d11fea537f9567483fc9be14932846ece1503563
This commit is contained in:
parent
0bd8f1920f
commit
b8b9ef2e79
4 changed files with 97 additions and 51 deletions
|
@ -185,7 +185,7 @@ COMMANDN(disconnect, trydisconnect, ARG_NONE)
|
|||
|
||||
// collect c2s messages conveniently
|
||||
|
||||
vector<ivector> messages;
|
||||
static OFMutableArray<OFData *> *messages;
|
||||
|
||||
void
|
||||
addmsg(int rel, int num, int type, ...)
|
||||
|
@ -197,18 +197,31 @@ addmsg(int rel, int num, int type, ...)
|
|||
stringWithFormat:@"inconsistant msg size for %d (%d != %d)",
|
||||
type, num, msgsizelookup(type)]);
|
||||
}
|
||||
if (messages.length() == 100) {
|
||||
if (messages.count == 100) {
|
||||
conoutf(@"command flood protection (type %d)", type);
|
||||
return;
|
||||
}
|
||||
ivector &msg = messages.add();
|
||||
msg.add(num);
|
||||
msg.add(rel);
|
||||
msg.add(type);
|
||||
|
||||
OFMutableData *msg = [OFMutableData dataWithItemSize:sizeof(int)
|
||||
capacity:num + 2];
|
||||
[msg addItem:&num];
|
||||
[msg addItem:&rel];
|
||||
[msg addItem:&type];
|
||||
|
||||
va_list marker;
|
||||
va_start(marker, type);
|
||||
loopi(num - 1) msg.add(va_arg(marker, int));
|
||||
loopi(num - 1)
|
||||
{
|
||||
int tmp = va_arg(marker, int);
|
||||
[msg addItem:&tmp];
|
||||
}
|
||||
va_end(marker);
|
||||
[msg makeImmutable];
|
||||
|
||||
if (messages == nil)
|
||||
messages = [[OFMutableArray alloc] init];
|
||||
|
||||
[messages addObject:msg];
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -313,7 +326,7 @@ c2sinfo(dynent *d) // send update to the server
|
|||
putint(p, -1);
|
||||
senditemstoserver = false;
|
||||
serveriteminitdone = true;
|
||||
};
|
||||
}
|
||||
if (ctext[0]) // player chat, not flood protected for
|
||||
// now
|
||||
{
|
||||
|
@ -321,7 +334,7 @@ c2sinfo(dynent *d) // send update to the server
|
|||
putint(p, SV_TEXT);
|
||||
sendstring(ctext, p);
|
||||
ctext[0] = 0;
|
||||
};
|
||||
}
|
||||
if (!c2sinit) // tell other clients who I am
|
||||
{
|
||||
packet->flags = ENET_PACKET_FLAG_RELIABLE;
|
||||
|
@ -330,23 +343,23 @@ c2sinfo(dynent *d) // send update to the server
|
|||
sendstring(player1->name, p);
|
||||
sendstring(player1->team, p);
|
||||
putint(p, player1->lifesequence);
|
||||
};
|
||||
loopv(messages) // send messages collected during the
|
||||
// previous frames
|
||||
{
|
||||
ivector &msg = messages[i];
|
||||
if (msg[1])
|
||||
}
|
||||
for (OFData *msg in messages) {
|
||||
// send messages collected during the previous
|
||||
// frames
|
||||
if (*(int *)[msg itemAtIndex:1])
|
||||
packet->flags =
|
||||
ENET_PACKET_FLAG_RELIABLE;
|
||||
loopi(msg[0]) putint(p, msg[i + 2]);
|
||||
};
|
||||
messages.setsize(0);
|
||||
loopi(*(int *)[msg itemAtIndex:0])
|
||||
putint(p, *(int *)[msg itemAtIndex:i + 2]);
|
||||
}
|
||||
[messages removeAllObjects];
|
||||
if (lastmillis - lastping > 250) {
|
||||
putint(p, SV_PING);
|
||||
putint(p, lastmillis);
|
||||
lastping = lastmillis;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
*(ushort *)start = ENET_HOST_TO_NET_16(p - start);
|
||||
enet_packet_resize(packet, p - start);
|
||||
incomingdemodata(start, p - start, true);
|
||||
|
|
|
@ -159,7 +159,7 @@ pasteconsole()
|
|||
strcat_s(commandbuf, cb);
|
||||
}
|
||||
|
||||
cvector vhistory;
|
||||
static OFMutableArray<OFString *> *vhistory;
|
||||
int histpos = 0;
|
||||
|
||||
void
|
||||
|
@ -167,9 +167,11 @@ history(int n)
|
|||
{
|
||||
static bool rec = false;
|
||||
|
||||
if (!rec && n >= 0 && n < vhistory.length()) {
|
||||
if (!rec && n >= 0 && n < vhistory.count) {
|
||||
rec = true;
|
||||
execute(vhistory[vhistory.length() - n - 1]);
|
||||
OFString *cmd = vhistory[vhistory.count - n - 1];
|
||||
std::unique_ptr<char> copy(strdup(cmd.UTF8String));
|
||||
execute(copy.get());
|
||||
rec = false;
|
||||
}
|
||||
}
|
||||
|
@ -192,18 +194,26 @@ keypress(int code, bool isdown, int cooked)
|
|||
commandbuf[i] = 0;
|
||||
resetcomplete();
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
case SDLK_UP:
|
||||
if (histpos)
|
||||
strcpy_s(
|
||||
commandbuf, vhistory[--histpos]);
|
||||
if (histpos) {
|
||||
@autoreleasepool {
|
||||
strcpy_s(commandbuf,
|
||||
vhistory[--histpos]
|
||||
.UTF8String);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_DOWN:
|
||||
if (histpos < vhistory.length())
|
||||
strcpy_s(
|
||||
commandbuf, vhistory[histpos++]);
|
||||
if (histpos < vhistory.count) {
|
||||
@autoreleasepool {
|
||||
strcpy_s(commandbuf,
|
||||
vhistory[histpos++]
|
||||
.UTF8String);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_TAB:
|
||||
|
@ -222,28 +232,39 @@ keypress(int code, bool isdown, int cooked)
|
|||
if (cooked) {
|
||||
char add[] = {(char)cooked, 0};
|
||||
strcat_s(commandbuf, add);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (code == SDLK_RETURN) {
|
||||
if (commandbuf[0]) {
|
||||
if (vhistory.empty() ||
|
||||
strcmp(
|
||||
vhistory.last(), commandbuf)) {
|
||||
vhistory.add(newstring(
|
||||
commandbuf)); // cap this?
|
||||
};
|
||||
histpos = vhistory.length();
|
||||
@autoreleasepool {
|
||||
OFString *cmdbuf =
|
||||
@(commandbuf);
|
||||
|
||||
if (vhistory == nil)
|
||||
vhistory =
|
||||
[[OFMutableArray
|
||||
alloc] init];
|
||||
|
||||
if (vhistory.count == 0 ||
|
||||
![vhistory.lastObject
|
||||
isEqual:cmdbuf]) {
|
||||
// cap this?
|
||||
[vhistory
|
||||
addObject:cmdbuf];
|
||||
}
|
||||
}
|
||||
histpos = vhistory.count;
|
||||
if (commandbuf[0] == '/')
|
||||
execute(commandbuf, true);
|
||||
else
|
||||
toserver(commandbuf);
|
||||
};
|
||||
}
|
||||
saycommand(NULL);
|
||||
} else if (code == SDLK_ESCAPE) {
|
||||
saycommand(NULL);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
} else if (!menukey(code, isdown)) {
|
||||
// keystrokes go to menu
|
||||
|
||||
|
|
|
@ -282,8 +282,6 @@ struct vertex {
|
|||
};
|
||||
|
||||
typedef vector<dynent *> dvector;
|
||||
typedef vector<char *> cvector;
|
||||
typedef vector<int> ivector;
|
||||
|
||||
// globals ooh naughty
|
||||
|
||||
|
|
24
src/sound.mm
24
src/sound.mm
|
@ -128,16 +128,30 @@ vector<Mix_Chunk *> samples;
|
|||
vector<FSOUND_SAMPLE *> samples;
|
||||
#endif
|
||||
|
||||
cvector snames;
|
||||
static OFMutableArray<OFString *> *snames;
|
||||
|
||||
int
|
||||
registersound(char *name)
|
||||
registersound(char *name_)
|
||||
{
|
||||
loopv(snames) if (strcmp(snames[i], name) == 0) return i;
|
||||
snames.add(newstring(name));
|
||||
@autoreleasepool {
|
||||
OFString *name = @(name_);
|
||||
|
||||
int i = 0;
|
||||
for (OFString *iter in snames) {
|
||||
if ([iter isEqual:name])
|
||||
return i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (snames == nil)
|
||||
snames = [[OFMutableArray alloc] init];
|
||||
|
||||
[snames addObject:name];
|
||||
samples.add(NULL);
|
||||
return samples.length() - 1;
|
||||
}
|
||||
}
|
||||
COMMAND(registersound, ARG_1EST)
|
||||
|
||||
void
|
||||
|
@ -240,7 +254,7 @@ playsound(int n, OFVector3D *loc)
|
|||
|
||||
if (!samples[n]) {
|
||||
OFString *path = [OFString
|
||||
stringWithFormat:@"packages/sounds/%s.wav", snames[n]];
|
||||
stringWithFormat:@"packages/sounds/%@.wav", snames[n]];
|
||||
OFIRI *IRI = [Cube.sharedInstance.gameDataIRI
|
||||
IRIByAppendingPathComponent:path];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue