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