Migrate more strings
FossilOrigin-Name: 0d125c31daf305a4363234402dbf375ecd71b24da762aa8e8c59751678cf47ec
This commit is contained in:
parent
ce5944a7b1
commit
b00de734e8
25 changed files with 476 additions and 439 deletions
|
@ -85,8 +85,8 @@ screenshot()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(screenshot, ARG_NONE);
|
COMMAND(screenshot, ARG_NONE)
|
||||||
COMMAND(quit, ARG_NONE);
|
COMMAND(quit, ARG_NONE)
|
||||||
|
|
||||||
void
|
void
|
||||||
keyrepeat(bool on)
|
keyrepeat(bool on)
|
||||||
|
@ -215,8 +215,8 @@ int framesinmap = 0;
|
||||||
|
|
||||||
log("localconnect");
|
log("localconnect");
|
||||||
localconnect();
|
localconnect();
|
||||||
changemap(
|
// if this map is changed, also change depthcorrect()
|
||||||
"metl3"); // if this map is changed, also change depthcorrect()
|
changemap(@"metl3");
|
||||||
|
|
||||||
log("mainloop");
|
log("mainloop");
|
||||||
int ignore = 5;
|
int ignore = 5;
|
||||||
|
|
|
@ -70,8 +70,8 @@ newteam(char *name)
|
||||||
strn0cpy(player1->team, name, 5);
|
strn0cpy(player1->team, name, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMANDN(team, newteam, ARG_1STR);
|
COMMANDN(team, newteam, ARG_1CSTR)
|
||||||
COMMANDN(name, newname, ARG_1STR);
|
COMMANDN(name, newname, ARG_1CSTR)
|
||||||
|
|
||||||
void
|
void
|
||||||
writeclientinfo(FILE *f)
|
writeclientinfo(FILE *f)
|
||||||
|
@ -171,10 +171,10 @@ echo(char *text)
|
||||||
conoutf(@"%s", text);
|
conoutf(@"%s", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(echo, ARG_VARI);
|
COMMAND(echo, ARG_VARI)
|
||||||
COMMANDN(say, toserver, ARG_VARI);
|
COMMANDN(say, toserver, ARG_VARI)
|
||||||
COMMANDN(connect, connects, ARG_1STR);
|
COMMANDN(connect, connects, ARG_1CSTR)
|
||||||
COMMANDN(disconnect, trydisconnect, ARG_NONE);
|
COMMANDN(disconnect, trydisconnect, ARG_NONE)
|
||||||
|
|
||||||
// collect c2s messages conveniently
|
// collect c2s messages conveniently
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ server_err()
|
||||||
}
|
}
|
||||||
|
|
||||||
int lastupdate = 0, lastping = 0;
|
int lastupdate = 0, lastping = 0;
|
||||||
string toservermap;
|
OFString *toservermap;
|
||||||
bool senditemstoserver =
|
bool senditemstoserver =
|
||||||
false; // after a map change, since server doesn't have map data
|
false; // after a map change, since server doesn't have map data
|
||||||
|
|
||||||
|
@ -221,8 +221,8 @@ void
|
||||||
password(char *p)
|
password(char *p)
|
||||||
{
|
{
|
||||||
strcpy_s(clientpassword, p);
|
strcpy_s(clientpassword, p);
|
||||||
};
|
}
|
||||||
COMMAND(password, ARG_1STR);
|
COMMAND(password, ARG_1CSTR)
|
||||||
|
|
||||||
bool
|
bool
|
||||||
netmapstart()
|
netmapstart()
|
||||||
|
@ -235,11 +235,11 @@ void
|
||||||
initclientnet()
|
initclientnet()
|
||||||
{
|
{
|
||||||
ctext[0] = 0;
|
ctext[0] = 0;
|
||||||
toservermap[0] = 0;
|
toservermap = @"";
|
||||||
clientpassword[0] = 0;
|
clientpassword[0] = 0;
|
||||||
newname("unnamed");
|
newname("unnamed");
|
||||||
newteam("red");
|
newteam("red");
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sendpackettoserv(void *packet)
|
sendpackettoserv(void *packet)
|
||||||
|
@ -254,26 +254,30 @@ sendpackettoserv(void *packet)
|
||||||
void
|
void
|
||||||
c2sinfo(dynent *d) // send update to the server
|
c2sinfo(dynent *d) // send update to the server
|
||||||
{
|
{
|
||||||
|
@autoreleasepool {
|
||||||
if (clientnum < 0)
|
if (clientnum < 0)
|
||||||
return; // we haven't had a welcome message from the server yet
|
return; // we haven't had a welcome message from the
|
||||||
|
// server yet
|
||||||
if (lastmillis - lastupdate < 40)
|
if (lastmillis - lastupdate < 40)
|
||||||
return; // don't update faster than 25fps
|
return; // don't update faster than 25fps
|
||||||
ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, 0);
|
ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, 0);
|
||||||
uchar *start = packet->data;
|
uchar *start = packet->data;
|
||||||
uchar *p = start + 2;
|
uchar *p = start + 2;
|
||||||
bool serveriteminitdone = false;
|
bool serveriteminitdone = false;
|
||||||
if (toservermap[0]) // suggest server to change map
|
if (toservermap.length > 0) // suggest server to change map
|
||||||
{ // do this exclusively as map change may invalidate rest of update
|
{ // do this exclusively as map change may invalidate rest of
|
||||||
|
// update
|
||||||
packet->flags = ENET_PACKET_FLAG_RELIABLE;
|
packet->flags = ENET_PACKET_FLAG_RELIABLE;
|
||||||
putint(p, SV_MAPCHANGE);
|
putint(p, SV_MAPCHANGE);
|
||||||
sendstring(toservermap, p);
|
sendstring(toservermap.UTF8String, p);
|
||||||
toservermap[0] = 0;
|
toservermap = @"";
|
||||||
putint(p, nextmode);
|
putint(p, nextmode);
|
||||||
} else {
|
} else {
|
||||||
putint(p, SV_POS);
|
putint(p, SV_POS);
|
||||||
putint(p, clientnum);
|
putint(p, clientnum);
|
||||||
putint(
|
putint(
|
||||||
p, (int)(d->o.x * DMF)); // quantize coordinates to 1/16th
|
p, (int)(d->o.x *
|
||||||
|
DMF)); // quantize coordinates to 1/16th
|
||||||
// of a cube, between 1 and 3 bytes
|
// of a cube, between 1 and 3 bytes
|
||||||
putint(p, (int)(d->o.y * DMF));
|
putint(p, (int)(d->o.y * DMF));
|
||||||
putint(p, (int)(d->o.z * DMF));
|
putint(p, (int)(d->o.z * DMF));
|
||||||
|
@ -281,12 +285,14 @@ c2sinfo(dynent *d) // send update to the server
|
||||||
putint(p, (int)(d->pitch * DAF));
|
putint(p, (int)(d->pitch * DAF));
|
||||||
putint(p, (int)(d->roll * DAF));
|
putint(p, (int)(d->roll * DAF));
|
||||||
putint(
|
putint(
|
||||||
p, (int)(d->vel.x *
|
p, (int)(d->vel.x * DVF)); // quantize to 1/100,
|
||||||
DVF)); // quantize to 1/100, almost always 1 byte
|
// almost always 1 byte
|
||||||
putint(p, (int)(d->vel.y * DVF));
|
putint(p, (int)(d->vel.y * DVF));
|
||||||
putint(p, (int)(d->vel.z * DVF));
|
putint(p, (int)(d->vel.z * DVF));
|
||||||
// pack rest in 1 byte: strafe:2, move:2, onfloor:1, state:3
|
// pack rest in 1 byte: strafe:2, move:2, onfloor:1,
|
||||||
putint(p, (d->strafe & 3) | ((d->move & 3) << 2) |
|
// state:3
|
||||||
|
putint(
|
||||||
|
p, (d->strafe & 3) | ((d->move & 3) << 2) |
|
||||||
(((int)d->onfloor) << 4) |
|
(((int)d->onfloor) << 4) |
|
||||||
((editmode ? CS_EDITING : d->state) << 5));
|
((editmode ? CS_EDITING : d->state) << 5));
|
||||||
|
|
||||||
|
@ -299,7 +305,8 @@ c2sinfo(dynent *d) // send update to the server
|
||||||
senditemstoserver = false;
|
senditemstoserver = false;
|
||||||
serveriteminitdone = true;
|
serveriteminitdone = true;
|
||||||
};
|
};
|
||||||
if (ctext[0]) // player chat, not flood protected for now
|
if (ctext[0]) // player chat, not flood protected for
|
||||||
|
// now
|
||||||
{
|
{
|
||||||
packet->flags = ENET_PACKET_FLAG_RELIABLE;
|
packet->flags = ENET_PACKET_FLAG_RELIABLE;
|
||||||
putint(p, SV_TEXT);
|
putint(p, SV_TEXT);
|
||||||
|
@ -315,12 +322,13 @@ c2sinfo(dynent *d) // send update to the server
|
||||||
sendstring(player1->team, p);
|
sendstring(player1->team, p);
|
||||||
putint(p, player1->lifesequence);
|
putint(p, player1->lifesequence);
|
||||||
};
|
};
|
||||||
loopv(messages) // send messages collected during the previous
|
loopv(messages) // send messages collected during the
|
||||||
// frames
|
// previous frames
|
||||||
{
|
{
|
||||||
ivector &msg = messages[i];
|
ivector &msg = messages[i];
|
||||||
if (msg[1])
|
if (msg[1])
|
||||||
packet->flags = ENET_PACKET_FLAG_RELIABLE;
|
packet->flags =
|
||||||
|
ENET_PACKET_FLAG_RELIABLE;
|
||||||
loopi(msg[0]) putint(p, msg[i + 2]);
|
loopi(msg[0]) putint(p, msg[i + 2]);
|
||||||
};
|
};
|
||||||
messages.setsize(0);
|
messages.setsize(0);
|
||||||
|
@ -341,7 +349,8 @@ c2sinfo(dynent *d) // send update to the server
|
||||||
lastupdate = lastmillis;
|
lastupdate = lastmillis;
|
||||||
if (serveriteminitdone)
|
if (serveriteminitdone)
|
||||||
loadgamerest(); // hack
|
loadgamerest(); // hack
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gets2c() // get updates from the server
|
gets2c() // get updates from the server
|
||||||
|
|
|
@ -161,12 +161,13 @@ renderscores()
|
||||||
// sendmap/getmap commands, should be replaced by more intuitive map downloading
|
// sendmap/getmap commands, should be replaced by more intuitive map downloading
|
||||||
|
|
||||||
void
|
void
|
||||||
sendmap(char *mapname)
|
sendmap(const char *mapname)
|
||||||
{
|
{
|
||||||
|
@autoreleasepool {
|
||||||
if (*mapname)
|
if (*mapname)
|
||||||
save_world(mapname);
|
save_world(mapname);
|
||||||
changemap(mapname);
|
changemap(@(mapname));
|
||||||
mapname = getclientmap();
|
mapname = getclientmap().UTF8String;
|
||||||
int mapsize;
|
int mapsize;
|
||||||
uchar *mapdata = readmap(mapname, &mapsize);
|
uchar *mapdata = readmap(mapname, &mapsize);
|
||||||
if (!mapdata)
|
if (!mapdata)
|
||||||
|
@ -192,8 +193,10 @@ sendmap(char *mapname)
|
||||||
sendpackettoserv(packet);
|
sendpackettoserv(packet);
|
||||||
conoutf(@"sending map %s to server...", mapname);
|
conoutf(@"sending map %s to server...", mapname);
|
||||||
sprintf_sd(msg)(
|
sprintf_sd(msg)(
|
||||||
"[map %s uploaded to server, \"getmap\" to receive it]", mapname);
|
"[map %s uploaded to server, \"getmap\" to receive it]",
|
||||||
|
mapname);
|
||||||
toserver(msg);
|
toserver(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -210,5 +213,5 @@ getmap()
|
||||||
conoutf(@"requesting map from server...");
|
conoutf(@"requesting map from server...");
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(sendmap, ARG_1STR);
|
COMMAND(sendmap, ARG_1CSTR)
|
||||||
COMMAND(getmap, ARG_NONE);
|
COMMAND(getmap, ARG_NONE)
|
||||||
|
|
|
@ -10,7 +10,7 @@ mode(int n)
|
||||||
{
|
{
|
||||||
addmsg(1, 2, SV_GAMEMODE, nextmode = n);
|
addmsg(1, 2, SV_GAMEMODE, nextmode = n);
|
||||||
};
|
};
|
||||||
COMMAND(mode, ARG_1INT);
|
COMMAND(mode, ARG_1INT)
|
||||||
|
|
||||||
bool intermission = false;
|
bool intermission = false;
|
||||||
|
|
||||||
|
@ -23,15 +23,15 @@ VARP(invmouse, 0, 0, 1);
|
||||||
|
|
||||||
int lastmillis = 0;
|
int lastmillis = 0;
|
||||||
int curtime = 10;
|
int curtime = 10;
|
||||||
string clientmap;
|
OFString *clientmap;
|
||||||
|
|
||||||
extern int framesinmap;
|
extern int framesinmap;
|
||||||
|
|
||||||
char *
|
OFString *
|
||||||
getclientmap()
|
getclientmap()
|
||||||
{
|
{
|
||||||
return clientmap;
|
return clientmap;
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
resetmovement(dynent *d)
|
resetmovement(dynent *d)
|
||||||
|
@ -220,15 +220,15 @@ respawn()
|
||||||
if (m_arena) {
|
if (m_arena) {
|
||||||
conoutf(@"waiting for new round to start...");
|
conoutf(@"waiting for new round to start...");
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
if (m_sp) {
|
if (m_sp) {
|
||||||
nextmode = gamemode;
|
nextmode = gamemode;
|
||||||
changemap(clientmap);
|
changemap(clientmap);
|
||||||
return;
|
return;
|
||||||
}; // if we die in SP we try the same map again
|
} // if we die in SP we try the same map again
|
||||||
respawnself();
|
respawnself();
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
int sleepwait = 0;
|
int sleepwait = 0;
|
||||||
string sleepcmd;
|
string sleepcmd;
|
||||||
|
@ -238,7 +238,7 @@ sleepf(char *msec, char *cmd)
|
||||||
sleepwait = atoi(msec) + lastmillis;
|
sleepwait = atoi(msec) + lastmillis;
|
||||||
strcpy_s(sleepcmd, cmd);
|
strcpy_s(sleepcmd, cmd);
|
||||||
};
|
};
|
||||||
COMMANDN(sleep, sleepf, ARG_2STR);
|
COMMANDN(sleep, sleepf, ARG_2STR)
|
||||||
|
|
||||||
void
|
void
|
||||||
updateworld(int millis) // main game update loop
|
updateworld(int millis) // main game update loop
|
||||||
|
@ -361,13 +361,13 @@ jumpn(bool on)
|
||||||
respawn();
|
respawn();
|
||||||
};
|
};
|
||||||
|
|
||||||
COMMAND(backward, ARG_DOWN);
|
COMMAND(backward, ARG_DOWN)
|
||||||
COMMAND(forward, ARG_DOWN);
|
COMMAND(forward, ARG_DOWN)
|
||||||
COMMAND(left, ARG_DOWN);
|
COMMAND(left, ARG_DOWN)
|
||||||
COMMAND(right, ARG_DOWN);
|
COMMAND(right, ARG_DOWN)
|
||||||
COMMANDN(jump, jumpn, ARG_DOWN);
|
COMMANDN(jump, jumpn, ARG_DOWN)
|
||||||
COMMAND(attack, ARG_DOWN);
|
COMMAND(attack, ARG_DOWN)
|
||||||
COMMAND(showscores, ARG_DOWN);
|
COMMAND(showscores, ARG_DOWN)
|
||||||
|
|
||||||
void
|
void
|
||||||
fixplayer1range()
|
fixplayer1range()
|
||||||
|
@ -484,9 +484,9 @@ getclient(int cn) // ensure valid entity
|
||||||
void
|
void
|
||||||
initclient()
|
initclient()
|
||||||
{
|
{
|
||||||
clientmap[0] = 0;
|
clientmap = @"";
|
||||||
initclientnet();
|
initclientnet();
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
startmap(char *name) // called just after a map load
|
startmap(char *name) // called just after a map load
|
||||||
|
@ -503,7 +503,9 @@ startmap(char *name) // called just after a map load
|
||||||
player1->frags = 0;
|
player1->frags = 0;
|
||||||
loopv(players) if (players[i]) players[i]->frags = 0;
|
loopv(players) if (players[i]) players[i]->frags = 0;
|
||||||
resetspawns();
|
resetspawns();
|
||||||
strcpy_s(clientmap, name);
|
@autoreleasepool {
|
||||||
|
clientmap = @(name);
|
||||||
|
}
|
||||||
if (editmode)
|
if (editmode)
|
||||||
toggleedit();
|
toggleedit();
|
||||||
setvar("gamespeed", 100);
|
setvar("gamespeed", 100);
|
||||||
|
@ -513,6 +515,6 @@ startmap(char *name) // called just after a map load
|
||||||
intermission = false;
|
intermission = false;
|
||||||
framesinmap = 0;
|
framesinmap = 0;
|
||||||
conoutf(@"game mode is %s", modestr(gamemode));
|
conoutf(@"game mode is %s", modestr(gamemode));
|
||||||
};
|
}
|
||||||
|
|
||||||
COMMANDN(map, changemap, ARG_1STR);
|
COMMANDN(map, changemap, ARG_1STR)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
extern int clientnum;
|
extern int clientnum;
|
||||||
extern bool c2sinit, senditemstoserver;
|
extern bool c2sinit, senditemstoserver;
|
||||||
extern string toservermap;
|
extern OFString *toservermap;
|
||||||
extern string clientpassword;
|
extern string clientpassword;
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -12,20 +12,20 @@ neterr(char *s)
|
||||||
{
|
{
|
||||||
conoutf(@"illegal network message (%s)", s);
|
conoutf(@"illegal network message (%s)", s);
|
||||||
disconnect();
|
disconnect();
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
changemapserv(char *name, int mode) // forced map change from the server
|
changemapserv(char *name, int mode) // forced map change from the server
|
||||||
{
|
{
|
||||||
gamemode = mode;
|
gamemode = mode;
|
||||||
load_world(name);
|
load_world(name);
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
changemap(char *name) // request map change, server may ignore
|
changemap(OFString *name) // request map change, server may ignore
|
||||||
{
|
{
|
||||||
strcpy_s(toservermap, name);
|
toservermap = name;
|
||||||
};
|
}
|
||||||
|
|
||||||
// update the position of other clients in the game in our world
|
// update the position of other clients in the game in our world
|
||||||
// don't care if he's in the scenery or other players,
|
// don't care if he's in the scenery or other players,
|
||||||
|
@ -82,12 +82,12 @@ localservertoclient(
|
||||||
disconnect();
|
disconnect();
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
toservermap[0] = 0;
|
toservermap = @"";
|
||||||
clientnum = cn; // we are now fully connected
|
clientnum = cn; // we are now fully connected
|
||||||
if (!getint(p))
|
if (!getint(p))
|
||||||
strcpy_s(toservermap,
|
// we are the first client on this server, set
|
||||||
getclientmap()); // we are the first client
|
// map
|
||||||
// on this server, set map
|
toservermap = getclientmap();
|
||||||
sgetstr();
|
sgetstr();
|
||||||
if (text[0] && strcmp(text, clientpassword)) {
|
if (text[0] && strcmp(text, clientpassword)) {
|
||||||
conoutf(@"you need to set the correct password "
|
conoutf(@"you need to set the correct password "
|
||||||
|
@ -160,10 +160,11 @@ localservertoclient(
|
||||||
case SV_MAPRELOAD: // server requests next map
|
case SV_MAPRELOAD: // server requests next map
|
||||||
{
|
{
|
||||||
getint(p);
|
getint(p);
|
||||||
sprintf_sd(nextmapalias)("nextmap_%s", getclientmap());
|
OFString *nextmapalias = [OFString
|
||||||
char *map =
|
stringWithFormat:@"nextmap_%@", getclientmap()];
|
||||||
|
OFString *map =
|
||||||
getalias(nextmapalias); // look up map in the cycle
|
getalias(nextmapalias); // look up map in the cycle
|
||||||
changemap(map ? map : getclientmap());
|
changemap(map != nil ? map : getclientmap());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
113
src/command.mm
113
src/command.mm
|
@ -7,12 +7,12 @@ enum { ID_VAR, ID_COMMAND, ID_ALIAS };
|
||||||
|
|
||||||
@interface Ident : OFObject
|
@interface Ident : OFObject
|
||||||
@property (nonatomic) int type; // one of ID_* above
|
@property (nonatomic) int type; // one of ID_* above
|
||||||
@property (nonatomic) char *name;
|
@property (copy, nonatomic) OFString *name;
|
||||||
@property (nonatomic) int min, max; // ID_VAR
|
@property (nonatomic) int min, max; // ID_VAR
|
||||||
@property (nonatomic) int *storage; // ID_VAR
|
@property (nonatomic) int *storage; // ID_VAR
|
||||||
@property (nonatomic) void (*fun)(); // ID_VAR, ID_COMMAND
|
@property (nonatomic) void (*fun)(); // ID_VAR, ID_COMMAND
|
||||||
@property (nonatomic) int narg; // ID_VAR, ID_COMMAND
|
@property (nonatomic) int narg; // ID_VAR, ID_COMMAND
|
||||||
@property (nonatomic) char *action; // ID_ALIAS
|
@property (copy, nonatomic) OFString *action; // ID_ALIAS
|
||||||
@property (nonatomic) bool persist;
|
@property (nonatomic) bool persist;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ itoa(char *s, int i)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
exchangestr(char *o, char *n)
|
exchangestr(char *o, const char *n)
|
||||||
{
|
{
|
||||||
gp()->deallocstr(o);
|
gp()->deallocstr(o);
|
||||||
return newstring(n);
|
return newstring(n);
|
||||||
|
@ -44,14 +44,14 @@ alias(char *name, char *action)
|
||||||
if (!b) {
|
if (!b) {
|
||||||
Ident *b = [[Ident alloc] init];
|
Ident *b = [[Ident alloc] init];
|
||||||
b.type = ID_ALIAS;
|
b.type = ID_ALIAS;
|
||||||
b.name = newstring(name);
|
b.name = @(name);
|
||||||
b.action = newstring(action);
|
b.action = @(action);
|
||||||
b.persist = true;
|
b.persist = true;
|
||||||
|
|
||||||
idents[@(name)] = b;
|
idents[b.name] = b;
|
||||||
} else {
|
} else {
|
||||||
if (b.type == ID_ALIAS)
|
if (b.type == ID_ALIAS)
|
||||||
b.action = exchangestr(b.action, action);
|
b.action = @(action);
|
||||||
else
|
else
|
||||||
conoutf(
|
conoutf(
|
||||||
@"cannot redefine builtin %s with an alias",
|
@"cannot redefine builtin %s with an alias",
|
||||||
|
@ -72,14 +72,14 @@ variable(char *name, int min, int cur, int max, int *storage, void (*fun)(),
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
Ident *v = [[Ident alloc] init];
|
Ident *v = [[Ident alloc] init];
|
||||||
v.type = ID_VAR;
|
v.type = ID_VAR;
|
||||||
v.name = name;
|
v.name = @(name);
|
||||||
v.min = min;
|
v.min = min;
|
||||||
v.max = max;
|
v.max = max;
|
||||||
v.storage = storage;
|
v.storage = storage;
|
||||||
v.fun = fun;
|
v.fun = fun;
|
||||||
v.persist = persist;
|
v.persist = persist;
|
||||||
|
|
||||||
idents[@(name)] = v;
|
idents[v.name] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cur;
|
return cur;
|
||||||
|
@ -109,17 +109,15 @@ identexists(char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
OFString *
|
||||||
getalias(char *name)
|
getalias(OFString *name)
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
Ident *i = idents[name];
|
||||||
Ident *i = idents[@(name)];
|
return i != nil && i.type == ID_ALIAS ? i.action : nil;
|
||||||
return i != nil && i.type == ID_ALIAS ? i.action : NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
addcommand(char *name, void (*fun)(), int narg)
|
addcommand(OFString *name, void (*fun)(), int narg)
|
||||||
{
|
{
|
||||||
if (idents == nil)
|
if (idents == nil)
|
||||||
idents = [[OFMutableDictionary alloc] init];
|
idents = [[OFMutableDictionary alloc] init];
|
||||||
|
@ -131,7 +129,7 @@ addcommand(char *name, void (*fun)(), int narg)
|
||||||
c.fun = fun;
|
c.fun = fun;
|
||||||
c.narg = narg;
|
c.narg = narg;
|
||||||
|
|
||||||
idents[@(name)] = c;
|
idents[name] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -206,7 +204,7 @@ lookup(char *n) // find value of ident referenced with $ in exp
|
||||||
itoa(t, *(ID.storage));
|
itoa(t, *(ID.storage));
|
||||||
return exchangestr(n, t);
|
return exchangestr(n, t);
|
||||||
case ID_ALIAS:
|
case ID_ALIAS:
|
||||||
return exchangestr(n, ID.action);
|
return exchangestr(n, ID.action.UTF8String);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,7 +296,7 @@ execute(char *p, bool isdown) // all evaluation happens here, recursively
|
||||||
((void(__cdecl *)())
|
((void(__cdecl *)())
|
||||||
ID.fun)();
|
ID.fun)();
|
||||||
break;
|
break;
|
||||||
case ARG_1STR:
|
case ARG_1CSTR:
|
||||||
if (isdown)
|
if (isdown)
|
||||||
((void(__cdecl *)(
|
((void(__cdecl *)(
|
||||||
char *))ID.fun)(
|
char *))ID.fun)(
|
||||||
|
@ -385,6 +383,17 @@ execute(char *p, bool isdown) // all evaluation happens here, recursively
|
||||||
char *))ID.fun)(r);
|
char *))ID.fun)(r);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ARG_1STR:
|
||||||
|
if (isdown) {
|
||||||
|
@autoreleasepool {
|
||||||
|
((void(
|
||||||
|
__cdecl *)(
|
||||||
|
OFString *))
|
||||||
|
ID.fun)(
|
||||||
|
@(w[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -478,7 +487,8 @@ execute(char *p, bool isdown) // all evaluation happens here, recursively
|
||||||
}
|
}
|
||||||
// create new string here because alias
|
// create new string here because alias
|
||||||
// could rebind itself
|
// could rebind itself
|
||||||
char *action = newstring(ID.action);
|
char *action =
|
||||||
|
newstring(ID.action.UTF8String);
|
||||||
val = execute(action, isdown);
|
val = execute(action, isdown);
|
||||||
gp()->deallocstr(action);
|
gp()->deallocstr(action);
|
||||||
break;
|
break;
|
||||||
|
@ -519,10 +529,10 @@ complete(char *s)
|
||||||
__block int idx = 0;
|
__block int idx = 0;
|
||||||
[idents enumerateKeysAndObjectsUsingBlock:^(
|
[idents enumerateKeysAndObjectsUsingBlock:^(
|
||||||
OFString *name, Ident *ident, bool *stop) {
|
OFString *name, Ident *ident, bool *stop) {
|
||||||
if (strncmp(ident.name, s + 1, completesize) == 0 &&
|
if (strncmp(ident.name.UTF8String, s + 1, completesize) == 0 &&
|
||||||
idx++ == completeidx) {
|
idx++ == completeidx) {
|
||||||
strcpy_s(s, "/");
|
strcpy_s(s, "/");
|
||||||
strcat_s(s, ident.name);
|
strcat_s(s, ident.name.UTF8String);
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
completeidx++;
|
completeidx++;
|
||||||
|
@ -565,7 +575,8 @@ writecfg()
|
||||||
[idents enumerateKeysAndObjectsUsingBlock:^(
|
[idents enumerateKeysAndObjectsUsingBlock:^(
|
||||||
OFString *name, Ident *ident, bool *stop) {
|
OFString *name, Ident *ident, bool *stop) {
|
||||||
if (ident.type == ID_VAR && ident.persist) {
|
if (ident.type == ID_VAR && ident.persist) {
|
||||||
fprintf(f, "%s %d\n", ident.name, *ident.storage);
|
fprintf(f, "%s %d\n", ident.name.UTF8String,
|
||||||
|
*ident.storage);
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
|
@ -573,15 +584,16 @@ writecfg()
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
[idents enumerateKeysAndObjectsUsingBlock:^(
|
[idents enumerateKeysAndObjectsUsingBlock:^(
|
||||||
OFString *name, Ident *ident, bool *stop) {
|
OFString *name, Ident *ident, bool *stop) {
|
||||||
if (ident.type == ID_ALIAS && !strstr(ident.name, "nextmap_")) {
|
if (ident.type == ID_ALIAS &&
|
||||||
fprintf(
|
!strstr(ident.name.UTF8String, "nextmap_")) {
|
||||||
f, "alias \"%s\" [%s]\n", ident.name, ident.action);
|
fprintf(f, "alias \"%s\" [%s]\n", ident.name.UTF8String,
|
||||||
|
ident.action.UTF8String);
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(writecfg, ARG_NONE);
|
COMMAND(writecfg, ARG_NONE)
|
||||||
|
|
||||||
// below the commands that implement a small imperative language. thanks to the
|
// below the commands that implement a small imperative language. thanks to the
|
||||||
// semantics of
|
// semantics of
|
||||||
|
@ -662,82 +674,89 @@ at(char *s, char *pos)
|
||||||
concat(s);
|
concat(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMANDN(loop, loopa, ARG_2STR);
|
COMMANDN(loop, loopa, ARG_2STR)
|
||||||
COMMANDN(while, whilea, ARG_2STR);
|
COMMANDN(while, whilea, ARG_2STR)
|
||||||
COMMANDN(if, ifthen, ARG_3STR);
|
COMMANDN(if, ifthen, ARG_3STR)
|
||||||
COMMAND(onrelease, ARG_DWN1);
|
COMMAND(onrelease, ARG_DWN1)
|
||||||
COMMAND(exec, ARG_1STR);
|
COMMAND(exec, ARG_1CSTR)
|
||||||
COMMAND(concat, ARG_VARI);
|
COMMAND(concat, ARG_VARI)
|
||||||
COMMAND(concatword, ARG_VARI);
|
COMMAND(concatword, ARG_VARI)
|
||||||
COMMAND(at, ARG_2STR);
|
COMMAND(at, ARG_2STR)
|
||||||
COMMAND(listlen, ARG_1EST);
|
COMMAND(listlen, ARG_1EST)
|
||||||
|
|
||||||
int
|
int
|
||||||
add(int a, int b)
|
add(int a, int b)
|
||||||
{
|
{
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
COMMANDN(+, add, ARG_2EXP);
|
COMMANDN(+, add, ARG_2EXP)
|
||||||
|
|
||||||
int
|
int
|
||||||
mul(int a, int b)
|
mul(int a, int b)
|
||||||
{
|
{
|
||||||
return a * b;
|
return a * b;
|
||||||
}
|
}
|
||||||
COMMANDN(*, mul, ARG_2EXP);
|
COMMANDN(*, mul, ARG_2EXP)
|
||||||
|
|
||||||
int
|
int
|
||||||
sub(int a, int b)
|
sub(int a, int b)
|
||||||
{
|
{
|
||||||
return a - b;
|
return a - b;
|
||||||
}
|
}
|
||||||
COMMANDN(-, sub, ARG_2EXP);
|
COMMANDN(-, sub, ARG_2EXP)
|
||||||
|
|
||||||
int
|
int
|
||||||
divi(int a, int b)
|
divi(int a, int b)
|
||||||
{
|
{
|
||||||
return b ? a / b : 0;
|
return b ? a / b : 0;
|
||||||
}
|
}
|
||||||
COMMANDN(div, divi, ARG_2EXP);
|
COMMANDN(div, divi, ARG_2EXP)
|
||||||
|
|
||||||
int
|
int
|
||||||
mod(int a, int b)
|
mod(int a, int b)
|
||||||
{
|
{
|
||||||
return b ? a % b : 0;
|
return b ? a % b : 0;
|
||||||
}
|
}
|
||||||
COMMAND(mod, ARG_2EXP);
|
COMMAND(mod, ARG_2EXP)
|
||||||
|
|
||||||
int
|
int
|
||||||
equal(int a, int b)
|
equal(int a, int b)
|
||||||
{
|
{
|
||||||
return (int)(a == b);
|
return (int)(a == b);
|
||||||
}
|
}
|
||||||
COMMANDN(=, equal, ARG_2EXP);
|
COMMANDN(=, equal, ARG_2EXP)
|
||||||
|
|
||||||
int
|
int
|
||||||
lt(int a, int b)
|
lt(int a, int b)
|
||||||
{
|
{
|
||||||
return (int)(a < b);
|
return (int)(a < b);
|
||||||
}
|
}
|
||||||
COMMANDN(<, lt, ARG_2EXP);
|
COMMANDN(<, lt, ARG_2EXP)
|
||||||
|
|
||||||
int
|
int
|
||||||
gt(int a, int b)
|
gt(int a, int b)
|
||||||
{
|
{
|
||||||
return (int)(a > b);
|
return (int)(a > b);
|
||||||
}
|
}
|
||||||
COMMANDN(>, gt, ARG_2EXP);
|
COMMANDN(>, gt, ARG_2EXP)
|
||||||
|
|
||||||
int
|
int
|
||||||
strcmpa(char *a, char *b)
|
strcmpa(char *a, char *b)
|
||||||
{
|
{
|
||||||
return strcmp(a, b) == 0;
|
return strcmp(a, b) == 0;
|
||||||
}
|
}
|
||||||
COMMANDN(strcmp, strcmpa, ARG_2EST);
|
COMMANDN(strcmp, strcmpa, ARG_2EST)
|
||||||
|
|
||||||
int
|
int
|
||||||
rndn(int a)
|
rndn(int a)
|
||||||
{
|
{
|
||||||
return a > 0 ? rnd(a) : 0;
|
return a > 0 ? rnd(a) : 0;
|
||||||
}
|
}
|
||||||
COMMANDN(rnd, rndn, ARG_1EXP);
|
COMMANDN(rnd, rndn, ARG_1EXP)
|
||||||
|
|
||||||
int
|
int
|
||||||
explastmillis()
|
explastmillis()
|
||||||
{
|
{
|
||||||
return lastmillis;
|
return lastmillis;
|
||||||
}
|
}
|
||||||
COMMANDN(millis, explastmillis, ARG_1EXP);
|
COMMANDN(millis, explastmillis, ARG_1EXP)
|
||||||
|
|
|
@ -22,9 +22,8 @@ setconskip(int n)
|
||||||
conskip += n;
|
conskip += n;
|
||||||
if (conskip < 0)
|
if (conskip < 0)
|
||||||
conskip = 0;
|
conskip = 0;
|
||||||
};
|
}
|
||||||
|
COMMANDN(conskip, setconskip, ARG_1INT)
|
||||||
COMMANDN(conskip, setconskip, ARG_1INT);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
conline(const char *sf, bool highlight) // add a line to the console buffer
|
conline(const char *sf, bool highlight) // add a line to the console buffer
|
||||||
|
@ -100,9 +99,8 @@ keymap(char *code, char *key, char *action)
|
||||||
keyms[numkm].code = atoi(code);
|
keyms[numkm].code = atoi(code);
|
||||||
keyms[numkm].name = newstring(key);
|
keyms[numkm].name = newstring(key);
|
||||||
keyms[numkm++].action = newstringbuf(action);
|
keyms[numkm++].action = newstringbuf(action);
|
||||||
};
|
}
|
||||||
|
COMMAND(keymap, ARG_3STR)
|
||||||
COMMAND(keymap, ARG_3STR);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
bindkey(char *key, char *action)
|
bindkey(char *key, char *action)
|
||||||
|
@ -115,9 +113,8 @@ bindkey(char *key, char *action)
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
conoutf(@"unknown key \"%s\"", key);
|
conoutf(@"unknown key \"%s\"", key);
|
||||||
};
|
}
|
||||||
|
COMMANDN(bind, bindkey, ARG_2STR)
|
||||||
COMMANDN(bind, bindkey, ARG_2STR);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
saycommand(char *init) // turns input to the command line on or off
|
saycommand(char *init) // turns input to the command line on or off
|
||||||
|
@ -134,10 +131,10 @@ void
|
||||||
mapmsg(char *s)
|
mapmsg(char *s)
|
||||||
{
|
{
|
||||||
strn0cpy(hdr.maptitle, s, 128);
|
strn0cpy(hdr.maptitle, s, 128);
|
||||||
};
|
}
|
||||||
|
|
||||||
COMMAND(saycommand, ARG_VARI);
|
COMMAND(saycommand, ARG_VARI)
|
||||||
COMMAND(mapmsg, ARG_1STR);
|
COMMAND(mapmsg, ARG_1CSTR)
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
# include <SDL_syswm.h>
|
# include <SDL_syswm.h>
|
||||||
|
@ -198,9 +195,8 @@ history(int n)
|
||||||
execute(vhistory[vhistory.length() - n - 1]);
|
execute(vhistory[vhistory.length() - n - 1]);
|
||||||
rec = false;
|
rec = false;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
COMMAND(history, ARG_1INT)
|
||||||
COMMAND(history, ARG_1INT);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
keypress(int code, bool isdown, int cooked)
|
keypress(int code, bool isdown, int cooked)
|
||||||
|
|
|
@ -379,7 +379,7 @@ enum // function signatures for script functions, see command.cpp
|
||||||
ARG_3INT,
|
ARG_3INT,
|
||||||
ARG_4INT,
|
ARG_4INT,
|
||||||
ARG_NONE,
|
ARG_NONE,
|
||||||
ARG_1STR,
|
ARG_1CSTR,
|
||||||
ARG_2STR,
|
ARG_2STR,
|
||||||
ARG_3STR,
|
ARG_3STR,
|
||||||
ARG_5STR,
|
ARG_5STR,
|
||||||
|
@ -389,7 +389,8 @@ enum // function signatures for script functions, see command.cpp
|
||||||
ARG_2EXP,
|
ARG_2EXP,
|
||||||
ARG_1EST,
|
ARG_1EST,
|
||||||
ARG_2EST,
|
ARG_2EST,
|
||||||
ARG_VARI
|
ARG_VARI,
|
||||||
|
ARG_1STR
|
||||||
};
|
};
|
||||||
|
|
||||||
// nasty macros for registering script functions, abuses globals to avoid
|
// nasty macros for registering script functions, abuses globals to avoid
|
||||||
|
@ -398,7 +399,7 @@ enum // function signatures for script functions, see command.cpp
|
||||||
OF_CONSTRUCTOR() \
|
OF_CONSTRUCTOR() \
|
||||||
{ \
|
{ \
|
||||||
enqueueInit(^{ \
|
enqueueInit(^{ \
|
||||||
addcommand(#name, (void (*)())fun, nargs); \
|
addcommand(@ #name, (void (*)())fun, nargs); \
|
||||||
}); \
|
}); \
|
||||||
}
|
}
|
||||||
#define COMMAND(name, nargs) COMMANDN(name, name, nargs)
|
#define COMMAND(name, nargs) COMMANDN(name, name, nargs)
|
||||||
|
|
|
@ -65,9 +65,8 @@ toggleedit()
|
||||||
keyrepeat(editmode);
|
keyrepeat(editmode);
|
||||||
selset = false;
|
selset = false;
|
||||||
editing = editmode;
|
editing = editmode;
|
||||||
};
|
}
|
||||||
|
COMMANDN(edittoggle, toggleedit, ARG_NONE)
|
||||||
COMMANDN(edittoggle, toggleedit, ARG_NONE);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
correctsel() // ensures above invariant
|
correctsel() // ensures above invariant
|
||||||
|
@ -355,9 +354,8 @@ editheight(int flr, int amount)
|
||||||
bool isfloor = flr == 0;
|
bool isfloor = flr == 0;
|
||||||
editheightxy(isfloor, amount, sel);
|
editheightxy(isfloor, amount, sel);
|
||||||
addmsg(1, 7, SV_EDITH, sel.x, sel.y, sel.xs, sel.ys, isfloor, amount);
|
addmsg(1, 7, SV_EDITH, sel.x, sel.y, sel.xs, sel.ys, isfloor, amount);
|
||||||
};
|
}
|
||||||
|
COMMAND(editheight, ARG_2INT)
|
||||||
COMMAND(editheight, ARG_2INT);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
edittexxy(int type, int t, block &sel)
|
edittexxy(int type, int t, block &sel)
|
||||||
|
@ -451,21 +449,22 @@ void
|
||||||
heightfield(int t)
|
heightfield(int t)
|
||||||
{
|
{
|
||||||
edittype(t == 0 ? FHF : CHF);
|
edittype(t == 0 ? FHF : CHF);
|
||||||
};
|
}
|
||||||
|
COMMAND(heightfield, ARG_1INT)
|
||||||
|
|
||||||
void
|
void
|
||||||
solid(int t)
|
solid(int t)
|
||||||
{
|
{
|
||||||
edittype(t == 0 ? SPACE : SOLID);
|
edittype(t == 0 ? SPACE : SOLID);
|
||||||
};
|
}
|
||||||
|
COMMAND(solid, ARG_1INT)
|
||||||
|
|
||||||
void
|
void
|
||||||
corner()
|
corner()
|
||||||
{
|
{
|
||||||
edittype(CORNER);
|
edittype(CORNER);
|
||||||
};
|
}
|
||||||
|
COMMAND(corner, ARG_NONE)
|
||||||
COMMAND(heightfield, ARG_1INT);
|
|
||||||
COMMAND(solid, ARG_1INT);
|
|
||||||
COMMAND(corner, ARG_NONE);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
editequalisexy(bool isfloor, block &sel)
|
editequalisexy(bool isfloor, block &sel)
|
||||||
|
@ -494,9 +493,8 @@ equalize(int flr)
|
||||||
EDITSEL;
|
EDITSEL;
|
||||||
editequalisexy(isfloor, sel);
|
editequalisexy(isfloor, sel);
|
||||||
addmsg(1, 6, SV_EDITE, sel.x, sel.y, sel.xs, sel.ys, isfloor);
|
addmsg(1, 6, SV_EDITE, sel.x, sel.y, sel.xs, sel.ys, isfloor);
|
||||||
};
|
}
|
||||||
|
COMMAND(equalize, ARG_1INT)
|
||||||
COMMAND(equalize, ARG_1INT);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
setvdeltaxy(int delta, block &sel)
|
setvdeltaxy(int delta, block &sel)
|
||||||
|
@ -602,16 +600,16 @@ newent(char *what, char *a1, char *a2, char *a3, char *a4)
|
||||||
ATOI(a3), ATOI(a4));
|
ATOI(a3), ATOI(a4));
|
||||||
};
|
};
|
||||||
|
|
||||||
COMMANDN(select, selectpos, ARG_4INT);
|
COMMANDN(select, selectpos, ARG_4INT)
|
||||||
COMMAND(edittag, ARG_1INT);
|
COMMAND(edittag, ARG_1INT)
|
||||||
COMMAND(replace, ARG_NONE);
|
COMMAND(replace, ARG_NONE)
|
||||||
COMMAND(archvertex, ARG_3INT);
|
COMMAND(archvertex, ARG_3INT)
|
||||||
COMMAND(arch, ARG_2INT);
|
COMMAND(arch, ARG_2INT)
|
||||||
COMMAND(slope, ARG_2INT);
|
COMMAND(slope, ARG_2INT)
|
||||||
COMMANDN(vdelta, setvdelta, ARG_1INT);
|
COMMANDN(vdelta, setvdelta, ARG_1INT)
|
||||||
COMMANDN(undo, editundo, ARG_NONE);
|
COMMANDN(undo, editundo, ARG_NONE)
|
||||||
COMMAND(copy, ARG_NONE);
|
COMMAND(copy, ARG_NONE)
|
||||||
COMMAND(paste, ARG_NONE);
|
COMMAND(paste, ARG_NONE)
|
||||||
COMMAND(edittex, ARG_2INT);
|
COMMAND(edittex, ARG_2INT)
|
||||||
COMMAND(newent, ARG_5STR);
|
COMMAND(newent, ARG_5STR)
|
||||||
COMMAND(perlin, ARG_3INT);
|
COMMAND(perlin, ARG_3INT)
|
||||||
|
|
12
src/init.mm
12
src/init.mm
|
@ -3,22 +3,22 @@
|
||||||
#import "cube.h"
|
#import "cube.h"
|
||||||
#import "protos.h"
|
#import "protos.h"
|
||||||
|
|
||||||
static OFMutableArray<void (^)(void)> *queue;
|
static std::vector<void (^)(void)> *queue;
|
||||||
|
|
||||||
void
|
void
|
||||||
enqueueInit(void (^init)(void))
|
enqueueInit(void (^init)(void))
|
||||||
{
|
{
|
||||||
if (queue == nil)
|
if (queue == NULL)
|
||||||
queue = [[OFMutableArray alloc] init];
|
queue = new std::vector<void (^)(void)>();
|
||||||
|
|
||||||
[queue addObject:init];
|
queue->push_back(init);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
processInitQueue(void)
|
processInitQueue(void)
|
||||||
{
|
{
|
||||||
for (void (^init)(void) in queue)
|
for (auto &init : *queue)
|
||||||
init();
|
init();
|
||||||
|
|
||||||
[queue removeAllObjects];
|
queue->clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,11 +127,11 @@ menuitem(char *text, char *action)
|
||||||
mitem &mi = menu.items.add();
|
mitem &mi = menu.items.add();
|
||||||
mi.text = newstring(text);
|
mi.text = newstring(text);
|
||||||
mi.action = action[0] ? newstring(action) : mi.text;
|
mi.action = action[0] ? newstring(action) : mi.text;
|
||||||
};
|
}
|
||||||
|
COMMAND(menuitem, ARG_2STR)
|
||||||
|
|
||||||
COMMAND(menuitem, ARG_2STR);
|
COMMAND(showmenu, ARG_1CSTR)
|
||||||
COMMAND(showmenu, ARG_1STR);
|
COMMAND(newmenu, ARG_1CSTR)
|
||||||
COMMAND(newmenu, ARG_1STR);
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
menukey(int code, bool isdown)
|
menukey(int code, bool isdown)
|
||||||
|
|
12
src/protos.h
12
src/protos.h
|
@ -6,14 +6,14 @@ extern int variable(char *name, int min, int cur, int max, int *storage,
|
||||||
extern void setvar(char *name, int i);
|
extern void setvar(char *name, int i);
|
||||||
extern int getvar(char *name);
|
extern int getvar(char *name);
|
||||||
extern bool identexists(char *name);
|
extern bool identexists(char *name);
|
||||||
extern bool addcommand(char *name, void (*fun)(), int narg);
|
extern bool addcommand(OFString *name, void (*fun)(), int narg);
|
||||||
extern int execute(char *p, bool down = true);
|
extern int execute(char *p, bool down = true);
|
||||||
extern void exec(char *cfgfile);
|
extern void exec(char *cfgfile);
|
||||||
extern bool execfile(char *cfgfile);
|
extern bool execfile(char *cfgfile);
|
||||||
extern void resetcomplete();
|
extern void resetcomplete();
|
||||||
extern void complete(char *s);
|
extern void complete(char *s);
|
||||||
extern void alias(char *name, char *action);
|
extern void alias(char *name, char *action);
|
||||||
extern char *getalias(char *name);
|
extern OFString *getalias(OFString *name);
|
||||||
extern void writecfg();
|
extern void writecfg();
|
||||||
|
|
||||||
// console
|
// console
|
||||||
|
@ -90,12 +90,12 @@ extern void writeclientinfo(FILE *f);
|
||||||
extern void mousemove(int dx, int dy);
|
extern void mousemove(int dx, int dy);
|
||||||
extern void updateworld(int millis);
|
extern void updateworld(int millis);
|
||||||
extern void startmap(char *name);
|
extern void startmap(char *name);
|
||||||
extern void changemap(char *name);
|
extern void changemap(OFString *name);
|
||||||
extern void initclient();
|
extern void initclient();
|
||||||
extern void spawnplayer(dynent *d);
|
extern void spawnplayer(dynent *d);
|
||||||
extern void selfdamage(int damage, int actor, dynent *act);
|
extern void selfdamage(int damage, int actor, dynent *act);
|
||||||
extern dynent *newdynent();
|
extern dynent *newdynent();
|
||||||
extern char *getclientmap();
|
extern OFString *getclientmap();
|
||||||
extern const char *modestr(int n);
|
extern const char *modestr(int n);
|
||||||
extern void zapdynent(dynent *&d);
|
extern void zapdynent(dynent *&d);
|
||||||
extern dynent *getclient(int cn);
|
extern dynent *getclient(int cn);
|
||||||
|
@ -182,10 +182,10 @@ extern void particle_trail(int type, int fade, vec &from, vec &to);
|
||||||
extern void render_particles(int time);
|
extern void render_particles(int time);
|
||||||
|
|
||||||
// worldio
|
// worldio
|
||||||
extern void save_world(char *fname);
|
extern void save_world(const char *fname);
|
||||||
extern void load_world(char *mname);
|
extern void load_world(char *mname);
|
||||||
extern void writemap(char *mname, int msize, uchar *mdata);
|
extern void writemap(char *mname, int msize, uchar *mdata);
|
||||||
extern uchar *readmap(char *mname, int *msize);
|
extern uchar *readmap(const char *mname, int *msize);
|
||||||
extern void loadgamerest();
|
extern void loadgamerest();
|
||||||
extern void incomingdemodata(uchar *buf, int len, bool extras = false);
|
extern void incomingdemodata(uchar *buf, int len, bool extras = false);
|
||||||
extern void demoplaybackstep();
|
extern void demoplaybackstep();
|
||||||
|
|
|
@ -66,15 +66,15 @@ void
|
||||||
showmip()
|
showmip()
|
||||||
{
|
{
|
||||||
showm = !showm;
|
showm = !showm;
|
||||||
};
|
}
|
||||||
|
COMMAND(showmip, ARG_NONE)
|
||||||
|
|
||||||
void
|
void
|
||||||
mipstats(int a, int b, int c)
|
mipstats(int a, int b, int c)
|
||||||
{
|
{
|
||||||
if (showm)
|
if (showm)
|
||||||
conoutf(@"1x1/2x2/4x4: %d / %d / %d", a, b, c);
|
conoutf(@"1x1/2x2/4x4: %d / %d / %d", a, b, c);
|
||||||
};
|
}
|
||||||
|
|
||||||
COMMAND(showmip, ARG_NONE);
|
|
||||||
|
|
||||||
#define stripend() \
|
#define stripend() \
|
||||||
{ \
|
{ \
|
||||||
|
|
|
@ -213,9 +213,8 @@ loadsky(char *basename)
|
||||||
conoutf(@"could not load sky textures");
|
conoutf(@"could not load sky textures");
|
||||||
};
|
};
|
||||||
strcpy_s(lastsky, basename);
|
strcpy_s(lastsky, basename);
|
||||||
};
|
}
|
||||||
|
COMMAND(loadsky, ARG_1CSTR)
|
||||||
COMMAND(loadsky, ARG_1STR);
|
|
||||||
|
|
||||||
float cursordepth = 0.9f;
|
float cursordepth = 0.9f;
|
||||||
GLint viewport[4];
|
GLint viewport[4];
|
||||||
|
|
|
@ -146,7 +146,8 @@ void
|
||||||
texturereset()
|
texturereset()
|
||||||
{
|
{
|
||||||
curtexnum = 0;
|
curtexnum = 0;
|
||||||
};
|
}
|
||||||
|
COMMAND(texturereset, ARG_NONE)
|
||||||
|
|
||||||
void
|
void
|
||||||
texture(char *aframe, char *name)
|
texture(char *aframe, char *name)
|
||||||
|
@ -158,10 +159,8 @@ texture(char *aframe, char *name)
|
||||||
char *n = mapname[num][frame];
|
char *n = mapname[num][frame];
|
||||||
strcpy_s(n, name);
|
strcpy_s(n, name);
|
||||||
path(n);
|
path(n);
|
||||||
};
|
}
|
||||||
|
COMMAND(texture, ARG_2STR)
|
||||||
COMMAND(texturereset, ARG_NONE);
|
|
||||||
COMMAND(texture, ARG_2STR);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
lookuptexture(int tex, int &xs, int &ys)
|
lookuptexture(int tex, int &xs, int &ys)
|
||||||
|
|
|
@ -246,22 +246,21 @@ mapmodel(char *rad, char *h, char *zoff, char *snap, char *name)
|
||||||
atoi(rad), atoi(h), atoi(zoff), atoi(snap), m->loadname};
|
atoi(rad), atoi(h), atoi(zoff), atoi(snap), m->loadname};
|
||||||
m->mmi = mmi;
|
m->mmi = mmi;
|
||||||
mapmodels.add(m);
|
mapmodels.add(m);
|
||||||
};
|
}
|
||||||
|
COMMAND(mapmodel, ARG_5STR)
|
||||||
|
|
||||||
void
|
void
|
||||||
mapmodelreset()
|
mapmodelreset()
|
||||||
{
|
{
|
||||||
mapmodels.setsize(0);
|
mapmodels.setsize(0);
|
||||||
};
|
}
|
||||||
|
COMMAND(mapmodelreset, ARG_NONE)
|
||||||
|
|
||||||
mapmodelinfo *
|
mapmodelinfo *
|
||||||
getmminfo(int i)
|
getmminfo(int i)
|
||||||
{
|
{
|
||||||
return i < mapmodels.length() ? &mapmodels[i]->mmi : NULL;
|
return i < mapmodels.length() ? &mapmodels[i]->mmi : NULL;
|
||||||
};
|
}
|
||||||
|
|
||||||
COMMAND(mapmodel, ARG_5STR);
|
|
||||||
COMMAND(mapmodelreset, ARG_NONE);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
rendermodel(char *mdl, int frame, int range, int tex, float rad, float x,
|
rendermodel(char *mdl, int frame, int range, int tex, float rad, float x,
|
||||||
|
|
|
@ -22,42 +22,47 @@ void
|
||||||
gzput(int i)
|
gzput(int i)
|
||||||
{
|
{
|
||||||
gzputc(f, i);
|
gzputc(f, i);
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gzputi(int i)
|
gzputi(int i)
|
||||||
{
|
{
|
||||||
gzwrite(f, &i, sizeof(int));
|
gzwrite(f, &i, sizeof(int));
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gzputv(vec &v)
|
gzputv(vec &v)
|
||||||
{
|
{
|
||||||
gzwrite(f, &v, sizeof(vec));
|
gzwrite(f, &v, sizeof(vec));
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gzcheck(int a, int b)
|
gzcheck(int a, int b)
|
||||||
{
|
{
|
||||||
if (a != b)
|
if (a != b)
|
||||||
fatal("savegame file corrupt (short)");
|
fatal("savegame file corrupt (short)");
|
||||||
};
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
gzget()
|
gzget()
|
||||||
{
|
{
|
||||||
char c = gzgetc(f);
|
char c = gzgetc(f);
|
||||||
return c;
|
return c;
|
||||||
};
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
gzgeti()
|
gzgeti()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
gzcheck(gzread(f, &i, sizeof(int)), sizeof(int));
|
gzcheck(gzread(f, &i, sizeof(int)), sizeof(int));
|
||||||
return i;
|
return i;
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gzgetv(vec &v)
|
gzgetv(vec &v)
|
||||||
{
|
{
|
||||||
gzcheck(gzread(f, &v, sizeof(vec)), sizeof(vec));
|
gzcheck(gzread(f, &v, sizeof(vec)), sizeof(vec));
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stop()
|
stop()
|
||||||
|
@ -73,14 +78,14 @@ stop()
|
||||||
demoloading = false;
|
demoloading = false;
|
||||||
loopv(playerhistory) zapdynent(playerhistory[i]);
|
loopv(playerhistory) zapdynent(playerhistory[i]);
|
||||||
playerhistory.setsize(0);
|
playerhistory.setsize(0);
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stopifrecording()
|
stopifrecording()
|
||||||
{
|
{
|
||||||
if (demorecording)
|
if (demorecording)
|
||||||
stop();
|
stop();
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
savestate(char *fn)
|
savestate(char *fn)
|
||||||
|
@ -95,7 +100,9 @@ savestate(char *fn)
|
||||||
gzputc(f, islittleendian);
|
gzputc(f, islittleendian);
|
||||||
gzputi(SAVEGAMEVERSION);
|
gzputi(SAVEGAMEVERSION);
|
||||||
gzputi(sizeof(dynent));
|
gzputi(sizeof(dynent));
|
||||||
gzwrite(f, getclientmap(), _MAXDEFSTR);
|
@autoreleasepool {
|
||||||
|
gzwrite(f, getclientmap().UTF8String, _MAXDEFSTR);
|
||||||
|
}
|
||||||
gzputi(gamemode);
|
gzputi(gamemode);
|
||||||
gzputi(ents.length());
|
gzputi(ents.length());
|
||||||
loopv(ents) gzputc(f, ents[i].spawned);
|
loopv(ents) gzputc(f, ents[i].spawned);
|
||||||
|
@ -123,6 +130,7 @@ savegame(char *name)
|
||||||
stop();
|
stop();
|
||||||
conoutf(@"wrote %s", fn);
|
conoutf(@"wrote %s", fn);
|
||||||
}
|
}
|
||||||
|
COMMAND(savegame, ARG_1CSTR)
|
||||||
|
|
||||||
void
|
void
|
||||||
loadstate(char *fn)
|
loadstate(char *fn)
|
||||||
|
@ -148,8 +156,11 @@ loadstate(char *fn)
|
||||||
string mapname;
|
string mapname;
|
||||||
gzread(f, mapname, _MAXDEFSTR);
|
gzread(f, mapname, _MAXDEFSTR);
|
||||||
nextmode = gzgeti();
|
nextmode = gzgeti();
|
||||||
changemap(mapname); // continue below once map has been loaded and
|
@autoreleasepool {
|
||||||
|
changemap(
|
||||||
|
@(mapname)); // continue below once map has been loaded and
|
||||||
// client & server have updated
|
// client & server have updated
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
out:
|
out:
|
||||||
conoutf(@"aborting: savegame/demo from a different version of cube or "
|
conoutf(@"aborting: savegame/demo from a different version of cube or "
|
||||||
|
@ -163,6 +174,7 @@ loadgame(char *name)
|
||||||
sprintf_sd(fn)("savegames/%s.csgz", name);
|
sprintf_sd(fn)("savegames/%s.csgz", name);
|
||||||
loadstate(fn);
|
loadstate(fn);
|
||||||
}
|
}
|
||||||
|
COMMAND(loadgame, ARG_1CSTR)
|
||||||
|
|
||||||
void
|
void
|
||||||
loadgameout()
|
loadgameout()
|
||||||
|
@ -247,7 +259,8 @@ record(char *name)
|
||||||
demorecording = true;
|
demorecording = true;
|
||||||
starttime = lastmillis;
|
starttime = lastmillis;
|
||||||
ddamage = bdamage = 0;
|
ddamage = bdamage = 0;
|
||||||
};
|
}
|
||||||
|
COMMAND(record, ARG_1CSTR)
|
||||||
|
|
||||||
void
|
void
|
||||||
demodamage(int damage, vec &o)
|
demodamage(int damage, vec &o)
|
||||||
|
@ -299,6 +312,7 @@ demo(char *name)
|
||||||
loadstate(fn);
|
loadstate(fn);
|
||||||
demoloading = true;
|
demoloading = true;
|
||||||
}
|
}
|
||||||
|
COMMAND(demo, ARG_1CSTR)
|
||||||
|
|
||||||
void
|
void
|
||||||
stopreset()
|
stopreset()
|
||||||
|
@ -488,11 +502,5 @@ stopn()
|
||||||
else
|
else
|
||||||
stop();
|
stop();
|
||||||
conoutf(@"demo stopped");
|
conoutf(@"demo stopped");
|
||||||
};
|
}
|
||||||
|
COMMANDN(stop, stopn, ARG_NONE)
|
||||||
COMMAND(record, ARG_1STR);
|
|
||||||
COMMAND(demo, ARG_1STR);
|
|
||||||
COMMANDN(stop, stopn, ARG_NONE);
|
|
||||||
|
|
||||||
COMMAND(savegame, ARG_1STR);
|
|
||||||
COMMAND(loadgame, ARG_1STR);
|
|
||||||
|
|
|
@ -312,11 +312,11 @@ updatefrommaster()
|
||||||
execute((char *)reply);
|
execute((char *)reply);
|
||||||
};
|
};
|
||||||
servermenu();
|
servermenu();
|
||||||
};
|
}
|
||||||
|
|
||||||
COMMAND(addserver, ARG_1STR);
|
COMMAND(addserver, ARG_1CSTR)
|
||||||
COMMAND(servermenu, ARG_NONE);
|
COMMAND(servermenu, ARG_NONE)
|
||||||
COMMAND(updatefrommaster, ARG_NONE);
|
COMMAND(updatefrommaster, ARG_NONE)
|
||||||
|
|
||||||
void
|
void
|
||||||
writeservercfg()
|
writeservercfg()
|
||||||
|
|
10
src/sound.mm
10
src/sound.mm
|
@ -110,9 +110,9 @@ music(char *name)
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
COMMAND(music, ARG_1STR);
|
COMMAND(music, ARG_1CSTR)
|
||||||
|
|
||||||
#ifdef USE_MIXER
|
#ifdef USE_MIXER
|
||||||
vector<Mix_Chunk *> samples;
|
vector<Mix_Chunk *> samples;
|
||||||
|
@ -131,7 +131,7 @@ registersound(char *name)
|
||||||
return samples.length() - 1;
|
return samples.length() - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
COMMAND(registersound, ARG_1EST);
|
COMMAND(registersound, ARG_1EST)
|
||||||
|
|
||||||
void
|
void
|
||||||
cleansound()
|
cleansound()
|
||||||
|
@ -267,5 +267,5 @@ void
|
||||||
sound(int n)
|
sound(int n)
|
||||||
{
|
{
|
||||||
playsound(n, NULL);
|
playsound(n, NULL);
|
||||||
};
|
}
|
||||||
COMMAND(sound, ARG_1INT);
|
COMMAND(sound, ARG_1INT)
|
||||||
|
|
29
src/tools.h
29
src/tools.h
|
@ -166,22 +166,25 @@ struct pool {
|
||||||
void dealloc(void *p, size_t size);
|
void dealloc(void *p, size_t size);
|
||||||
void *realloc(void *p, size_t oldsize, size_t newsize);
|
void *realloc(void *p, size_t oldsize, size_t newsize);
|
||||||
|
|
||||||
char *string(char *s, size_t l);
|
char *string(const char *s, size_t l);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
string(char *s)
|
string(const char *s)
|
||||||
{
|
{
|
||||||
return string(s, strlen(s));
|
return string(s, strlen(s));
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
deallocstr(char *s)
|
deallocstr(char *s)
|
||||||
{
|
{
|
||||||
dealloc(s, strlen(s) + 1);
|
dealloc(s, strlen(s) + 1);
|
||||||
};
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
stringbuf(char *s)
|
stringbuf(const char *s)
|
||||||
{
|
{
|
||||||
return string(s, _MAXDEFSTR - 1);
|
return string(s, _MAXDEFSTR - 1);
|
||||||
};
|
}
|
||||||
|
|
||||||
void dealloc_block(void *b);
|
void dealloc_block(void *b);
|
||||||
void allocnext(size_t allocsize);
|
void allocnext(size_t allocsize);
|
||||||
|
@ -379,19 +382,21 @@ template <class T> struct hashtable {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char *
|
inline char *
|
||||||
newstring(char *s)
|
newstring(const char *s)
|
||||||
{
|
{
|
||||||
return gp()->string(s);
|
return gp()->string(s);
|
||||||
};
|
}
|
||||||
|
|
||||||
inline char *
|
inline char *
|
||||||
newstring(char *s, size_t l)
|
newstring(const char *s, size_t l)
|
||||||
{
|
{
|
||||||
return gp()->string(s, l);
|
return gp()->string(s, l);
|
||||||
};
|
}
|
||||||
|
|
||||||
inline char *
|
inline char *
|
||||||
newstringbuf(char *s)
|
newstringbuf(const char *s)
|
||||||
{
|
{
|
||||||
return gp()->stringbuf(s);
|
return gp()->stringbuf(s);
|
||||||
};
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -82,13 +82,13 @@ pool::allocnext(size_t allocsize)
|
||||||
};
|
};
|
||||||
|
|
||||||
char *
|
char *
|
||||||
pool::string(char *s, size_t l)
|
pool::string(const char *s, size_t l)
|
||||||
{
|
{
|
||||||
char *b = (char *)alloc(l + 1);
|
char *b = (char *)alloc(l + 1);
|
||||||
strncpy(b, s, l);
|
strncpy(b, s, l);
|
||||||
b[l] = 0;
|
b[l] = 0;
|
||||||
return b;
|
return b;
|
||||||
};
|
}
|
||||||
|
|
||||||
pool *
|
pool *
|
||||||
gp() // useful for global buffers that need to be initialisation order
|
gp() // useful for global buffers that need to be initialisation order
|
||||||
|
|
|
@ -64,9 +64,8 @@ weapon(char *a1, char *a2, char *a3)
|
||||||
{
|
{
|
||||||
selectgun(a1[0] ? atoi(a1) : -1, a2[0] ? atoi(a2) : -1,
|
selectgun(a1[0] ? atoi(a1) : -1, a2[0] ? atoi(a2) : -1,
|
||||||
a3[0] ? atoi(a3) : -1);
|
a3[0] ? atoi(a3) : -1);
|
||||||
};
|
}
|
||||||
|
COMMAND(weapon, ARG_3STR)
|
||||||
COMMAND(weapon, ARG_3STR);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
createrays(vec &from, vec &to) // create random spread of rays for the shotgun
|
createrays(vec &from, vec &to) // create random spread of rays for the shotgun
|
||||||
|
|
25
src/world.mm
25
src/world.mm
|
@ -66,9 +66,8 @@ trigger(int tag, int type, bool savegame)
|
||||||
execute(aliasname);
|
execute(aliasname);
|
||||||
if (type == 2)
|
if (type == 2)
|
||||||
endsp(false);
|
endsp(false);
|
||||||
};
|
}
|
||||||
|
COMMAND(trigger, ARG_2INT)
|
||||||
COMMAND(trigger, ARG_2INT);
|
|
||||||
|
|
||||||
// main geometric mipmapping routine, recursively rebuild mipmaps within block
|
// main geometric mipmapping routine, recursively rebuild mipmaps within block
|
||||||
// b. tries to produce cube out of 4 lower level mips as well as possible, sets
|
// b. tries to produce cube out of 4 lower level mips as well as possible, sets
|
||||||
|
@ -360,9 +359,8 @@ clearents(char *name)
|
||||||
};
|
};
|
||||||
if (type == LIGHT)
|
if (type == LIGHT)
|
||||||
calclight();
|
calclight();
|
||||||
};
|
}
|
||||||
|
COMMAND(clearents, ARG_1CSTR)
|
||||||
COMMAND(clearents, ARG_1STR);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
scalecomp(uchar &c, int intens)
|
scalecomp(uchar &c, int intens)
|
||||||
|
@ -393,9 +391,8 @@ scalelights(int f, int intens)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
calclight();
|
calclight();
|
||||||
};
|
}
|
||||||
|
COMMAND(scalelights, ARG_2INT)
|
||||||
COMMAND(scalelights, ARG_2INT);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
findentity(int type, int index)
|
findentity(int type, int index)
|
||||||
|
@ -504,8 +501,8 @@ newmap(int i)
|
||||||
empty_world(i, false);
|
empty_world(i, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
COMMAND(mapenlarge, ARG_NONE);
|
COMMAND(mapenlarge, ARG_NONE)
|
||||||
COMMAND(newmap, ARG_1INT);
|
COMMAND(newmap, ARG_1INT)
|
||||||
COMMANDN(recalc, calclight, ARG_NONE);
|
COMMANDN(recalc, calclight, ARG_NONE)
|
||||||
COMMAND(delent, ARG_NONE);
|
COMMAND(delent, ARG_NONE)
|
||||||
COMMAND(entproperty, ARG_2INT);
|
COMMAND(entproperty, ARG_2INT)
|
||||||
|
|
|
@ -11,18 +11,18 @@ backup(char *name, char *backupname)
|
||||||
|
|
||||||
string cgzname, bakname, pcfname, mcfname;
|
string cgzname, bakname, pcfname, mcfname;
|
||||||
|
|
||||||
void
|
static void
|
||||||
setnames(char *name)
|
setnames(const char *name)
|
||||||
{
|
{
|
||||||
string pakname, mapname;
|
string pakname, mapname;
|
||||||
char *slash = strpbrk(name, "/\\");
|
const char *slash = strpbrk(name, "/\\");
|
||||||
if (slash) {
|
if (slash) {
|
||||||
strn0cpy(pakname, name, slash - name + 1);
|
strn0cpy(pakname, name, slash - name + 1);
|
||||||
strcpy_s(mapname, slash + 1);
|
strcpy_s(mapname, slash + 1);
|
||||||
} else {
|
} else {
|
||||||
strcpy_s(pakname, "base");
|
strcpy_s(pakname, "base");
|
||||||
strcpy_s(mapname, name);
|
strcpy_s(mapname, name);
|
||||||
};
|
}
|
||||||
sprintf_s(cgzname)("packages/%s/%s.cgz", pakname, mapname);
|
sprintf_s(cgzname)("packages/%s/%s.cgz", pakname, mapname);
|
||||||
sprintf_s(bakname)(
|
sprintf_s(bakname)(
|
||||||
"packages/%s/%s_%d.BAK", pakname, mapname, lastmillis);
|
"packages/%s/%s_%d.BAK", pakname, mapname, lastmillis);
|
||||||
|
@ -31,7 +31,7 @@ setnames(char *name)
|
||||||
|
|
||||||
path(cgzname);
|
path(cgzname);
|
||||||
path(bakname);
|
path(bakname);
|
||||||
};
|
}
|
||||||
|
|
||||||
// the optimize routines below are here to reduce the detrimental effects of
|
// the optimize routines below are here to reduce the detrimental effects of
|
||||||
// messy mapping by setting certain properties (vdeltas and textures) to
|
// messy mapping by setting certain properties (vdeltas and textures) to
|
||||||
|
@ -137,7 +137,7 @@ writemap(char *mname, int msize, uchar *mdata)
|
||||||
}
|
}
|
||||||
|
|
||||||
uchar *
|
uchar *
|
||||||
readmap(char *mname, int *msize)
|
readmap(const char *mname, int *msize)
|
||||||
{
|
{
|
||||||
setnames(mname);
|
setnames(mname);
|
||||||
uchar *mdata = (uchar *)loadfile(cgzname, msize);
|
uchar *mdata = (uchar *)loadfile(cgzname, msize);
|
||||||
|
@ -154,13 +154,15 @@ readmap(char *mname, int *msize)
|
||||||
// miniscule map sizes.
|
// miniscule map sizes.
|
||||||
|
|
||||||
void
|
void
|
||||||
save_world(char *mname)
|
save_world(const char *mname)
|
||||||
{
|
{
|
||||||
resettagareas(); // wouldn't be able to reproduce tagged areas otherwise
|
@autoreleasepool {
|
||||||
|
resettagareas(); // wouldn't be able to reproduce tagged areas
|
||||||
|
// otherwise
|
||||||
voptimize();
|
voptimize();
|
||||||
toptimize();
|
toptimize();
|
||||||
if (!*mname)
|
if (!*mname)
|
||||||
mname = getclientmap();
|
mname = getclientmap().UTF8String;
|
||||||
setnames(mname);
|
setnames(mname);
|
||||||
backup(cgzname, bakname);
|
backup(cgzname, bakname);
|
||||||
gzFile f = gzopen(cgzname, "wb9");
|
gzFile f = gzopen(cgzname, "wb9");
|
||||||
|
@ -216,9 +218,9 @@ save_world(char *mname)
|
||||||
gzputc(f, s->vdelta);
|
gzputc(f, s->vdelta);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
if (t && c(type) && c(floor) && c(ceil) && c(ctex) &&
|
if (t && c(type) && c(floor) && c(ceil) &&
|
||||||
c(ftex) && c(utex) && c(wtex) && c(vdelta) &&
|
c(ctex) && c(ftex) && c(utex) && c(wtex) &&
|
||||||
c(tag)) {
|
c(vdelta) && c(tag)) {
|
||||||
sc++;
|
sc++;
|
||||||
} else {
|
} else {
|
||||||
spurge;
|
spurge;
|
||||||
|
@ -239,7 +241,8 @@ save_world(char *mname)
|
||||||
gzclose(f);
|
gzclose(f);
|
||||||
conoutf(@"wrote map file %s", cgzname);
|
conoutf(@"wrote map file %s", cgzname);
|
||||||
settagareas();
|
settagareas();
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
load_world(char *mname) // still supports all map formats that have existed
|
load_world(char *mname) // still supports all map formats that have existed
|
||||||
|
@ -371,6 +374,6 @@ load_world(char *mname) // still supports all map formats that have existed
|
||||||
execfile("data/default_map_settings.cfg");
|
execfile("data/default_map_settings.cfg");
|
||||||
execfile(pcfname);
|
execfile(pcfname);
|
||||||
execfile(mcfname);
|
execfile(mcfname);
|
||||||
};
|
}
|
||||||
|
|
||||||
COMMANDN(savemap, save_world, ARG_1STR);
|
COMMANDN(savemap, save_world, ARG_1CSTR)
|
||||||
|
|
|
@ -12,9 +12,8 @@ void
|
||||||
toggleocull()
|
toggleocull()
|
||||||
{
|
{
|
||||||
ocull = !ocull;
|
ocull = !ocull;
|
||||||
};
|
}
|
||||||
|
COMMAND(toggleocull, ARG_NONE)
|
||||||
COMMAND(toggleocull, ARG_NONE);
|
|
||||||
|
|
||||||
// constructs occlusion map: cast rays in all directions on the 2d plane and
|
// constructs occlusion map: cast rays in all directions on the 2d plane and
|
||||||
// record distance. done exactly once per frame.
|
// record distance. done exactly once per frame.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue