Convert all references to pointers in protos.h

FossilOrigin-Name: c38d75087b98b5b7a4c7963d119b8eb0bf6be2603bdf43a79e743300951a4d28
This commit is contained in:
Jonathan Schleifer 2025-03-20 20:11:37 +00:00
parent d25e07085c
commit d9d56601bb
20 changed files with 406 additions and 383 deletions

View file

@ -187,9 +187,9 @@ sendmap(OFString *mapname)
NULL, MAXTRANS + mapdata.count, ENET_PACKET_FLAG_RELIABLE); NULL, MAXTRANS + mapdata.count, ENET_PACKET_FLAG_RELIABLE);
uchar *start = packet->data; uchar *start = packet->data;
uchar *p = start + 2; uchar *p = start + 2;
putint(p, SV_SENDMAP); putint(&p, SV_SENDMAP);
sendstring(mapname, p); sendstring(mapname, &p);
putint(p, mapdata.count); putint(&p, mapdata.count);
if (65535 - (p - start) < mapdata.count) { if (65535 - (p - start) < mapdata.count) {
conoutf(@"map %@ is too large to send", mapname); conoutf(@"map %@ is too large to send", mapname);
enet_packet_destroy(packet); enet_packet_destroy(packet);
@ -215,7 +215,7 @@ getmap()
enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE); enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
uchar *start = packet->data; uchar *start = packet->data;
uchar *p = start + 2; uchar *p = start + 2;
putint(p, SV_RECVMAP); putint(&p, SV_RECVMAP);
*(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);
sendpackettoserv(packet); sendpackettoserv(packet);

View file

@ -261,10 +261,11 @@ updateworld(int millis) // main game update loop
demoplaybackstep(); demoplaybackstep();
if (!demoplayback) { if (!demoplayback) {
if (getclientnum() >= 0) if (getclientnum() >= 0)
shoot(player1, worldpos); // only shoot when // only shoot when connected to server
// connected to server shoot(player1, &worldpos);
gets2c(); // do this first, so we have most accurate // do this first, so we have most accurate information
// information when our player moves // when our player moves
gets2c();
} }
otherplayers(); otherplayers();
if (!demoplayback) { if (!demoplayback) {

View file

@ -293,67 +293,67 @@ c2sinfo(DynamicEntity *d)
// do this exclusively as map change may invalidate rest of // do this exclusively as map change may invalidate rest of
// update // 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, &p);
toservermap = @""; toservermap = @"";
putint(p, nextmode); putint(&p, nextmode);
} else { } else {
putint(p, SV_POS); putint(&p, SV_POS);
putint(p, clientnum); putint(&p, clientnum);
// quantize coordinates to 1/16th of a cube, between 1 and 3 // quantize coordinates to 1/16th of a cube, between 1 and 3
// bytes // bytes
putint(p, (int)(d.o.x * DMF)); putint(&p, (int)(d.o.x * DMF));
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));
putint(p, (int)(d.yaw * DAF)); putint(&p, (int)(d.yaw * DAF));
putint(p, (int)(d.pitch * DAF)); putint(&p, (int)(d.pitch * DAF));
putint(p, (int)(d.roll * DAF)); putint(&p, (int)(d.roll * DAF));
// quantize to 1/100, almost always 1 byte // quantize to 1/100, almost always 1 byte
putint(p, (int)(d.vel.x * DVF)); putint(&p, (int)(d.vel.x * DVF));
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, state:3
putint(p, putint(&p,
(d.strafe & 3) | ((d.move & 3) << 2) | (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));
if (senditemstoserver) { if (senditemstoserver) {
packet->flags = ENET_PACKET_FLAG_RELIABLE; packet->flags = ENET_PACKET_FLAG_RELIABLE;
putint(p, SV_ITEMLIST); putint(&p, SV_ITEMLIST);
if (!m_noitems) if (!m_noitems)
putitems(p); putitems(&p);
putint(p, -1); putint(&p, -1);
senditemstoserver = false; senditemstoserver = false;
serveriteminitdone = true; serveriteminitdone = true;
} }
// player chat, not flood protected for now // player chat, not flood protected for now
if (ctext.length > 0) { if (ctext.length > 0) {
packet->flags = ENET_PACKET_FLAG_RELIABLE; packet->flags = ENET_PACKET_FLAG_RELIABLE;
putint(p, SV_TEXT); putint(&p, SV_TEXT);
sendstring(ctext, p); sendstring(ctext, &p);
ctext = @""; ctext = @"";
} }
// tell other clients who I am // tell other clients who I am
if (!c2sinit) { if (!c2sinit) {
packet->flags = ENET_PACKET_FLAG_RELIABLE; packet->flags = ENET_PACKET_FLAG_RELIABLE;
c2sinit = true; c2sinit = true;
putint(p, SV_INITC2S); putint(&p, SV_INITC2S);
sendstring(player1.name, p); sendstring(player1.name, &p);
sendstring(player1.team, p); sendstring(player1.team, &p);
putint(p, player1.lifesequence); putint(&p, player1.lifesequence);
} }
for (OFData *msg in messages) { for (OFData *msg in messages) {
// send messages collected during the previous frames // send messages collected during the previous frames
if (*(int *)[msg itemAtIndex:1]) if (*(int *)[msg itemAtIndex:1])
packet->flags = ENET_PACKET_FLAG_RELIABLE; packet->flags = ENET_PACKET_FLAG_RELIABLE;
loopi(*(int *)[msg itemAtIndex:0]) loopi(*(int *)[msg itemAtIndex:0])
putint(p, *(int *)[msg itemAtIndex:i + 2]); putint(&p, *(int *)[msg itemAtIndex:i + 2]);
} }
[messages removeAllObjects]; [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;
} }
} }

View file

@ -77,11 +77,11 @@ localservertoclient(uchar *buf, int len)
bool mapchanged = false; bool mapchanged = false;
while (p < end) while (p < end)
switch (type = getint(p)) { switch (type = getint(&p)) {
case SV_INITS2C: // welcome messsage from the server case SV_INITS2C: // welcome messsage from the server
{ {
cn = getint(p); cn = getint(&p);
int prot = getint(p); int prot = getint(&p);
if (prot != PROTOCOL_VERSION) { if (prot != PROTOCOL_VERSION) {
conoutf(@"you are using a different game " conoutf(@"you are using a different game "
@"protocol (you: %d, server: %d)", @"protocol (you: %d, server: %d)",
@ -91,7 +91,7 @@ localservertoclient(uchar *buf, int len)
} }
toservermap = @""; toservermap = @"";
clientnum = cn; // we are now fully connected clientnum = cn; // we are now fully connected
if (!getint(p)) if (!getint(&p))
// we are the first client on this server, set // we are the first client on this server, set
// map // map
toservermap = getclientmap(); toservermap = getclientmap();
@ -103,25 +103,30 @@ localservertoclient(uchar *buf, int len)
disconnect(); disconnect();
return; return;
} }
if (getint(p) == 1) if (getint(&p) == 1)
conoutf(@"server is FULL, disconnecting.."); conoutf(@"server is FULL, disconnecting..");
break; break;
} }
case SV_POS: { case SV_POS: {
// position of another client // position of another client
cn = getint(p); cn = getint(&p);
d = getclient(cn); d = getclient(cn);
if (d == nil) if (d == nil)
return; return;
d.o = OFMakeVector3D( OFVector3D tmp;
getint(p) / DMF, getint(p) / DMF, getint(p) / DMF); tmp.x = getint(&p) / DMF;
d.yaw = getint(p) / DAF; tmp.y = getint(&p) / DMF;
d.pitch = getint(p) / DAF; tmp.z = getint(&p) / DMF;
d.roll = getint(p) / DAF; d.o = tmp;
d.vel = OFMakeVector3D( d.yaw = getint(&p) / DAF;
getint(p) / DVF, getint(p) / DVF, getint(p) / DVF); d.pitch = getint(&p) / DAF;
int f = getint(p); d.roll = getint(&p) / DAF;
tmp.x = getint(&p) / DVF;
tmp.y = getint(&p) / DVF;
tmp.z = getint(&p) / DVF;
d.vel = tmp;
int f = getint(&p);
d.strafe = (f & 3) == 3 ? -1 : f & 3; d.strafe = (f & 3) == 3 ? -1 : f & 3;
f >>= 2; f >>= 2;
d.move = (f & 3) == 3 ? -1 : f & 3; d.move = (f & 3) == 3 ? -1 : f & 3;
@ -137,7 +142,7 @@ localservertoclient(uchar *buf, int len)
case SV_SOUND: { case SV_SOUND: {
OFVector3D loc = d.o; OFVector3D loc = d.o;
playsound(getint(p), &loc); playsound(getint(&p), &loc);
break; break;
} }
@ -148,7 +153,7 @@ localservertoclient(uchar *buf, int len)
case SV_MAPCHANGE: case SV_MAPCHANGE:
sgetstr(); sgetstr();
changemapserv(@(text), getint(p)); changemapserv(@(text), getint(&p));
mapchanged = true; mapchanged = true;
break; break;
@ -158,15 +163,14 @@ localservertoclient(uchar *buf, int len)
senditemstoserver = false; senditemstoserver = false;
resetspawns(); resetspawns();
} }
while ((n = getint(p)) != -1) while ((n = getint(&p)) != -1)
if (mapchanged) if (mapchanged)
setspawn(n, true); setspawn(n, true);
break; break;
} }
// server requests next map
case SV_MAPRELOAD: // server requests next map case SV_MAPRELOAD: {
{ getint(&p);
getint(p);
OFString *nextmapalias = [OFString OFString *nextmapalias = [OFString
stringWithFormat:@"nextmap_%@", getclientmap()]; stringWithFormat:@"nextmap_%@", getclientmap()];
OFString *map = OFString *map =
@ -193,12 +197,12 @@ localservertoclient(uchar *buf, int len)
d.name = @(text); d.name = @(text);
sgetstr(); sgetstr();
d.team = @(text); d.team = @(text);
d.lifesequence = getint(p); d.lifesequence = getint(&p);
break; break;
} }
case SV_CDIS: case SV_CDIS:
cn = getint(p); cn = getint(&p);
if ((d = getclient(cn)) == nil) if ((d = getclient(cn)) == nil)
break; break;
conoutf(@"player %@ disconnected", conoutf(@"player %@ disconnected",
@ -207,24 +211,24 @@ localservertoclient(uchar *buf, int len)
break; break;
case SV_SHOT: { case SV_SHOT: {
int gun = getint(p); int gun = getint(&p);
OFVector3D s, e; OFVector3D s, e;
s.x = getint(p) / DMF; s.x = getint(&p) / DMF;
s.y = getint(p) / DMF; s.y = getint(&p) / DMF;
s.z = getint(p) / DMF; s.z = getint(&p) / DMF;
e.x = getint(p) / DMF; e.x = getint(&p) / DMF;
e.y = getint(p) / DMF; e.y = getint(&p) / DMF;
e.z = getint(p) / DMF; e.z = getint(&p) / DMF;
if (gun == GUN_SG) if (gun == GUN_SG)
createrays(s, e); createrays(&s, &e);
shootv(gun, s, e, d); shootv(gun, &s, &e, d);
break; break;
} }
case SV_DAMAGE: { case SV_DAMAGE: {
int target = getint(p); int target = getint(&p);
int damage = getint(p); int damage = getint(&p);
int ls = getint(p); int ls = getint(&p);
if (target == clientnum) { if (target == clientnum) {
if (ls == player1.lifesequence) if (ls == player1.lifesequence)
selfdamage(damage, cn, d); selfdamage(damage, cn, d);
@ -236,7 +240,7 @@ localservertoclient(uchar *buf, int len)
} }
case SV_DIED: { case SV_DIED: {
int actor = getint(p); int actor = getint(&p);
if (actor == cn) { if (actor == cn) {
conoutf(@"%@ suicided", d.name); conoutf(@"%@ suicided", d.name);
} else if (actor == clientnum) { } else if (actor == clientnum) {
@ -270,16 +274,16 @@ localservertoclient(uchar *buf, int len)
} }
case SV_FRAGS: case SV_FRAGS:
[players[cn] setFrags:getint(p)]; [players[cn] setFrags:getint(&p)];
break; break;
case SV_ITEMPICKUP: case SV_ITEMPICKUP:
setspawn(getint(p), false); setspawn(getint(&p), false);
getint(p); getint(&p);
break; break;
case SV_ITEMSPAWN: { case SV_ITEMSPAWN: {
uint i = getint(p); uint i = getint(&p);
setspawn(i, true); setspawn(i, true);
if (i >= (uint)ents.count) if (i >= (uint)ents.count)
break; break;
@ -288,10 +292,9 @@ localservertoclient(uchar *buf, int len)
playsound(S_ITEMSPAWN, &v); playsound(S_ITEMSPAWN, &v);
break; break;
} }
// server acknowledges that I picked up this item
case SV_ITEMACC: // server acknowledges that I picked up this case SV_ITEMACC:
// item realpickup(getint(&p), player1);
realpickup(getint(p), player1);
break; break;
case SV_EDITH: // coop editing messages, should be extended to case SV_EDITH: // coop editing messages, should be extended to
@ -300,27 +303,27 @@ localservertoclient(uchar *buf, int len)
case SV_EDITS: case SV_EDITS:
case SV_EDITD: case SV_EDITD:
case SV_EDITE: { case SV_EDITE: {
int x = getint(p); int x = getint(&p);
int y = getint(p); int y = getint(&p);
int xs = getint(p); int xs = getint(&p);
int ys = getint(p); int ys = getint(&p);
int v = getint(p); int v = getint(&p);
block b = { x, y, xs, ys }; block b = { x, y, xs, ys };
switch (type) { switch (type) {
case SV_EDITH: case SV_EDITH:
editheightxy(v != 0, getint(p), b); editheightxy(v != 0, getint(&p), &b);
break; break;
case SV_EDITT: case SV_EDITT:
edittexxy(v, getint(p), b); edittexxy(v, getint(&p), &b);
break; break;
case SV_EDITS: case SV_EDITS:
edittypexy(v, b); edittypexy(v, &b);
break; break;
case SV_EDITD: case SV_EDITD:
setvdeltaxy(v, b); setvdeltaxy(v, &b);
break; break;
case SV_EDITE: case SV_EDITE:
editequalisexy(v != 0, b); editequalisexy((v != 0), &b);
break; break;
} }
break; break;
@ -328,7 +331,7 @@ localservertoclient(uchar *buf, int len)
case SV_EDITENT: // coop edit of ent case SV_EDITENT: // coop edit of ent
{ {
uint i = getint(p); uint i = getint(&p);
while ((uint)ents.count <= i) { while ((uint)ents.count <= i) {
Entity *e = [Entity entity]; Entity *e = [Entity entity];
@ -337,14 +340,14 @@ localservertoclient(uchar *buf, int len)
} }
int to = ents[i].type; int to = ents[i].type;
ents[i].type = getint(p); ents[i].type = getint(&p);
ents[i].x = getint(p); ents[i].x = getint(&p);
ents[i].y = getint(p); ents[i].y = getint(&p);
ents[i].z = getint(p); ents[i].z = getint(&p);
ents[i].attr1 = getint(p); ents[i].attr1 = getint(&p);
ents[i].attr2 = getint(p); ents[i].attr2 = getint(&p);
ents[i].attr3 = getint(p); ents[i].attr3 = getint(&p);
ents[i].attr4 = getint(p); ents[i].attr4 = getint(&p);
ents[i].spawned = false; ents[i].spawned = false;
if (ents[i].type == LIGHT || to == LIGHT) if (ents[i].type == LIGHT || to == LIGHT)
calclight(); calclight();
@ -352,33 +355,33 @@ localservertoclient(uchar *buf, int len)
} }
case SV_PING: case SV_PING:
getint(p); getint(&p);
break; break;
case SV_PONG: case SV_PONG:
addmsg(0, 2, SV_CLIENTPING, addmsg(0, 2, SV_CLIENTPING,
player1.ping = player1.ping =
(player1.ping * 5 + lastmillis - getint(p)) / (player1.ping * 5 + lastmillis - getint(&p)) /
6); 6);
break; break;
case SV_CLIENTPING: case SV_CLIENTPING:
[players[cn] setPing:getint(p)]; [players[cn] setPing:getint(&p)];
break; break;
case SV_GAMEMODE: case SV_GAMEMODE:
nextmode = getint(p); nextmode = getint(&p);
break; break;
case SV_TIMEUP: case SV_TIMEUP:
timeupdate(getint(p)); timeupdate(getint(&p));
break; break;
case SV_RECVMAP: { case SV_RECVMAP: {
sgetstr(); sgetstr();
conoutf(@"received map \"%s\" from server, reloading..", conoutf(@"received map \"%s\" from server, reloading..",
text); text);
int mapsize = getint(p); int mapsize = getint(&p);
OFString *string = @(text); OFString *string = @(text);
writemap(string, mapsize, p); writemap(string, mapsize, p);
p += mapsize; p += mapsize;
@ -394,8 +397,8 @@ localservertoclient(uchar *buf, int len)
case SV_EXT: // so we can messages without breaking previous case SV_EXT: // so we can messages without breaking previous
// clients/servers, if necessary // clients/servers, if necessary
{ {
for (int n = getint(p); n; n--) for (int n = getint(&p); n; n--)
getint(p); getint(&p);
break; break;
} }

View file

@ -315,12 +315,12 @@ extern bool demoplayback;
(v).z = (v).z * f + (u).z * g; \ (v).z = (v).z * f + (u).z * g; \
} }
#define sgetstr() \ #define sgetstr() \
{ \ { \
char *t = text; \ char *t = text; \
do { \ do { \
*t = getint(p); \ *t = getint(&p); \
} while (*t++); \ } while (*t++); \
} // used by networking } // used by networking
#define m_noitems (gamemode >= 4) #define m_noitems (gamemode >= 4)

View file

@ -29,15 +29,15 @@ OF_CONSTRUCTOR()
int selh = 0; int selh = 0;
bool selset = false; bool selset = false;
#define loopselxy(b) \ #define loopselxy(b) \
{ \ { \
makeundo(); \ makeundo(); \
loop(x, sel.xs) loop(y, sel.ys) \ loop(x, sel->xs) loop(y, sel->ys) \
{ \ { \
sqr *s = S(sel.x + x, sel.y + y); \ sqr *s = S(sel->x + x, sel->y + y); \
b; \ b; \
} \ } \
remip(sel); \ remip(sel); \
} }
int cx, cy, ch; int cx, cy, ch;
@ -208,7 +208,7 @@ cursorupdate() // called every frame from hud
else else
linestyle(GRIDW, 0x80, 0x80, 0x80); linestyle(GRIDW, 0x80, 0x80, 0x80);
block b = { ix, iy, 1, 1 }; block b = { ix, iy, 1, 1 };
box(b, h1, h2, h3, h4); box(&b, h1, h2, h3, h4);
linestyle(GRID8, 0x40, 0x40, 0xFF); linestyle(GRID8, 0x40, 0x40, 0xFF);
if (!(ix & GRIDM)) if (!(ix & GRIDM))
line(ix, iy, h1, ix, iy + 1, h4); line(ix, iy, h1, ix, iy + 1, h4);
@ -225,7 +225,7 @@ cursorupdate() // called every frame from hud
float ih = sheight(s, s, z); float ih = sheight(s, s, z);
linestyle(GRIDS, 0xFF, 0xFF, 0xFF); linestyle(GRIDS, 0xFF, 0xFF, 0xFF);
block b = { cx, cy, 1, 1 }; block b = { cx, cy, 1, 1 };
box(b, ih, sheight(s, SWS(s, 1, 0, ssize), z), box(&b, ih, sheight(s, SWS(s, 1, 0, ssize), z),
sheight(s, SWS(s, 1, 1, ssize), z), sheight(s, SWS(s, 1, 1, ssize), z),
sheight(s, SWS(s, 0, 1, ssize), z)); sheight(s, SWS(s, 0, 1, ssize), z));
linestyle(GRIDS, 0xFF, 0x00, 0x00); linestyle(GRIDS, 0xFF, 0x00, 0x00);
@ -235,7 +235,7 @@ cursorupdate() // called every frame from hud
if (selset) { if (selset) {
linestyle(GRIDS, 0xFF, 0x40, 0x40); linestyle(GRIDS, 0xFF, 0x40, 0x40);
box(sel, (float)selh, (float)selh, (float)selh, (float)selh); box(&sel, (float)selh, (float)selh, (float)selh, (float)selh);
} }
} }
@ -264,7 +264,7 @@ makeundo()
undos = undos =
[[OFMutableData alloc] initWithItemSize:sizeof(block *)]; [[OFMutableData alloc] initWithItemSize:sizeof(block *)];
block *copy = blockcopy(sel); block *copy = blockcopy(&sel);
[undos addItem:&copy]; [undos addItem:&copy];
pruneundos(undomegs << 20); pruneundos(undomegs << 20);
} }
@ -279,7 +279,7 @@ editundo()
} }
block *p = *(block **)undos.lastItem; block *p = *(block **)undos.lastItem;
[undos removeLastItem]; [undos removeLastItem];
blockpaste(*p); blockpaste(p);
OFFreeMemory(p); OFFreeMemory(p);
} }
@ -291,7 +291,7 @@ copy()
EDITSELMP; EDITSELMP;
if (copybuf) if (copybuf)
OFFreeMemory(copybuf); OFFreeMemory(copybuf);
copybuf = blockcopy(sel); copybuf = blockcopy(&sel);
} }
void void
@ -312,7 +312,7 @@ paste()
makeundo(); makeundo();
copybuf->x = sel.x; copybuf->x = sel.x;
copybuf->y = sel.y; copybuf->y = sel.y;
blockpaste(*copybuf); blockpaste(copybuf);
} }
void void
@ -351,7 +351,7 @@ editdrag(bool isDown)
// strictly triggered locally. They all have very similar structure. // strictly triggered locally. They all have very similar structure.
void void
editheightxy(bool isfloor, int amount, block &sel) editheightxy(bool isfloor, int amount, const block *sel)
{ {
loopselxy( loopselxy(
if (isfloor) { if (isfloor) {
@ -370,13 +370,13 @@ editheight(int flr, int amount)
{ {
EDITSEL; EDITSEL;
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, const block *sel)
{ {
loopselxy(switch (type) { loopselxy(switch (type) {
case 0: case 0:
@ -409,7 +409,7 @@ edittex(int type, int dir)
i = i < 0 ? 0 : i + dir; i = i < 0 ? 0 : i + dir;
curedittex[atype] = i = min(max(i, 0), 255); curedittex[atype] = i = min(max(i, 0), 255);
int t = lasttex = hdr.texlists[atype][i]; int t = lasttex = hdr.texlists[atype][i];
edittexxy(type, t, sel); edittexxy(type, t, &sel);
addmsg(1, 7, SV_EDITT, sel.x, sel.y, sel.xs, sel.ys, type, t); addmsg(1, 7, SV_EDITT, sel.x, sel.y, sel.xs, sel.ys, type, t);
} }
@ -440,11 +440,11 @@ replace()
} }
} }
block b = { 0, 0, ssize, ssize }; block b = { 0, 0, ssize, ssize };
remip(b); remip(&b);
} }
void void
edittypexy(int type, block &sel) edittypexy(int type, const block *sel)
{ {
loopselxy(s->type = type); loopselxy(s->type = type);
} }
@ -459,7 +459,7 @@ edittype(int type)
conoutf(@"corner selection must be power of 2 aligned"); conoutf(@"corner selection must be power of 2 aligned");
return; return;
} }
edittypexy(type, sel); edittypexy(type, &sel);
addmsg(1, 6, SV_EDITS, sel.x, sel.y, sel.xs, sel.ys, type); addmsg(1, 6, SV_EDITS, sel.x, sel.y, sel.xs, sel.ys, type);
} }
@ -485,7 +485,7 @@ corner()
COMMAND(corner, ARG_NONE) COMMAND(corner, ARG_NONE)
void void
editequalisexy(bool isfloor, block &sel) editequalisexy(bool isfloor, const block *sel)
{ {
int low = 127, hi = -128; int low = 127, hi = -128;
loopselxy({ loopselxy({
@ -509,13 +509,13 @@ equalize(int flr)
{ {
bool isfloor = flr == 0; bool isfloor = flr == 0;
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, const block *sel)
{ {
loopselxy(s->vdelta = max(s->vdelta + delta, 0)); loopselxy(s->vdelta = max(s->vdelta + delta, 0));
remipmore(sel); remipmore(sel);
@ -525,7 +525,7 @@ void
setvdelta(int delta) setvdelta(int delta)
{ {
EDITSEL; EDITSEL;
setvdeltaxy(delta, sel); setvdeltaxy(delta, &sel);
addmsg(1, 6, SV_EDITD, sel.x, sel.y, sel.xs, sel.ys, delta); addmsg(1, 6, SV_EDITD, sel.x, sel.y, sel.xs, sel.ys, delta);
} }
@ -555,11 +555,14 @@ arch(int sidedelta, int _a)
sel.xs = MAXARCHVERT; sel.xs = MAXARCHVERT;
if (sel.ys > MAXARCHVERT) if (sel.ys > MAXARCHVERT)
sel.ys = MAXARCHVERT; sel.ys = MAXARCHVERT;
loopselxy(s->vdelta = sel.xs > sel.ys block *sel_ = &sel;
? (archverts[sel.xs - 1][x] + // Ugly hack to make the macro work.
(y == 0 || y == sel.ys - 1 ? sidedelta : 0)) block *sel = sel_;
: (archverts[sel.ys - 1][y] + loopselxy(s->vdelta = sel->xs > sel->ys
(x == 0 || x == sel.xs - 1 ? sidedelta : 0))); ? (archverts[sel->xs - 1][x] +
(y == 0 || y == sel->ys - 1 ? sidedelta : 0))
: (archverts[sel->ys - 1][y] +
(x == 0 || x == sel->xs - 1 ? sidedelta : 0)));
remipmore(sel); remipmore(sel);
} }
@ -574,6 +577,9 @@ slope(int xd, int yd)
off -= yd * sel.ys; off -= yd * sel.ys;
sel.xs++; sel.xs++;
sel.ys++; sel.ys++;
block *sel_ = &sel;
// Ugly hack to make the macro work.
block *sel = sel_;
loopselxy(s->vdelta = xd * x + yd * y + off); loopselxy(s->vdelta = xd * x + yd * y + off);
remipmore(sel); remipmore(sel);
} }
@ -587,10 +593,10 @@ perlin(int scale, int seed, int psize)
makeundo(); makeundo();
sel.xs--; sel.xs--;
sel.ys--; sel.ys--;
perlinarea(sel, scale, seed, psize); perlinarea(&sel, scale, seed, psize);
sel.xs++; sel.xs++;
sel.ys++; sel.ys++;
remipmore(sel); remipmore(&sel);
sel.xs--; sel.xs--;
sel.ys--; sel.ys--;
} }
@ -606,6 +612,9 @@ void
edittag(int tag) edittag(int tag)
{ {
EDITSELMP; EDITSELMP;
block *sel_ = &sel;
// Ugly hack to make the macro work.
block *sel = sel_;
loopselxy(s->tag = tag); loopselxy(s->tag = tag);
} }

View file

@ -336,7 +336,7 @@ checkquad(int time)
} }
void void
putitems(uchar *&p) // puts items in network stream and also spawns them locally putitems(uchar **p) // puts items in network stream and also spawns them locally
{ {
[ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) {
if ((e.type >= I_SHELLS && e.type <= I_QUAD) || if ((e.type >= I_SHELLS && e.type <= I_QUAD) ||

View file

@ -283,7 +283,8 @@ monsteraction(DynamicEntity *m)
if (m.trigger < lastmillis) { if (m.trigger < lastmillis) {
m.lastaction = 0; m.lastaction = 0;
m.attacking = true; m.attacking = true;
shoot(m, m.attacktarget); OFVector3D attacktarget = m.attacktarget;
shoot(m, &attacktarget);
transition(m, M_ATTACKING, 0, 600, 0); transition(m, M_ATTACKING, 0, 600, 0);
} }
break; break;

View file

@ -114,8 +114,8 @@ extern void renderscores();
// world // world
extern void setupworld(int factor); extern void setupworld(int factor);
extern void empty_world(int factor, bool force); extern void empty_world(int factor, bool force);
extern void remip(block &b, int level = 0); extern void remip(const block *b, int level = 0);
extern void remipmore(const block &b, int level = 0); extern void remipmore(const block *b, int level = 0);
extern int closestent(); extern int closestent();
extern int findentity(int type, int index = 0); extern int findentity(int type, int index = 0);
extern void trigger(int tag, int type, bool savegame); extern void trigger(int tag, int type, bool savegame);
@ -126,11 +126,11 @@ extern Entity *newentity(
// worldlight // worldlight
extern void calclight(); extern void calclight();
extern void dodynlight(const OFVector3D &vold, const OFVector3D &v, int reach, extern void dodynlight(const OFVector3D *vold, const OFVector3D *v, int reach,
int strength, DynamicEntity *owner); int strength, DynamicEntity *owner);
extern void cleardlights(); extern void cleardlights();
extern block *blockcopy(block &b); extern block *blockcopy(const block *b);
extern void blockpaste(const block &b); extern void blockpaste(const block *b);
// worldrender // worldrender
extern void render_world(float vx, float vy, float vh, int yaw, int pitch, extern void render_world(float vx, float vy, float vh, int yaw, int pitch,
@ -154,20 +154,20 @@ extern void draw_envbox(int t, int fogdist);
extern void cursorupdate(); extern void cursorupdate();
extern void toggleedit(); extern void toggleedit();
extern void editdrag(bool isdown); extern void editdrag(bool isdown);
extern void setvdeltaxy(int delta, block &sel); extern void setvdeltaxy(int delta, const block *sel);
extern void editequalisexy(bool isfloor, block &sel); extern void editequalisexy(bool isfloor, const block *sel);
extern void edittypexy(int type, block &sel); extern void edittypexy(int type, const block *sel);
extern void edittexxy(int type, int t, block &sel); extern void edittexxy(int type, int t, const block *sel);
extern void editheightxy(bool isfloor, int amount, block &sel); extern void editheightxy(bool isfloor, int amount, const block *sel);
extern bool noteditmode(); extern bool noteditmode();
extern void pruneundos(int maxremain = 0); extern void pruneundos(int maxremain = 0);
// renderextras // renderextras
extern void line(int x1, int y1, float z1, int x2, int y2, float z2); extern void line(int x1, int y1, float z1, int x2, int y2, float z2);
extern void box(block &b, float z1, float z2, float z3, float z4); extern void box(const block *b, float z1, float z2, float z3, float z4);
extern void dot(int x, int y, float z); extern void dot(int x, int y, float z);
extern void linestyle(float width, int r, int g, int b); extern void linestyle(float width, int r, int g, int b);
extern void newsphere(const OFVector3D &o, float max, int type); extern void newsphere(const OFVector3D *o, float max, int type);
extern void renderspheres(int time); extern void renderspheres(int time);
extern void gl_drawhud( extern void gl_drawhud(
int w, int h, int curfps, int nquads, int curvert, bool underwater); int w, int h, int curfps, int nquads, int curvert, bool underwater);
@ -176,10 +176,10 @@ extern void blendbox(int x1, int y1, int x2, int y2, bool border);
extern void damageblend(int n); extern void damageblend(int n);
// renderparticles // renderparticles
extern void setorient(OFVector3D &r, OFVector3D &u); extern void setorient(const OFVector3D *r, const OFVector3D *u);
extern void particle_splash(int type, int num, int fade, const OFVector3D &p); extern void particle_splash(int type, int num, int fade, const OFVector3D *p);
extern void particle_trail( extern void particle_trail(
int type, int fade, OFVector3D &from, OFVector3D &to); int type, int fade, const OFVector3D *from, const OFVector3D *to);
extern void render_particles(int time); extern void render_particles(int time);
// worldio // worldio
@ -192,7 +192,7 @@ extern void incomingdemodata(uchar *buf, int len, bool extras = false);
extern void demoplaybackstep(); extern void demoplaybackstep();
extern void stop(); extern void stop();
extern void stopifrecording(); extern void stopifrecording();
extern void demodamage(int damage, const OFVector3D &o); extern void demodamage(int damage, const OFVector3D *o);
extern void demoblend(int damage); extern void demoblend(int damage);
// physics // physics
@ -223,9 +223,9 @@ extern void localconnect();
extern void localdisconnect(); extern void localdisconnect();
extern void localclienttoserver(struct _ENetPacket *); extern void localclienttoserver(struct _ENetPacket *);
extern void serverslice(int seconds, unsigned int timeout); extern void serverslice(int seconds, unsigned int timeout);
extern void putint(uchar *&p, int n); extern void putint(uchar **p, int n);
extern int getint(uchar *&p); extern int getint(uchar **p);
extern void sendstring(OFString *t, uchar *&p); extern void sendstring(OFString *t, uchar **p);
extern void startintermission(); extern void startintermission();
extern void restoreserverstate(OFArray<Entity *> *ents); extern void restoreserverstate(OFArray<Entity *> *ents);
extern uchar *retrieveservers(uchar *buf, int buflen); extern uchar *retrieveservers(uchar *buf, int buflen);
@ -238,10 +238,10 @@ extern ENetPacket *recvmap(int n);
// weapon // weapon
extern void selectgun(int a = -1, int b = -1, int c = -1); extern void selectgun(int a = -1, int b = -1, int c = -1);
extern void shoot(DynamicEntity *d, const OFVector3D &to); extern void shoot(DynamicEntity *d, const OFVector3D *to);
extern void shootv(int gun, OFVector3D &from, OFVector3D &to, extern void shootv(int gun, const OFVector3D *from, const OFVector3D *to,
DynamicEntity *d = 0, bool local = false); DynamicEntity *d = 0, bool local = false);
extern void createrays(OFVector3D &from, OFVector3D &to); extern void createrays(const OFVector3D *from, const OFVector3D *to);
extern void moveprojectiles(float time); extern void moveprojectiles(float time);
extern void projreset(); extern void projreset();
extern OFString *playerincrosshair(); extern OFString *playerincrosshair();
@ -259,7 +259,7 @@ extern void endsp(bool allkilled);
// entities // entities
extern void initEntities(); extern void initEntities();
extern void renderents(); extern void renderents();
extern void putitems(uchar *&p); extern void putitems(uchar **p);
extern void checkquad(int time); extern void checkquad(int time);
extern void checkitems(); extern void checkitems();
extern void realpickup(int n, DynamicEntity *d); extern void realpickup(int n, DynamicEntity *d);
@ -270,4 +270,4 @@ extern void teleport(int n, DynamicEntity *d);
extern void baseammo(int gun); extern void baseammo(int gun);
// rndmap // rndmap
extern void perlinarea(block &b, int scale, int seed, int psize); extern void perlinarea(const block *b, int scale, int seed, int psize);

View file

@ -25,13 +25,13 @@ linestyle(float width, int r, int g, int b)
} }
void void
box(block &b, float z1, float z2, float z3, float z4) box(const block *b, float z1, float z2, float z3, float z4)
{ {
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glVertex3f((float)b.x, z1, (float)b.y); glVertex3f((float)b->x, z1, (float)b->y);
glVertex3f((float)b.x + b.xs, z2, (float)b.y); glVertex3f((float)b->x + b->xs, z2, (float)b->y);
glVertex3f((float)b.x + b.xs, z3, (float)b.y + b.ys); glVertex3f((float)b->x + b->xs, z3, (float)b->y + b->ys);
glVertex3f((float)b.x, z4, (float)b.y + b.ys); glVertex3f((float)b->x, z4, (float)b->y + b->ys);
glEnd(); glEnd();
xtraverts += 4; xtraverts += 4;
} }
@ -92,7 +92,7 @@ sphere spheres[MAXSPHERES], *slist = NULL, *sempty = NULL;
bool sinit = false; bool sinit = false;
void void
newsphere(const OFVector3D &o, float max, int type) newsphere(const OFVector3D *o, float max, int type)
{ {
if (!sinit) { if (!sinit) {
loopi(MAXSPHERES) loopi(MAXSPHERES)
@ -105,7 +105,7 @@ newsphere(const OFVector3D &o, float max, int type)
if (sempty) { if (sempty) {
sphere *p = sempty; sphere *p = sempty;
sempty = p->next; sempty = p->next;
p->o = o; p->o = *o;
p->max = max; p->max = max;
p->size = 1; p->size = 1;
p->type = type; p->type = type;
@ -190,7 +190,7 @@ renderents()
continue; continue;
OFVector3D v = OFMakeVector3D(e.x, e.y, e.z); OFVector3D v = OFMakeVector3D(e.x, e.y, e.z);
particle_splash(2, 2, 40, v); particle_splash(2, 2, 40, &v);
} }
int e = closestent(); int e = closestent();
@ -276,7 +276,7 @@ readdepth(int w, int h)
worldpos.z = (float)worldz; worldpos.z = (float)worldz;
OFVector3D r = OFMakeVector3D(mm[0], mm[4], mm[8]); OFVector3D r = OFMakeVector3D(mm[0], mm[4], mm[8]);
OFVector3D u = OFMakeVector3D(mm[1], mm[5], mm[9]); OFVector3D u = OFMakeVector3D(mm[1], mm[5], mm[9]);
setorient(r, u); setorient(&r, &u);
} }
void void

View file

@ -18,7 +18,7 @@ bool parinit = false;
VARP(maxparticles, 100, 2000, MAXPARTICLES - 500); VARP(maxparticles, 100, 2000, MAXPARTICLES - 500);
static void static void
newparticle(const OFVector3D &o, const OFVector3D &d, int fade, int type) newparticle(const OFVector3D *o, const OFVector3D *d, int fade, int type)
{ {
if (!parinit) { if (!parinit) {
loopi(MAXPARTICLES) loopi(MAXPARTICLES)
@ -31,8 +31,8 @@ newparticle(const OFVector3D &o, const OFVector3D &d, int fade, int type)
if (parempty) { if (parempty) {
particle *p = parempty; particle *p = parempty;
parempty = p->next; parempty = p->next;
p->o = o; p->o = *o;
p->d = d; p->d = *d;
p->fade = fade; p->fade = fade;
p->type = type; p->type = type;
p->millis = lastmillis; p->millis = lastmillis;
@ -47,18 +47,19 @@ VARP(particlesize, 20, 100, 500);
OFVector3D right, up; OFVector3D right, up;
void void
setorient(OFVector3D &r, OFVector3D &u) setorient(const OFVector3D *r, const OFVector3D *u)
{ {
right = r; right = *r;
up = u; up = *u;
} }
void void
render_particles(int time) render_particles(int time)
{ {
if (demoplayback && demotracking) { if (demoplayback && demotracking) {
OFVector3D o = player1.o;
OFVector3D nom = OFMakeVector3D(0, 0, 0); OFVector3D nom = OFMakeVector3D(0, 0, 0);
newparticle(player1.o, nom, 100000000, 8); newparticle(&o, &nom, 100000000, 8);
} }
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
@ -135,7 +136,7 @@ render_particles(int time)
} }
void void
particle_splash(int type, int num, int fade, const OFVector3D &p) particle_splash(int type, int num, int fade, const OFVector3D *p)
{ {
loopi(num) loopi(num)
{ {
@ -146,21 +147,22 @@ particle_splash(int type, int num, int fade, const OFVector3D &p)
y = rnd(radius * 2) - radius; y = rnd(radius * 2) - radius;
z = rnd(radius * 2) - radius; z = rnd(radius * 2) - radius;
} while (x * x + y * y + z * z > radius * radius); } while (x * x + y * y + z * z > radius * radius);
newparticle(p, OFMakeVector3D(x, y, z), rnd(fade * 3), type); OFVector3D d = OFMakeVector3D(x, y, z);
newparticle(p, &d, rnd(fade * 3), type);
} }
} }
void void
particle_trail(int type, int fade, OFVector3D &s, OFVector3D &e) particle_trail(int type, int fade, const OFVector3D *s, const OFVector3D *e)
{ {
vdist(d, v, s, e); vdist(d, v, *s, *e);
vdiv(v, d * 2 + 0.1f); vdiv(v, d * 2 + 0.1f);
OFVector3D p = s; OFVector3D p = *s;
loopi((int)d * 2) loopi((int)d * 2)
{ {
vadd(p, v); vadd(p, v);
OFVector3D d = OFVector3D d =
OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5); OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5);
newparticle(p, d, rnd(fade) + fade, type); newparticle(&p, &d, rnd(fade) + fade, type);
} }
} }

View file

@ -67,16 +67,16 @@ perlinnoise_2D(float x, float y, int seedstep, float pers)
} }
void void
perlinarea(block &b, int scale, int seed, int psize) perlinarea(const block *b, int scale, int seed, int psize)
{ {
srand(seed); srand(seed);
seed = rnd(10000); seed = rnd(10000);
if (!scale) if (!scale)
scale = 10; scale = 10;
for (int x = b.x; x <= b.x + b.xs; x++) { for (int x = b->x; x <= b->x + b->xs; x++) {
for (int y = b.y; y <= b.y + b.ys; y++) { for (int y = b->y; y <= b->y + b->ys; y++) {
sqr *s = S(x, y); sqr *s = S(x, y);
if (!SOLID(s) && x != b.x + b.xs && y != b.y + b.ys) if (!SOLID(s) && x != b->x + b->xs && y != b->y + b->ys)
s->type = FHF; s->type = FHF;
s->vdelta = s->vdelta =
(int)(perlinnoise_2D(x / ((float)scale) + seed, (int)(perlinnoise_2D(x / ((float)scale) + seed,

View file

@ -291,10 +291,10 @@ record(OFString *name)
COMMAND(record, ARG_1STR) COMMAND(record, ARG_1STR)
void void
demodamage(int damage, const OFVector3D &o) demodamage(int damage, const OFVector3D *o)
{ {
ddamage = damage; ddamage = damage;
dorig = o; dorig = *o;
} }
void void
@ -454,7 +454,7 @@ demoplaybackstep()
damageblend(bdamage); damageblend(bdamage);
if ((ddamage = gzgeti())) { if ((ddamage = gzgeti())) {
gzgetv(dorig); gzgetv(dorig);
particle_splash(3, ddamage, 1000, dorig); particle_splash(3, ddamage, 1000, &dorig);
} }
// FIXME: set more client state here // FIXME: set more client state here
} }

View file

@ -70,8 +70,8 @@ send2(bool rel, int cn, int a, int b)
enet_packet_create(NULL, 32, rel ? ENET_PACKET_FLAG_RELIABLE : 0); enet_packet_create(NULL, 32, rel ? ENET_PACKET_FLAG_RELIABLE : 0);
uchar *start = packet->data; uchar *start = packet->data;
uchar *p = start + 2; uchar *p = start + 2;
putint(p, a); putint(&p, a);
putint(p, b); putint(&p, b);
*(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);
if (cn < 0) if (cn < 0)
@ -89,8 +89,8 @@ sendservmsg(OFString *msg)
NULL, _MAXDEFSTR + 10, ENET_PACKET_FLAG_RELIABLE); NULL, _MAXDEFSTR + 10, ENET_PACKET_FLAG_RELIABLE);
uchar *start = packet->data; uchar *start = packet->data;
uchar *p = start + 2; uchar *p = start + 2;
putint(p, SV_SERVMSG); putint(&p, SV_SERVMSG);
sendstring(msg, p); sendstring(msg, &p);
*(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);
multicast(packet, -1); multicast(packet, -1);
@ -190,7 +190,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
int cn = -1, type; int cn = -1, type;
while (p < end) { while (p < end) {
switch ((type = getint(p))) { switch ((type = getint(&p))) {
case SV_TEXT: case SV_TEXT:
sgetstr(); sgetstr();
break; break;
@ -199,12 +199,12 @@ process(ENetPacket *packet, int sender) // sender may be -1
sgetstr(); sgetstr();
clients[cn].name = @(text); clients[cn].name = @(text);
sgetstr(); sgetstr();
getint(p); getint(&p);
break; break;
case SV_MAPCHANGE: { case SV_MAPCHANGE: {
sgetstr(); sgetstr();
int reqmode = getint(p); int reqmode = getint(&p);
if (reqmode < 0) if (reqmode < 0)
reqmode = 0; reqmode = 0;
if (smapname.length > 0 && !mapreload && if (smapname.length > 0 && !mapreload &&
@ -223,7 +223,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
case SV_ITEMLIST: { case SV_ITEMLIST: {
int n; int n;
while ((n = getint(p)) != -1) while ((n = getint(&p)) != -1)
if (notgotitems) { if (notgotitems) {
while (sents.count <= n) while (sents.count <= n)
[sents addObject:[ServerEntity [sents addObject:[ServerEntity
@ -235,17 +235,17 @@ process(ENetPacket *packet, int sender) // sender may be -1
} }
case SV_ITEMPICKUP: { case SV_ITEMPICKUP: {
int n = getint(p); int n = getint(&p);
pickup(n, getint(p), sender); pickup(n, getint(&p), sender);
break; break;
} }
case SV_PING: case SV_PING:
send2(false, cn, SV_PONG, getint(p)); send2(false, cn, SV_PONG, getint(&p));
break; break;
case SV_POS: { case SV_POS: {
cn = getint(p); cn = getint(&p);
if (cn < 0 || cn >= clients.count || if (cn < 0 || cn >= clients.count ||
clients[cn].type == ST_EMPTY) { clients[cn].type == ST_EMPTY) {
disconnect_client(sender, @"client num"); disconnect_client(sender, @"client num");
@ -253,13 +253,13 @@ process(ENetPacket *packet, int sender) // sender may be -1
} }
int size = msgsizelookup(type); int size = msgsizelookup(type);
assert(size != -1); assert(size != -1);
loopi(size - 2) getint(p); loopi(size - 2) getint(&p);
break; break;
} }
case SV_SENDMAP: { case SV_SENDMAP: {
sgetstr(); sgetstr();
int mapsize = getint(p); int mapsize = getint(&p);
sendmaps(sender, @(text), mapsize, p); sendmaps(sender, @(text), mapsize, p);
return; return;
} }
@ -270,8 +270,8 @@ process(ENetPacket *packet, int sender) // sender may be -1
// allows for new features that require no server updates // allows for new features that require no server updates
case SV_EXT: case SV_EXT:
for (int n = getint(p); n; n--) for (int n = getint(&p); n; n--)
getint(p); getint(&p);
break; break;
default: { default: {
@ -280,7 +280,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
disconnect_client(sender, @"tag type"); disconnect_client(sender, @"tag type");
return; return;
} }
loopi(size - 1) getint(p); loopi(size - 1) getint(&p);
} }
} }
} }
@ -300,23 +300,23 @@ send_welcome(int n)
enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE); enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
uchar *start = packet->data; uchar *start = packet->data;
__block uchar *p = start + 2; __block uchar *p = start + 2;
putint(p, SV_INITS2C); putint(&p, SV_INITS2C);
putint(p, n); putint(&p, n);
putint(p, PROTOCOL_VERSION); putint(&p, PROTOCOL_VERSION);
putint(p, *smapname.UTF8String); putint(&p, *smapname.UTF8String);
sendstring(serverpassword, p); sendstring(serverpassword, &p);
putint(p, clients.count > maxclients); putint(&p, clients.count > maxclients);
if (smapname.length > 0) { if (smapname.length > 0) {
putint(p, SV_MAPCHANGE); putint(&p, SV_MAPCHANGE);
sendstring(smapname, p); sendstring(smapname, &p);
putint(p, mode); putint(&p, mode);
putint(p, SV_ITEMLIST); putint(&p, SV_ITEMLIST);
[sents enumerateObjectsUsingBlock:^( [sents enumerateObjectsUsingBlock:^(
ServerEntity *e, size_t i, bool *stop) { ServerEntity *e, size_t i, bool *stop) {
if (e.spawned) if (e.spawned)
putint(p, i); putint(&p, i);
}]; }];
putint(p, -1); putint(&p, -1);
} }
*(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);

View file

@ -138,7 +138,7 @@ pingservers()
continue; continue;
p = ping; p = ping;
putint(p, lastmillis); putint(&p, lastmillis);
buf.data = ping; buf.data = ping;
buf.dataLength = p - ping; buf.dataLength = p - ping;
ENetAddress address = si.address; ENetAddress address = si.address;
@ -185,13 +185,13 @@ checkpings()
for (ServerInfo *si in servers) { for (ServerInfo *si in servers) {
if (addr.host == si.address.host) { if (addr.host == si.address.host) {
p = ping; p = ping;
si.ping = lastmillis - getint(p); si.ping = lastmillis - getint(&p);
si.protocol = getint(p); si.protocol = getint(&p);
if (si.protocol != PROTOCOL_VERSION) if (si.protocol != PROTOCOL_VERSION)
si.ping = 9998; si.ping = 9998;
si.mode = getint(p); si.mode = getint(&p);
si.numplayers = getint(p); si.numplayers = getint(&p);
si.minremain = getint(p); si.minremain = getint(&p);
sgetstr(); sgetstr();
si.map = @(text); si.map = @(text);
sgetstr(); sgetstr();

View file

@ -136,15 +136,15 @@ serverms(int mode, int numplayers, int minremain, OFString *smapname,
if (len < 0) if (len < 0)
return; return;
p = &pong[len]; p = &pong[len];
putint(p, PROTOCOL_VERSION); putint(&p, PROTOCOL_VERSION);
putint(p, mode); putint(&p, mode);
putint(p, numplayers); putint(&p, numplayers);
putint(p, minremain); putint(&p, minremain);
OFString *mname = OFString *mname =
[OFString stringWithFormat:@"%@%@", [OFString stringWithFormat:@"%@%@",
(isfull ? @"[FULL] " : @""), smapname]; (isfull ? @"[FULL] " : @""), smapname];
sendstring(mname, p); sendstring(mname, &p);
sendstring(serverdesc, p); sendstring(serverdesc, &p);
buf.dataLength = p - pong; buf.dataLength = p - pong;
enet_socket_send(pongsock, &addr, &buf, 1); enet_socket_send(pongsock, &addr, &buf, 1);
} }

View file

@ -6,44 +6,44 @@
// following simple scheme (assumes that most values are small). // following simple scheme (assumes that most values are small).
void void
putint(uchar *&p, int n) putint(uchar **p, int n)
{ {
if (n < 128 && n > -127) { if (n < 128 && n > -127) {
*p++ = n; *(*p)++ = n;
} else if (n < 0x8000 && n >= -0x8000) { } else if (n < 0x8000 && n >= -0x8000) {
*p++ = 0x80; *(*p)++ = 0x80;
*p++ = n; *(*p)++ = n;
*p++ = n >> 8; *(*p)++ = n >> 8;
} else { } else {
*p++ = 0x81; *(*p)++ = 0x81;
*p++ = n; *(*p)++ = n;
*p++ = n >> 8; *(*p)++ = n >> 8;
*p++ = n >> 16; *(*p)++ = n >> 16;
*p++ = n >> 24; *(*p)++ = n >> 24;
} }
} }
int int
getint(uchar *&p) getint(uchar **p)
{ {
int c = *((char *)p); int c = *((char *)*p);
p++; (*p)++;
if (c == -128) { if (c == -128) {
int n = *p++; int n = *(*p)++;
n |= *((char *)p) << 8; n |= *((char *)*p) << 8;
p++; (*p)++;
return n; return n;
} else if (c == -127) { } else if (c == -127) {
int n = *p++; int n = *(*p)++;
n |= *p++ << 8; n |= *(*p)++ << 8;
n |= *p++ << 16; n |= *(*p)++ << 16;
return n | (*p++ << 24); return n | (*(*p)++ << 24);
} else } else
return c; return c;
} }
void void
sendstring(OFString *t_, uchar *&p) sendstring(OFString *t_, uchar **p)
{ {
const char *t = t_.UTF8String; const char *t = t_.UTF8String;
@ -122,9 +122,9 @@ recvmap(int n)
NULL, MAXTRANS + copysize, ENET_PACKET_FLAG_RELIABLE); NULL, MAXTRANS + copysize, ENET_PACKET_FLAG_RELIABLE);
uchar *start = packet->data; uchar *start = packet->data;
uchar *p = start + 2; uchar *p = start + 2;
putint(p, SV_RECVMAP); putint(&p, SV_RECVMAP);
sendstring(copyname, p); sendstring(copyname, &p);
putint(p, copysize); putint(&p, copysize);
memcpy(p, copydata, copysize); memcpy(p, copydata, copysize);
p += copysize; p += copysize;
*(ushort *)start = ENET_HOST_TO_NET_16(p - start); *(ushort *)start = ENET_HOST_TO_NET_16(p - start);

View file

@ -70,41 +70,41 @@ weapon(OFString *a1, OFString *a2, OFString *a3)
} }
COMMAND(weapon, ARG_3STR) COMMAND(weapon, ARG_3STR)
// create random spread of rays for the shotgun
void void
createrays(OFVector3D &from, createrays(const OFVector3D *from, const OFVector3D *to)
OFVector3D &to) // create random spread of rays for the shotgun
{ {
vdist(dist, dvec, from, to); vdist(dist, dvec, *from, *to);
float f = dist * SGSPREAD / 1000; float f = dist * SGSPREAD / 1000;
loopi(SGRAYS) loopi(SGRAYS)
{ {
#define RNDD (rnd(101) - 50) * f #define RNDD (rnd(101) - 50) * f
OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD); OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD);
sg[i] = to; sg[i] = *to;
vadd(sg[i], r); vadd(sg[i], r);
} }
} }
// if lineseg hits entity bounding box // if lineseg hits entity bounding box
bool static bool
intersect(DynamicEntity *d, const OFVector3D &from, const OFVector3D &to) intersect(DynamicEntity *d, const OFVector3D *from, const OFVector3D *to)
{ {
OFVector3D v = to, w = d.o; OFVector3D v = *to, w = d.o;
const OFVector3D *p; const OFVector3D *p;
vsub(v, from); vsub(v, *from);
vsub(w, from); vsub(w, *from);
float c1 = dotprod(w, v); float c1 = dotprod(w, v);
if (c1 <= 0) if (c1 <= 0)
p = &from; p = from;
else { else {
float c2 = dotprod(v, v); float c2 = dotprod(v, v);
if (c2 <= c1) if (c2 <= c1)
p = &to; p = to;
else { else {
float f = c1 / c2; float f = c1 / c2;
vmul(v, f); vmul(v, f);
vadd(v, from); vadd(v, *from);
p = &v; p = &v;
} }
} }
@ -124,7 +124,8 @@ playerincrosshair()
if (player == [OFNull null]) if (player == [OFNull null])
continue; continue;
if (intersect(player, player1.o, worldpos)) OFVector3D o = player1.o;
if (intersect(player, &o, &worldpos))
return [player name]; return [player name];
} }
@ -142,8 +143,8 @@ projreset()
} }
void void
newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local, newprojectile(const OFVector3D *from, const OFVector3D *to, float speed,
DynamicEntity *owner, int gun) bool local, DynamicEntity *owner, int gun)
{ {
for (size_t i = 0; i < MAXPROJ; i++) { for (size_t i = 0; i < MAXPROJ; i++) {
Projectile *p = projs[i]; Projectile *p = projs[i];
@ -155,8 +156,8 @@ newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local,
continue; continue;
p.inuse = true; p.inuse = true;
p.o = from; p.o = *from;
p.to = to; p.to = *to;
p.speed = speed; p.speed = speed;
p.local = local; p.local = local;
p.owner = owner; p.owner = owner;
@ -168,17 +169,17 @@ newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local,
void void
hit(int target, int damage, DynamicEntity *d, DynamicEntity *at) hit(int target, int damage, DynamicEntity *d, DynamicEntity *at)
{ {
OFVector3D o = d.o;
if (d == player1) if (d == player1)
selfdamage(damage, at == player1 ? -1 : -2, at); selfdamage(damage, at == player1 ? -1 : -2, at);
else if (d.monsterstate) else if (d.monsterstate)
monsterpain(d, damage, at); monsterpain(d, damage, at);
else { else {
addmsg(1, 4, SV_DAMAGE, target, damage, d.lifesequence); addmsg(1, 4, SV_DAMAGE, target, damage, d.lifesequence);
OFVector3D loc = d.o; playsound(S_PAIN1 + rnd(5), &o);
playsound(S_PAIN1 + rnd(5), &loc);
} }
particle_splash(3, damage, 1000, d.o); particle_splash(3, damage, 1000, &o);
demodamage(damage, d.o); demodamage(damage, &o);
} }
const float RL_RADIUS = 5; const float RL_RADIUS = 5;
@ -186,11 +187,11 @@ const float RL_DAMRAD = 7; // hack
static void static void
radialeffect( radialeffect(
DynamicEntity *o, const OFVector3D &v, int cn, int qdam, DynamicEntity *at) DynamicEntity *o, const OFVector3D *v, int cn, int qdam, DynamicEntity *at)
{ {
if (o.state != CS_ALIVE) if (o.state != CS_ALIVE)
return; return;
vdist(dist, temp, v, o.o); vdist(dist, temp, *v, o.o);
dist -= 2; // account for eye distance imprecision dist -= 2; // account for eye distance imprecision
if (dist < RL_DAMRAD) { if (dist < RL_DAMRAD) {
if (dist < 0) if (dist < 0)
@ -203,17 +204,17 @@ radialeffect(
} }
void void
splash(Projectile *p, const OFVector3D &v, const OFVector3D &vold, splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold,
int notthisplayer, int notthismonster, int qdam) int notthisplayer, int notthismonster, int qdam)
{ {
particle_splash(0, 50, 300, v); particle_splash(0, 50, 300, v);
p.inuse = false; p.inuse = false;
if (p.gun != GUN_RL) { if (p.gun != GUN_RL) {
playsound(S_FEXPLODE, &v); playsound(S_FEXPLODE, v);
// no push? // no push?
} else { } else {
playsound(S_RLHIT, &v); playsound(S_RLHIT, v);
newsphere(v, RL_RADIUS, 0); newsphere(v, RL_RADIUS, 0);
dodynlight(vold, v, 0, 0, p.owner); dodynlight(vold, v, 0, 0, p.owner);
@ -242,14 +243,15 @@ splash(Projectile *p, const OFVector3D &v, const OFVector3D &vold,
} }
inline void inline void
projdamage( projdamage(DynamicEntity *o, Projectile *p, const OFVector3D *v, int i, int im,
DynamicEntity *o, Projectile *p, OFVector3D &v, int i, int im, int qdam) int qdam)
{ {
if (o.state != CS_ALIVE) if (o.state != CS_ALIVE)
return; return;
if (intersect(o, p.o, v)) { OFVector3D po = p.o;
splash(p, v, p.o, i, im, qdam); if (intersect(o, &po, v)) {
splash(p, v, &po, i, im, qdam);
hit(i, qdam, o, p.owner); hit(i, qdam, o, p.owner);
} }
} }
@ -275,27 +277,29 @@ moveprojectiles(float time)
if (p.local) { if (p.local) {
for (id player in players) for (id player in players)
if (player != [OFNull null]) if (player != [OFNull null])
projdamage(player, p, v, i, -1, qdam); projdamage(player, p, &v, i, -1, qdam);
if (p.owner != player1) if (p.owner != player1)
projdamage(player1, p, v, -1, -1, qdam); projdamage(player1, p, &v, -1, -1, qdam);
for (DynamicEntity *monster in getmonsters()) for (DynamicEntity *monster in getmonsters())
if (!vreject(monster.o, v, 10.0f) && if (!vreject(monster.o, v, 10.0f) &&
monster != p.owner) monster != p.owner)
projdamage(monster, p, v, -1, i, qdam); projdamage(monster, p, &v, -1, i, qdam);
} }
if (p.inuse) { if (p.inuse) {
OFVector3D po = p.o;
if (time == dtime) if (time == dtime)
splash(p, v, p.o, -1, -1, qdam); splash(p, &v, &po, -1, -1, qdam);
else { else {
if (p.gun == GUN_RL) { if (p.gun == GUN_RL) {
dodynlight(p.o, v, 0, 255, p.owner); dodynlight(&po, &v, 0, 255, p.owner);
particle_splash(5, 2, 200, v); particle_splash(5, 2, 200, &v);
} else { } else {
particle_splash(1, 1, 200, v); particle_splash(1, 1, 200, &v);
particle_splash( particle_splash(
guns[p.gun].part, 1, 1, v); guns[p.gun].part, 1, 1, &v);
} }
} }
} }
@ -305,7 +309,8 @@ moveprojectiles(float time)
// create visual effect from a shot // create visual effect from a shot
void void
shootv(int gun, OFVector3D &from, OFVector3D &to, DynamicEntity *d, bool local) shootv(int gun, const OFVector3D *from, const OFVector3D *to, DynamicEntity *d,
bool local)
{ {
OFVector3D loc = d.o; OFVector3D loc = d.o;
playsound(guns[gun].sound, d == player1 ? NULL : &loc); playsound(guns[gun].sound, d == player1 ? NULL : &loc);
@ -315,7 +320,7 @@ shootv(int gun, OFVector3D &from, OFVector3D &to, DynamicEntity *d, bool local)
break; break;
case GUN_SG: { case GUN_SG: {
loopi(SGRAYS) particle_splash(0, 5, 200, sg[i]); loopi(SGRAYS) particle_splash(0, 5, 200, &sg[i]);
break; break;
} }
@ -343,16 +348,16 @@ shootv(int gun, OFVector3D &from, OFVector3D &to, DynamicEntity *d, bool local)
void void
hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at, hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
const OFVector3D &from, const OFVector3D &to) const OFVector3D *from, const OFVector3D *to)
{ {
hit(target, damage, d, at); hit(target, damage, d, at);
vdist(dist, v, from, to); vdist(dist, v, *from, *to);
vmul(v, damage / dist / 50); vmul(v, damage / dist / 50);
vadd(d.vel, v); vadd(d.vel, v);
} }
void void
raydamage(DynamicEntity *o, const OFVector3D &from, const OFVector3D &to, raydamage(DynamicEntity *o, const OFVector3D *from, const OFVector3D *to,
DynamicEntity *d, int i) DynamicEntity *d, int i)
{ {
if (o.state != CS_ALIVE) if (o.state != CS_ALIVE)
@ -364,7 +369,7 @@ raydamage(DynamicEntity *o, const OFVector3D &from, const OFVector3D &to,
qdam /= MONSTERDAMAGEFACTOR; qdam /= MONSTERDAMAGEFACTOR;
if (d.gunselect == GUN_SG) { if (d.gunselect == GUN_SG) {
int damage = 0; int damage = 0;
loop(r, SGRAYS) if (intersect(o, from, sg[r])) damage += qdam; loop(r, SGRAYS) if (intersect(o, from, &sg[r])) damage += qdam;
if (damage) if (damage)
hitpush(i, damage, o, d, from, to); hitpush(i, damage, o, d, from, to);
} else if (intersect(o, from, to)) } else if (intersect(o, from, to))
@ -372,7 +377,7 @@ raydamage(DynamicEntity *o, const OFVector3D &from, const OFVector3D &to,
} }
void void
shoot(DynamicEntity *d, const OFVector3D &targ) shoot(DynamicEntity *d, const OFVector3D *targ)
{ {
int attacktime = lastmillis - d.lastaction; int attacktime = lastmillis - d.lastaction;
if (attacktime < d.gunwait) if (attacktime < d.gunwait)
@ -391,7 +396,7 @@ shoot(DynamicEntity *d, const OFVector3D &targ)
if (d.gunselect) if (d.gunselect)
d.ammo[d.gunselect]--; d.ammo[d.gunselect]--;
OFVector3D from = d.o; OFVector3D from = d.o;
OFVector3D to = targ; OFVector3D to = *targ;
from.z -= 0.2f; // below eye from.z -= 0.2f; // below eye
vdist(dist, unitv, from, to); vdist(dist, unitv, from, to);
@ -408,11 +413,11 @@ shoot(DynamicEntity *d, const OFVector3D &targ)
vadd(to, unitv); vadd(to, unitv);
} }
if (d.gunselect == GUN_SG) if (d.gunselect == GUN_SG)
createrays(from, to); createrays(&from, &to);
if (d.quadmillis && attacktime > 200) if (d.quadmillis && attacktime > 200)
playsoundc(S_ITEMPUP); playsoundc(S_ITEMPUP);
shootv(d.gunselect, from, to, d, true); shootv(d.gunselect, &from, &to, d, true);
if (!d.monsterstate) if (!d.monsterstate)
addmsg(1, 8, SV_SHOT, d.gunselect, (int)(from.x * DMF), addmsg(1, 8, SV_SHOT, d.gunselect, (int)(from.x * DMF),
(int)(from.y * DMF), (int)(from.z * DMF), (int)(to.x * DMF), (int)(from.y * DMF), (int)(from.z * DMF), (int)(to.x * DMF),
@ -424,13 +429,13 @@ shoot(DynamicEntity *d, const OFVector3D &targ)
[players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) { [players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) {
if (player != [OFNull null]) if (player != [OFNull null])
raydamage(player, from, to, d, i); raydamage(player, &from, &to, d, i);
}]; }];
for (DynamicEntity *monster in getmonsters()) for (DynamicEntity *monster in getmonsters())
if (monster != d) if (monster != d)
raydamage(monster, from, to, d, -2); raydamage(monster, &from, &to, d, -2);
if (d.monsterstate) if (d.monsterstate)
raydamage(player1, from, to, d, -1); raydamage(player1, &from, &to, d, -1);
} }

View file

@ -42,7 +42,7 @@ settag(int tag, int type)
} }
block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 }; block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
if (maxx) if (maxx)
remip(b); // remip minimal area of changed geometry remip(&b); // remip minimal area of changed geometry
} }
void void
@ -90,16 +90,17 @@ COMMAND(trigger, ARG_2INT)
// rendering time if this is possible). // rendering time if this is possible).
void void
remip(block &b, int level) remip(const block *b, int level)
{ {
if (level >= SMALLEST_FACTOR) if (level >= SMALLEST_FACTOR)
return; return;
int lighterr = getvar(@"lighterror") * 3; int lighterr = getvar(@"lighterror") * 3;
sqr *w = wmip[level]; sqr *w = wmip[level];
sqr *v = wmip[level + 1]; sqr *v = wmip[level + 1];
int ws = ssize >> level; int ws = ssize >> level;
int vs = ssize >> (level + 1); int vs = ssize >> (level + 1);
block s = b; block s = *b;
if (s.x & 1) { if (s.x & 1) {
s.x--; s.x--;
s.xs++; s.xs++;
@ -117,15 +118,15 @@ remip(block &b, int level)
o[1] = SWS(w, x + 1, y, ws); o[1] = SWS(w, x + 1, y, ws);
o[2] = SWS(w, x + 1, y + 1, ws); o[2] = SWS(w, x + 1, y + 1, ws);
o[3] = SWS(w, x, y + 1, ws); o[3] = SWS(w, x, y + 1, ws);
sqr *r = SWS(v, x / 2, y / 2, // the target cube in the higher mip level
vs); // the target cube in the higher mip level sqr *r = SWS(v, x / 2, y / 2, vs);
*r = *o[0]; *r = *o[0];
uchar nums[MAXTYPE]; uchar nums[MAXTYPE];
loopi(MAXTYPE) nums[i] = 0; loopi(MAXTYPE) nums[i] = 0;
loopj(4) nums[o[j]->type]++; loopj(4) nums[o[j]->type]++;
r->type = // cube contains both solid and space, treated
SEMISOLID; // cube contains both solid and space, // specially in the renderer
// treated specially in the renderer r->type = SEMISOLID;
loopk(MAXTYPE) if (nums[k] == 4) r->type = k; loopk(MAXTYPE) if (nums[k] == 4) r->type = k;
if (!SOLID(r)) { if (!SOLID(r)) {
int floor = 127, ceil = -128, num = 0; int floor = 127, ceil = -128, num = 0;
@ -136,28 +137,26 @@ remip(block &b, int level)
int ch = o[i]->ceil; int ch = o[i]->ceil;
if (r->type == SEMISOLID) { if (r->type == SEMISOLID) {
if (o[i]->type == FHF) if (o[i]->type == FHF)
// crap hack, needed
// for rendering large
// mips next to hfs
fh -= o[i]->vdelta / 4 + fh -= o[i]->vdelta / 4 +
2; // crap hack, 2;
// needed for
// rendering
// large mips
// next to hfs
if (o[i]->type == CHF) if (o[i]->type == CHF)
// FIXME: needs to
// somehow take into
// account middle
// vertices on higher
// mips
ch += o[i]->vdelta / 4 + ch += o[i]->vdelta / 4 +
2; // FIXME: needs 2;
// to somehow
// take into
// account middle
// vertices on
// higher mips
} }
if (fh < floor) if (fh < floor)
floor = // take lowest floor and
fh; // take lowest floor and // highest ceil, so we never
// highest ceil, so we // have to see missing
// never have to see // lower/upper from the side
// missing lower/upper floor = fh;
// from the side
if (ch > ceil) if (ch > ceil)
ceil = ch; ceil = ch;
} }
@ -165,32 +164,33 @@ remip(block &b, int level)
r->ceil = ceil; r->ceil = ceil;
} }
if (r->type == CORNER) if (r->type == CORNER)
goto mip; // special case: don't ever split even // special case: don't ever split even if
// if textures etc are different // textures etc are different
goto mip;
r->defer = 1; r->defer = 1;
if (SOLID(r)) { if (SOLID(r)) {
loopi(3) loopi(3)
{ {
if (o[i]->wtex != o[3]->wtex) if (o[i]->wtex != o[3]->wtex)
goto c; // on an all solid cube, // on an all solid cube, only
// only thing that needs // thing that needs to be equal
// to be equal for a // for a perfect mip is the
// perfect mip is the // wall texture
// wall texture goto c;
} }
} else { } else {
loopi(3) loopi(3)
{ {
// perfect mip even if light is not
// exactly equal
if (o[i]->type != o[3]->type || if (o[i]->type != o[3]->type ||
o[i]->floor != o[3]->floor || o[i]->floor != o[3]->floor ||
o[i]->ceil != o[3]->ceil || o[i]->ceil != o[3]->ceil ||
o[i]->ftex != o[3]->ftex || o[i]->ftex != o[3]->ftex ||
o[i]->ctex != o[3]->ctex || o[i]->ctex != o[3]->ctex ||
abs(o[i + 1]->r - o[0]->r) > abs(o[i + 1]->r - o[0]->r) >
lighterr // perfect mip even if lighterr ||
// light is not exactly abs(o[i + 1]->g - o[0]->g) >
// equal
|| abs(o[i + 1]->g - o[0]->g) >
lighterr || lighterr ||
abs(o[i + 1]->b - o[0]->b) > abs(o[i + 1]->b - o[0]->b) >
lighterr || lighterr ||
@ -198,11 +198,10 @@ remip(block &b, int level)
o[i]->wtex != o[3]->wtex) o[i]->wtex != o[3]->wtex)
goto c; goto c;
} }
if (r->type == CHF ||
r->type == // can make a perfect mip out of a hf if slopes
FHF) // can make a perfect mip out of a // lie on one line
// hf if slopes lie on one line if (r->type == CHF || r->type == FHF) {
{
if (o[0]->vdelta - o[1]->vdelta != if (o[0]->vdelta - o[1]->vdelta !=
o[1]->vdelta - o[1]->vdelta -
SWS(w, x + 2, y, ws) SWS(w, x + 2, y, ws)
@ -227,9 +226,10 @@ remip(block &b, int level)
} }
} }
{ {
// if any of the constituents is not perfect,
// then this one isn't either
loopi(4) if (o[i]->defer) goto c; loopi(4) if (o[i]->defer) goto c;
} // if any of the constituents is not perfect, then }
// this one isn't either
mip: mip:
r->defer = 0; r->defer = 0;
c:; c:;
@ -238,13 +238,14 @@ remip(block &b, int level)
s.y /= 2; s.y /= 2;
s.xs /= 2; s.xs /= 2;
s.ys /= 2; s.ys /= 2;
remip(s, level + 1); remip(&s, level + 1);
} }
void void
remipmore(const block &b, int level) remipmore(const block *b, int level)
{ {
block bb = b; block bb = *b;
if (bb.x > 1) if (bb.x > 1)
bb.x--; bb.x--;
if (bb.y > 1) if (bb.y > 1)
@ -253,7 +254,8 @@ remipmore(const block &b, int level)
bb.xs++; bb.xs++;
if (bb.ys < ssize - 3) if (bb.ys < ssize - 3)
bb.ys++; bb.ys++;
remip(bb, level);
remip(&bb, level);
} }
int int
@ -506,7 +508,7 @@ empty_world(int factor, bool force)
loopk(3) loopi(256) hdr.texlists[k][i] = i; loopk(3) loopi(256) hdr.texlists[k][i] = i;
[ents removeAllObjects]; [ents removeAllObjects];
block b = { 8, 8, ssize - 16, ssize - 16 }; block b = { 8, 8, ssize - 16, ssize - 16 };
edittypexy(SPACE, b); edittypexy(SPACE, &b);
} }
calclight(); calclight();

View file

@ -165,7 +165,7 @@ postlightarea(block &a) // median filter, smooths out random noise in light and
median(b); median(b);
} }
remip(a); remip(&a);
} }
void void
@ -196,13 +196,13 @@ cleardlights()
while (dlights.count > 0) { while (dlights.count > 0) {
block *backup = *(block **)[dlights lastItem]; block *backup = *(block **)[dlights lastItem];
[dlights removeLastItem]; [dlights removeLastItem];
blockpaste(*backup); blockpaste(backup);
OFFreeMemory(backup); OFFreeMemory(backup);
} }
} }
void void
dodynlight(const OFVector3D &vold, const OFVector3D &v, int reach, int strength, dodynlight(const OFVector3D *vold, const OFVector3D *v, int reach, int strength,
DynamicEntity *owner) DynamicEntity *owner)
{ {
if (!reach) if (!reach)
@ -211,11 +211,11 @@ dodynlight(const OFVector3D &vold, const OFVector3D &v, int reach, int strength,
reach = reach / 2; reach = reach / 2;
if (!reach) if (!reach)
return; return;
if (v.x < 0 || v.y < 0 || v.x > ssize || v.y > ssize) if (v->x < 0 || v->y < 0 || v->x > ssize || v->y > ssize)
return; return;
int creach = reach + 16; // dependant on lightray random offsets! int creach = reach + 16; // dependant on lightray random offsets!
block b = { (int)v.x - creach, (int)v.y - creach, creach * 2 + 1, block b = { (int)v->x - creach, (int)v->y - creach, creach * 2 + 1,
creach * 2 + 1 }; creach * 2 + 1 };
if (b.x < 1) if (b.x < 1)
@ -232,13 +232,13 @@ dodynlight(const OFVector3D &vold, const OFVector3D &v, int reach, int strength,
[[OFMutableData alloc] initWithItemSize:sizeof(block *)]; [[OFMutableData alloc] initWithItemSize:sizeof(block *)];
// backup area before rendering in dynlight // backup area before rendering in dynlight
block *copy = blockcopy(b); block *copy = blockcopy(&b);
[dlights addItem:&copy]; [dlights addItem:&copy];
PersistentEntity *l = [Entity entity]; PersistentEntity *l = [Entity entity];
l.x = v.x; l.x = v->x;
l.y = v.y; l.y = v->y;
l.z = v.z; l.z = v->z;
l.attr1 = reach; l.attr1 = reach;
l.type = LIGHT; l.type = LIGHT;
l.attr2 = strength; l.attr2 = strength;
@ -249,24 +249,24 @@ dodynlight(const OFVector3D &vold, const OFVector3D &v, int reach, int strength,
// utility functions also used by editing code // utility functions also used by editing code
block * block *
blockcopy(block &s) blockcopy(const block *s)
{ {
block *b = (block *)OFAllocZeroedMemory( block *b = (block *)OFAllocZeroedMemory(
1, sizeof(block) + s.xs * s.ys * sizeof(sqr)); 1, sizeof(block) + s->xs * s->ys * sizeof(sqr));
*b = s; *b = *s;
sqr *q = (sqr *)(b + 1); sqr *q = (sqr *)(b + 1);
for (int x = s.x; x < s.xs + s.x; x++) for (int x = s->x; x < s->xs + s->x; x++)
for (int y = s.y; y < s.ys + s.y; y++) for (int y = s->y; y < s->ys + s->y; y++)
*q++ = *S(x, y); *q++ = *S(x, y);
return b; return b;
} }
void void
blockpaste(const block &b) blockpaste(const block *b)
{ {
sqr *q = (sqr *)((&b) + 1); sqr *q = (sqr *)(b + 1);
for (int x = b.x; x < b.xs + b.x; x++) for (int x = b->x; x < b->xs + b->x; x++)
for (int y = b.y; y < b.ys + b.y; y++) for (int y = b->y; y < b->ys + b->y; y++)
*S(x, y) = *q++; *S(x, y) = *q++;
remipmore(b); remipmore(b);
} }