Remove loop[ijkl]

They confused clang-format a lot.

FossilOrigin-Name: 6b85eefc857c74c00d7ef693e312cc15df53201a6712aee8ba8d57c643c1703b
This commit is contained in:
Jonathan Schleifer 2025-03-23 02:47:40 +00:00
parent 2c5f2d0342
commit 006dba8370
22 changed files with 318 additions and 257 deletions

View file

@ -127,8 +127,7 @@ snap(int sn, float f)
struct md2_frame *cf = struct md2_frame *cf =
(struct md2_frame *)((char *)_frames + _frameSize * frame); (struct md2_frame *)((char *)_frames + _frameSize * frame);
float sc = 16.0f / scale; float sc = 16.0f / scale;
loop(vi, _numVerts) for (int vi = 0; vi < _numVerts; vi++) {
{
uchar *cv = (uchar *)&cf->vertices[vi].vertex; uchar *cv = (uchar *)&cf->vertices[vi].vertex;
OFVector3D *v = &(_mverts[frame])[vi]; OFVector3D *v = &(_mverts[frame])[vi];
v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc; v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc;
@ -149,9 +148,9 @@ snap(int sn, float f)
snap:(int)sn snap:(int)sn
basetime:(int)basetime basetime:(int)basetime
{ {
loopi(range) if (!_mverts[frame + i])[self scaleWithFrame:frame + i for (int i = 0; i < range; i++)
scale:sc if (!_mverts[frame + i])
snap:sn]; [self scaleWithFrame:frame + i scale:sc snap:sn];
glPushMatrix(); glPushMatrix();
glTranslatef(position.x, position.y, position.z); glTranslatef(position.x, position.y, position.z);
@ -192,8 +191,7 @@ snap(int sn, float f)
numVertex = -numVertex; numVertex = -numVertex;
} }
loopi(numVertex) for (int i = 0; i < numVertex; i++) {
{
float tu = *((float *)command++); float tu = *((float *)command++);
float tv = *((float *)command++); float tv = *((float *)command++);
glTexCoord2f(tu, tv); glTexCoord2f(tu, tv);

View file

@ -198,8 +198,8 @@ updateworld(int millis) // main game update loop
void void
entinmap(DynamicEntity *d) entinmap(DynamicEntity *d)
{ {
loopi(100) // try max 100 times // try max 100 times
{ for (int i = 0; i < 100; i++) {
float dx = (rnd(21) - 10) / 10.0f * i; // increasing distance float dx = (rnd(21) - 10) / 10.0f * i; // increasing distance
float dy = (rnd(21) - 10) / 10.0f * i; float dy = (rnd(21) - 10) / 10.0f * i;
OFVector3D old = d.origin; OFVector3D old = d.origin;
@ -221,7 +221,8 @@ void
spawnplayer(DynamicEntity *d) spawnplayer(DynamicEntity *d)
{ {
int r = fixspawn-- > 0 ? 4 : rnd(10) + 1; int r = fixspawn-- > 0 ? 4 : rnd(10) + 1;
loopi(r) spawncycle = findentity(PLAYERSTART, spawncycle + 1); for (int i = 0; i < r; i++)
spawncycle = findentity(PLAYERSTART, spawncycle + 1);
if (spawncycle != -1) { if (spawncycle != -1) {
d.origin = OFMakeVector3D( d.origin = OFMakeVector3D(
ents[spawncycle].x, ents[spawncycle].y, ents[spawncycle].z); ents[spawncycle].x, ents[spawncycle].y, ents[spawncycle].z);

View file

@ -213,8 +213,7 @@ addmsg(int rel, int num, int type, ...)
va_list marker; va_list marker;
va_start(marker, type); va_start(marker, type);
loopi(num - 1) for (int i = 0; i < num - 1; i++) {
{
int tmp = va_arg(marker, int); int tmp = va_arg(marker, int);
[msg addItem:&tmp]; [msg addItem:&tmp];
} }
@ -345,7 +344,7 @@ c2sinfo(DynamicEntity *d)
// 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]) for (int i = 0; i < *(int *)[msg itemAtIndex:0]; i++)
putint(&p, *(int *)[msg itemAtIndex:i + 2]); putint(&p, *(int *)[msg itemAtIndex:i + 2]);
} }
[messages removeAllObjects]; [messages removeAllObjects];

View file

@ -240,8 +240,7 @@ execute(OFString *string, bool isDown)
for (bool cont = true; cont;) { for (bool cont = true; cont;) {
// for each ; seperated statement // for each ; seperated statement
int numargs = MAXWORDS; int numargs = MAXWORDS;
loopi(MAXWORDS) for (int i = 0; i < MAXWORDS; i++) {
{
// collect all argument values // collect all argument values
w[i] = @""; w[i] = @"";
if (i > numargs) if (i > numargs)
@ -421,8 +420,7 @@ loopa(OFString *times, OFString *body)
{ {
int t = times.cube_intValue; int t = times.cube_intValue;
loopi(t) for (int i = 0; i < t; i++) {
{
intset(@"i", i); intset(@"i", i);
execute(body, true); execute(body, true);
} }
@ -477,8 +475,7 @@ at(OFString *s_, OFString *pos)
char *copy __attribute__((__cleanup__(cleanup))) = char *copy __attribute__((__cleanup__(cleanup))) =
strdup(s_.UTF8String); strdup(s_.UTF8String);
char *s = copy; char *s = copy;
loopi(n) for (int i = 0; i < n; i++) {
{
s += strcspn(s, " \0"); s += strcspn(s, " \0");
s += strspn(s, " "); s += strspn(s, " ");
} }

View file

@ -95,12 +95,10 @@ renderconsole()
i++; i++;
} }
loopj(nd) for (int j = 0; j < nd; j++)
{
draw_text(refs[j], FONTH / 3, draw_text(refs[j], FONTH / 3,
(FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2); (FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2);
} }
}
// keymap is defined externally in keymap.cfg // keymap is defined externally in keymap.cfg

View file

@ -33,11 +33,12 @@ bool selset = false;
#define loopselxy(b) \ #define loopselxy(b) \
{ \ { \
makeundo(); \ makeundo(); \
loop(x, sel->xs) loop(y, sel->ys) \ for (int x = 0; x < sel->xs; x++) { \
{ \ for (int y = 0; y < sel->ys; y++) { \
struct sqr *s = S(sel->x + x, sel->y + y); \ struct sqr *s = S(sel->x + x, sel->y + y); \
b; \ b; \
} \ } \
} \
remip(sel, 0); \ remip(sel, 0); \
} }
@ -291,8 +292,10 @@ void
copy() copy()
{ {
EDITSELMP; EDITSELMP;
if (copybuf) if (copybuf)
OFFreeMemory(copybuf); OFFreeMemory(copybuf);
copybuf = blockcopy(&sel); copybuf = blockcopy(&sel);
} }
@ -321,8 +324,7 @@ void
tofronttex() // maintain most recently used of the texture lists when applying tofronttex() // maintain most recently used of the texture lists when applying
// texture // texture
{ {
loopi(3) for (int i = 0; i < 3; i++) {
{
int c = curedittex[i]; int c = curedittex[i];
if (c >= 0) { if (c >= 0) {
uchar *p = hdr.texlists[i]; uchar *p = hdr.texlists[i];
@ -371,6 +373,7 @@ void
editheight(int flr, int amount) 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);
@ -400,12 +403,15 @@ void
edittex(int type, int dir) edittex(int type, int dir)
{ {
EDITSEL; EDITSEL;
if (type < 0 || type > 3) if (type < 0 || type > 3)
return; return;
if (type != lasttype) { if (type != lasttype) {
tofronttex(); tofronttex();
lasttype = type; lasttype = type;
} }
int atype = type == 3 ? 1 : type; int atype = type == 3 ? 1 : type;
int i = curedittex[atype]; int i = curedittex[atype];
i = i < 0 ? 0 : i + dir; i = i < 0 ? 0 : i + dir;
@ -419,8 +425,9 @@ void
replace() replace()
{ {
EDITSELMP; EDITSELMP;
loop(x, ssize) loop(y, ssize)
{ for (int x = 0; x < ssize; x++) {
for (int y = 0; y < ssize; y++) {
struct sqr *s = S(x, y); struct sqr *s = S(x, y);
switch (lasttype) { switch (lasttype) {
case 0: case 0:
@ -441,6 +448,8 @@ replace()
break; break;
} }
} }
}
struct block b = { 0, 0, ssize, ssize }; struct block b = { 0, 0, ssize, ssize };
remip(&b, 0); remip(&b, 0);
} }
@ -455,12 +464,14 @@ void
edittype(int type) edittype(int type)
{ {
EDITSEL; EDITSEL;
if (type == CORNER && if (type == CORNER &&
(sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 && sel.xs != 8) || (sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 && sel.xs != 8) ||
sel.x & ~-sel.xs || sel.y & ~-sel.ys)) { sel.x & ~-sel.xs || sel.y & ~-sel.ys)) {
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);
} }
@ -509,8 +520,10 @@ editequalisexy(bool isfloor, const struct block *sel)
void void
equalize(int flr) 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);
} }
@ -527,6 +540,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);
} }
@ -540,7 +554,9 @@ archvertex(int span, int vert, int delta)
{ {
if (!archvinit) { if (!archvinit) {
archvinit = true; archvinit = true;
loop(s, MAXARCHVERT) loop(v, MAXARCHVERT) archverts[s][v] = 0; for (int s = 0; s < MAXARCHVERT; s++)
for (int v = 0; v < MAXARCHVERT; v++)
archverts[s][v] = 0;
} }
if (span >= MAXARCHVERT || vert >= MAXARCHVERT || span < 0 || vert < 0) if (span >= MAXARCHVERT || vert >= MAXARCHVERT || span < 0 || vert < 0)
return; return;
@ -551,12 +567,15 @@ void
arch(int sidedelta, int _a) arch(int sidedelta, int _a)
{ {
EDITSELMP; EDITSELMP;
sel.xs++; sel.xs++;
sel.ys++; sel.ys++;
if (sel.xs > MAXARCHVERT) if (sel.xs > MAXARCHVERT)
sel.xs = MAXARCHVERT; sel.xs = MAXARCHVERT;
if (sel.ys > MAXARCHVERT) if (sel.ys > MAXARCHVERT)
sel.ys = MAXARCHVERT; sel.ys = MAXARCHVERT;
struct block *sel_ = &sel; struct block *sel_ = &sel;
// Ugly hack to make the macro work. // Ugly hack to make the macro work.
struct block *sel = sel_; struct block *sel = sel_;
@ -572,13 +591,16 @@ void
slope(int xd, int yd) slope(int xd, int yd)
{ {
EDITSELMP; EDITSELMP;
int off = 0; int off = 0;
if (xd < 0) if (xd < 0)
off -= xd * sel.xs; off -= xd * sel.xs;
if (yd < 0) if (yd < 0)
off -= yd * sel.ys; off -= yd * sel.ys;
sel.xs++; sel.xs++;
sel.ys++; sel.ys++;
struct block *sel_ = &sel; struct block *sel_ = &sel;
// Ugly hack to make the macro work. // Ugly hack to make the macro work.
struct block *sel = sel_; struct block *sel = sel_;
@ -590,15 +612,22 @@ void
perlin(int scale, int seed, int psize) perlin(int scale, int seed, int psize)
{ {
EDITSELMP; EDITSELMP;
sel.xs++; sel.xs++;
sel.ys++; sel.ys++;
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, 0); remipmore(&sel, 0);
sel.xs--; sel.xs--;
sel.ys--; sel.ys--;
} }
@ -607,13 +636,15 @@ VARF(
fullbright, 0, 0, 1, if (fullbright) { fullbright, 0, 0, 1, if (fullbright) {
if (noteditmode()) if (noteditmode())
return; return;
loopi(mipsize) world[i].r = world[i].g = world[i].b = 176; for (int i = 0; i < mipsize; i++)
world[i].r = world[i].g = world[i].b = 176;
}); });
void void
edittag(int tag) edittag(int tag)
{ {
EDITSELMP; EDITSELMP;
struct block *sel_ = &sel; struct block *sel_ = &sel;
// Ugly hack to make the macro work. // Ugly hack to make the macro work.
struct block *sel = sel_; struct block *sel = sel_;
@ -624,6 +655,7 @@ void
newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4) newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4)
{ {
EDITSEL; EDITSEL;
newentity(sel.x, sel.y, (int)player1.origin.z, what, newentity(sel.x, sel.y, (int)player1.origin.z, what,
[a1 cube_intValueWithBase:0], [a2 cube_intValueWithBase:0], [a1 cube_intValueWithBase:0], [a2 cube_intValueWithBase:0],
[a3 cube_intValueWithBase:0], [a4 cube_intValueWithBase:0]); [a3 cube_intValueWithBase:0], [a4 cube_intValueWithBase:0]);

View file

@ -61,8 +61,7 @@ rendermenu()
title = m.name; title = m.name;
int mdisp = m.items.count; int mdisp = m.items.count;
int w = 0; int w = 0;
loopi(mdisp) for (int i = 0; i < mdisp; i++) {
{
int x = text_width(m.items[i].text); int x = text_width(m.items[i].text);
if (x > w) if (x > w)
w = x; w = x;
@ -83,8 +82,7 @@ rendermenu()
blendbox( blendbox(
x - FONTH, bh - 10, x + w + FONTH, bh + FONTH + 10, false); x - FONTH, bh - 10, x + w + FONTH, bh + FONTH + 10, false);
} }
loopj(mdisp) for (int j = 0; j < mdisp; j++) {
{
draw_text(m.items[j].text, x, y, 2); draw_text(m.items[j].text, x, y, 2);
y += step; y += step;
} }

View file

@ -358,8 +358,8 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime)
// extra smoothness when lifting up stairs // extra smoothness when lifting up stairs
const float rise = speed / moveres / 1.2f; const float rise = speed / moveres / 1.2f;
loopi(moveres) // discrete steps collision detection & sliding // discrete steps collision detection & sliding
{ for (int i = 0; i < moveres; i++) {
// try move forward // try move forward
pl.origin = OFAddVector3D(pl.origin, pl.origin = OFAddVector3D(pl.origin,
OFMakeVector3D(f * d.x, f * d.y, f * d.z)); OFMakeVector3D(f * d.x, f * d.y, f * d.z));
@ -441,7 +441,9 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime)
void void
moveplayer(DynamicEntity *pl, int moveres, bool local) moveplayer(DynamicEntity *pl, int moveres, bool local)
{ {
loopi(physicsrepeat) moveplayer4(pl, moveres, local, for (int i = 0; i < physicsrepeat; i++)
moveplayer4(pl, moveres, local,
i ? curtime / physicsrepeat i ? curtime / physicsrepeat
: curtime - curtime / physicsrepeat * (physicsrepeat - 1)); : curtime -
curtime / physicsrepeat * (physicsrepeat - 1));
} }

View file

@ -95,8 +95,7 @@ void
newsphere(const OFVector3D *o, float max, int type) newsphere(const OFVector3D *o, float max, int type)
{ {
if (!sinit) { if (!sinit) {
loopi(MAXSPHERES) for (int i = 0; i < MAXSPHERES; i++) {
{
spheres[i].next = sempty; spheres[i].next = sempty;
sempty = &spheres[i]; sempty = &spheres[i];
} }
@ -218,8 +217,7 @@ loadsky(OFString *basename)
static const OFString *side[] = { @"ft", @"bk", @"lf", @"rt", @"dn", static const OFString *side[] = { @"ft", @"bk", @"lf", @"rt", @"dn",
@"up" }; @"up" };
int texnum = 14; int texnum = 14;
loopi(6) for (int i = 0; i < 6; i++) {
{
OFString *path = [OFString OFString *path = [OFString
stringWithFormat:@"packages/%@_%@.jpg", basename, side[i]]; stringWithFormat:@"packages/%@_%@.jpg", basename, side[i]];

View file

@ -112,8 +112,7 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
} }
#if 0 #if 0
loopi(s->w * s->h * 3) for (int i = 0; i < s->w * s->h * 3; i++) {
{
uchar *p = (uchar *)s->pixels + i; uchar *p = (uchar *)s->pixels + i;
*p = 255 - *p; *p = 255 - *p;
} }
@ -179,7 +178,9 @@ static OFString *mapname[256][MAXFRAMES];
void void
purgetextures() purgetextures()
{ {
loopi(256) loop(j, MAXFRAMES) mapping[i][j] = 0; for (int i = 0; i < 256; i++)
for (int j = 0; j < MAXFRAMES; j++)
mapping[i][j] = 0;
} }
int curtexnum = 0; int curtexnum = 0;
@ -221,8 +222,8 @@ lookuptexture(int tex, int *xs, int *ys)
if (tid == 0) if (tid == 0)
return 1; // crosshair :) return 1; // crosshair :)
loopi(curtex) // lazily happens once per "texture" command, basically // lazily happens once per "texture" command, basically
{ for (int i = 0; i < curtex; i++) {
if ([mapname[tex][frame] isEqual:texname[i]]) { if ([mapname[tex][frame] isEqual:texname[i]]) {
mapping[tex][frame] = tid = i + FIRSTTEX; mapping[tex][frame] = tid = i + FIRSTTEX;
*xs = texx[i]; *xs = texx[i];

View file

@ -21,8 +21,7 @@ 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) for (int i = 0; i < MAXPARTICLES; i++) {
{
particles[i].next = parempty; particles[i].next = parempty;
parempty = &particles[i]; parempty = &particles[i];
} }
@ -138,8 +137,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) for (int i = 0; i < num; i++) {
{
const int radius = type == 5 ? 50 : 150; const int radius = type == 5 ? 50 : 150;
int x, y, z; int x, y, z;
do { do {
@ -158,8 +156,7 @@ 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) for (int i = 0; i < ((int)d * 2); i++) {
{
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);

View file

@ -245,13 +245,14 @@ loadgamerest()
[Monster restoreAll]; [Monster restoreAll];
int nplayers = gzgeti(); int nplayers = gzgeti();
loopi(nplayers) if (!gzget()) for (int i = 0; i < nplayers; i++) {
{ if (!gzget()) {
DynamicEntity *d = getclient(i); DynamicEntity *d = getclient(i);
assert(d); assert(d);
gzread(f, data.mutableItems, data.count); gzread(f, data.mutableItems, data.count);
[d setFromSerializedData:data]; [d setFromSerializedData:data];
} }
}
conoutf(@"savegame restored"); conoutf(@"savegame restored");
if (demoloading) if (demoloading)
@ -321,7 +322,8 @@ incomingdemodata(uchar *buf, int len, bool extras)
gzputi(player1.health); gzputi(player1.health);
gzputi(player1.armour); gzputi(player1.armour);
gzput(player1.armourType); gzput(player1.armourType);
loopi(NUMGUNS) gzput(player1.ammo[i]); for (int i = 0; i < NUMGUNS; i++)
gzput(player1.ammo[i]);
gzput(player1.state); gzput(player1.state);
gzputi(bdamage); gzputi(bdamage);
bdamage = 0; bdamage = 0;
@ -448,7 +450,8 @@ demoplaybackstep()
target.health = gzgeti(); target.health = gzgeti();
target.armour = gzgeti(); target.armour = gzgeti();
target.armourType = gzget(); target.armourType = gzget();
loopi(NUMGUNS) target.ammo[i] = gzget(); for (int i = 0; i < NUMGUNS; i++)
target.ammo[i] = gzget();
target.state = gzget(); target.state = gzget();
target.lastMove = playbacktime; target.lastMove = playbacktime;
if ((bdamage = gzgeti())) if ((bdamage = gzgeti()))

View file

@ -253,7 +253,8 @@ 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); for (int i = 0; i < size - 2; i++)
getint(&p);
break; break;
} }
@ -280,7 +281,8 @@ 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); for (int i = 0; i < size - 1; i++)
getint(&p);
} }
} }
} }
@ -546,7 +548,8 @@ initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip,
serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate); serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate);
if (!serverhost) if (!serverhost)
fatal(@"could not create server host\n"); fatal(@"could not create server host\n");
loopi(MAXCLIENTS) serverhost->peers[i].data = (void *)-1; for (int i = 0; i < MAXCLIENTS; i++)
serverhost->peers[i].data = (void *)-1;
} }
resetserverifempty(); resetserverifempty();

View file

@ -146,14 +146,16 @@ updatevol()
{ {
if (nosound) if (nosound)
return; return;
loopi(MAXCHAN) if (soundlocs[i].inuse)
{ for (int i = 0; i < MAXCHAN; i++) {
if (soundlocs[i].inuse) {
if (Mix_Playing(i)) if (Mix_Playing(i))
updatechanvol(i, &soundlocs[i].loc); updatechanvol(i, &soundlocs[i].loc);
else else
soundlocs[i].inuse = false; soundlocs[i].inuse = false;
} }
} }
}
void void
playsoundc(int n) playsoundc(int n)

View file

@ -32,13 +32,9 @@ typedef unsigned int uint;
#define rndreset() (srand(1)) #define rndreset() (srand(1))
#define rndtime() \ #define rndtime() \
{ \ { \
loopi(lastmillis & 0xF) rnd(i + 1); \ for (int i = 0; i < (lastmillis & 0xF); i++) \
rnd(i + 1); \
} }
#define loop(v, m) for (int v = 0; v < (m); v++)
#define loopi(m) loop(i, m)
#define loopj(m) loop(j, m)
#define loopk(m) loop(k, m)
#define loopl(m) loop(l, m)
#ifndef OF_WINDOWS #ifndef OF_WINDOWS
# define __cdecl # define __cdecl

View file

@ -10,11 +10,13 @@ endianswap(
{ {
if (*((char *)&stride)) if (*((char *)&stride))
return; return;
loop(w, length) loop(i, stride / 2)
{ for (int w = 0; w < length; w++) {
for (int i = 0; i < stride / 2; i++) {
uchar *p = (uchar *)memory + w * stride; uchar *p = (uchar *)memory + w * stride;
uchar t = p[i]; uchar t = p[i];
p[i] = p[stride - i - 1]; p[i] = p[stride - i - 1];
p[stride - i - 1] = t; p[stride - i - 1] = t;
} }
} }
}

View file

@ -77,8 +77,7 @@ createrays(const OFVector3D *from, const OFVector3D *to)
{ {
vdist(dist, dvec, *from, *to); vdist(dist, dvec, *from, *to);
float f = dist * SGSPREAD / 1000; float f = dist * SGSPREAD / 1000;
loopi(SGRAYS) for (int i = 0; i < SGRAYS; i++) {
{
#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;
@ -168,7 +167,7 @@ newprojectile(const OFVector3D *from, const OFVector3D *to, float speed,
} }
} }
void static void
hit(int target, int damage, __kindof DynamicEntity *d, DynamicEntity *at) hit(int target, int damage, __kindof DynamicEntity *d, DynamicEntity *at)
{ {
OFVector3D o = d.origin; OFVector3D o = d.origin;
@ -205,7 +204,7 @@ radialeffect(
} }
} }
void static 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)
{ {
@ -322,7 +321,8 @@ shootv(int gun, const OFVector3D *from, const OFVector3D *to, DynamicEntity *d,
break; break;
case GUN_SG: { case GUN_SG: {
loopi(SGRAYS) particle_splash(0, 5, 200, &sg[i]); for (int i = 0; i < SGRAYS; i++)
particle_splash(0, 5, 200, &sg[i]);
break; break;
} }
@ -371,7 +371,9 @@ 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; for (int r = 0; r < SGRAYS; r++)
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))

View file

@ -19,18 +19,19 @@ void
settag(int tag, int type) settag(int tag, int type)
{ {
int maxx = 0, maxy = 0, minx = ssize, miny = ssize; int maxx = 0, maxy = 0, minx = ssize, miny = ssize;
loop(x, ssize) loop(y, ssize) for (int x = 0; x < ssize; x++) {
{ for (int y = 0; y < ssize; y++) {
struct sqr *s = S(x, y); struct sqr *s = S(x, y);
if (s->tag) { if (s->tag) {
if (tag) { if (tag) {
if (tag == s->tag) if (tag == s->tag)
s->type = SPACE; s->type = SPACE;
else else
continue; continue;
} else { } else
s->type = type ? SOLID : SPACE; s->type = type ? SOLID : SPACE;
}
if (x > maxx) if (x > maxx)
maxx = x; maxx = x;
if (y > maxy) if (y > maxy)
@ -41,16 +42,24 @@ settag(int tag, int type)
miny = y; miny = y;
} }
} }
struct block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
if (maxx)
remip(&b, 0); // remip minimal area of changed geometry
} }
if (maxx) {
// remip minimal area of changed geometry
struct block b = { minx, miny, maxx - minx + 1,
maxy - miny + 1 };
remip(&b, 0);
}
}
// reset for editing or map saving
void void
resettagareas() resettagareas()
{ {
settag(0, 0); settag(0, 0);
} // reset for editing or map saving }
// set for playing
void void
settagareas() settagareas()
{ {
@ -60,7 +69,7 @@ settagareas()
if (ents[i].type == CARROT) if (ents[i].type == CARROT)
setspawn(i, true); setspawn(i, true);
}]; }];
} // set for playing }
void void
trigger(int tag, int type, bool savegame) trigger(int tag, int type, bool savegame)
@ -123,43 +132,57 @@ remip(const struct block *b, int level)
struct sqr *r = SWS(v, x / 2, y / 2, vs); struct 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; for (int i = 0; i < MAXTYPE; i++)
loopj(4) nums[o[j]->type]++; nums[i] = 0;
for (int j = 0; j < 4; j++)
nums[o[j]->type]++;
// cube contains both solid and space, treated // cube contains both solid and space, treated
// specially in the renderer // specially in the renderer
r->type = SEMISOLID; r->type = SEMISOLID;
loopk(MAXTYPE) if (nums[k] == 4) r->type = k; for (int k = 0; k < MAXTYPE; k++)
if (nums[k] == 4)
r->type = k;
if (!SOLID(r)) { if (!SOLID(r)) {
int floor = 127, ceil = -128; int floor = 127, ceil = -128;
loopi(4) if (!SOLID(o[i])) for (int i = 0; i < 4; i++) {
{ if (!SOLID(o[i])) {
int fh = o[i]->floor; int fh = o[i]->floor;
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 // crap hack,
// for rendering large // needed for
// mips next to hfs // rendering
fh -= o[i]->vdelta / 4 + // large mips
// next to hfs
fh -=
o[i]->vdelta /
4 +
2; 2;
if (o[i]->type == CHF) if (o[i]->type == CHF)
// FIXME: needs to // FIXME: needs
// somehow take into // to somehow
// account middle // take into
// vertices on higher // account
// mips // middle
ch += o[i]->vdelta / 4 + // vertices on
// higher mips
ch +=
o[i]->vdelta /
4 +
2; 2;
} }
if (fh < floor) if (fh < floor)
// take lowest floor and // 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
// from the side
floor = fh; floor = fh;
if (ch > ceil) if (ch > ceil)
ceil = ch; ceil = ch;
} }
}
r->floor = floor; r->floor = floor;
r->ceil = ceil; r->ceil = ceil;
} }
@ -169,8 +192,7 @@ remip(const struct block *b, int level)
goto mip; goto mip;
r->defer = 1; r->defer = 1;
if (SOLID(r)) { if (SOLID(r)) {
loopi(3) for (int i = 0; i < 3; i++) {
{
if (o[i]->wtex != o[3]->wtex) if (o[i]->wtex != o[3]->wtex)
// on an all solid cube, only // on an all solid cube, only
// thing that needs to be equal // thing that needs to be equal
@ -179,8 +201,7 @@ remip(const struct block *b, int level)
goto c; goto c;
} }
} else { } else {
loopi(3) for (int i = 0; i < 3; i++) {
{
// perfect mip even if light is not // perfect mip even if light is not
// exactly equal // exactly equal
if (o[i]->type != o[3]->type || if (o[i]->type != o[3]->type ||
@ -228,7 +249,9 @@ remip(const struct block *b, int level)
{ {
// if any of the constituents is not perfect, // if any of the constituents is not perfect,
// then this one isn't either // then this one isn't either
loopi(4) if (o[i]->defer) goto c; for (int i = 0; i < 4; i++)
if (o[i]->defer)
goto c;
} }
mip: mip:
r->defer = 0; r->defer = 0;
@ -322,7 +345,9 @@ delent()
int int
findtype(OFString *what) findtype(OFString *what)
{ {
loopi(MAXENTTYPES) if ([what isEqual:entnames[i]]) return i; for (int i = 0; i < MAXENTTYPES; i++)
if ([what isEqual:entnames[i]])
return i;
conoutf(@"unknown entity type \"%@\"", what); conoutf(@"unknown entity type \"%@\"", what);
return NOTUSED; return NOTUSED;
} }
@ -428,7 +453,9 @@ findentity(int type, int index)
for (int i = index; i < ents.count; i++) for (int i = index; i < ents.count; i++)
if (ents[i].type == type) if (ents[i].type == type)
return i; return i;
loopj(index) if (ents[j].type == type) return j; for (int j = 0; j < index; j++)
if (ents[j].type == type)
return j;
return -1; return -1;
} }
@ -442,8 +469,7 @@ setupworld(int factor)
mipsize = cubicsize * 134 / 100; mipsize = cubicsize * 134 / 100;
struct sqr *w = world = struct sqr *w = world =
OFAllocZeroedMemory(mipsize, sizeof(struct sqr)); OFAllocZeroedMemory(mipsize, sizeof(struct sqr));
loopi(LARGEST_FACTOR * 2) for (int i = 0; i < LARGEST_FACTOR * 2; i++) {
{
wmip[i] = w; wmip[i] = w;
w += cubicsize >> (i * 2); w += cubicsize >> (i * 2);
} }
@ -470,8 +496,8 @@ empty_world(int factor, bool force)
factor = LARGEST_FACTOR; factor = LARGEST_FACTOR;
setupworld(factor); setupworld(factor);
loop(x, ssize) loop(y, ssize) for (int x = 0; x < ssize; x++) {
{ for (int y = 0; y < ssize; y++) {
struct sqr *s = S(x, y); struct sqr *s = S(x, y);
s->r = s->g = s->b = 150; s->r = s->g = s->b = 150;
s->ftex = DEFAULT_FLOOR; s->ftex = DEFAULT_FLOOR;
@ -483,6 +509,7 @@ empty_world(int factor, bool force)
s->vdelta = 0; s->vdelta = 0;
s->defer = 0; s->defer = 0;
} }
}
strncpy(hdr.head, "CUBE", 4); strncpy(hdr.head, "CUBE", 4);
hdr.version = MAPVERSION; hdr.version = MAPVERSION;
@ -490,11 +517,12 @@ empty_world(int factor, bool force)
hdr.sfactor = sfactor; hdr.sfactor = sfactor;
if (copy) { if (copy) {
loop(x, ssize / 2) loop(y, ssize / 2) for (int x = 0; x < ssize / 2; x++) {
{ for (int y = 0; y < ssize / 2; y++) {
*S(x + ssize / 4, y + ssize / 4) = *S(x + ssize / 4, y + ssize / 4) =
*SWS(oldworld, x, y, ssize / 2); *SWS(oldworld, x, y, ssize / 2);
} }
}
for (Entity *e in ents) { for (Entity *e in ents) {
e.x += ssize / 4; e.x += ssize / 4;
@ -504,8 +532,11 @@ empty_world(int factor, bool force)
char buffer[128] = "Untitled Map by Unknown"; char buffer[128] = "Untitled Map by Unknown";
memcpy(hdr.maptitle, buffer, 128); memcpy(hdr.maptitle, buffer, 128);
hdr.waterlevel = -100000; hdr.waterlevel = -100000;
loopi(15) hdr.reserved[i] = 0; for (int i = 0; i < 15; i++)
loopk(3) loopi(256) hdr.texlists[k][i] = i; hdr.reserved[i] = 0;
for (int k = 0; k < 3; k++)
for (int i = 0; i < 256; i++)
hdr.texlists[k][i] = i;
[ents removeAllObjects]; [ents removeAllObjects];
struct block b = { 8, 8, ssize - 16, ssize - 16 }; struct block b = { 8, 8, ssize - 16, ssize - 16 };
edittypexy(SPACE, &b); edittypexy(SPACE, &b);

View file

@ -61,9 +61,10 @@ nhf(struct sqr *s)
void void
voptimize() // reset vdeltas on non-hf cubes voptimize() // reset vdeltas on non-hf cubes
{ {
loop(x, ssize) loop(y, ssize) for (int x = 0; x < ssize; x++) {
{ for (int y = 0; y < ssize; y++) {
struct sqr *s = S(x, y); struct sqr *s = S(x, y);
if (x && y) { if (x && y) {
if (nhf(s) && nhf(S(x - 1, y)) && if (nhf(s) && nhf(S(x - 1, y)) &&
nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1))) nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1)))
@ -72,6 +73,7 @@ voptimize() // reset vdeltas on non-hf cubes
s->vdelta = 0; s->vdelta = 0;
} }
} }
}
static void static void
topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut) topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut)
@ -84,16 +86,17 @@ topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut)
*wf = true; *wf = true;
*uf = true; *uf = true;
if (SOLID(s)) { if (SOLID(s)) {
loopi(4) if (!SOLID(o[i])) for (int i = 0; i < 4; i++) {
{ if (!SOLID(o[i])) {
*wf = false; *wf = false;
*wt = s->wtex; *wt = s->wtex;
*ut = s->utex; *ut = s->utex;
return; return;
} }
}
} else { } else {
loopi(4) if (!SOLID(o[i])) for (int i = 0; i < 4; i++) {
{ if (!SOLID(o[i])) {
if (o[i]->floor < s->floor) { if (o[i]->floor < s->floor) {
*wt = s->wtex; *wt = s->wtex;
*wf = false; *wf = false;
@ -105,6 +108,7 @@ topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut)
} }
} }
} }
}
void void
toptimize() // FIXME: only does 2x2, make atleast for 4x4 also toptimize() // FIXME: only does 2x2, make atleast for 4x4 also
@ -122,8 +126,7 @@ toptimize() // FIXME: only does 2x2, make atleast for 4x4 also
&ut); &ut);
topt(s[3] = SWS(s[0], 1, 0, ssize), &wf[3], &uf[3], &wt, topt(s[3] = SWS(s[0], 1, 0, ssize), &wf[3], &uf[3], &wt,
&ut); &ut);
loopi(4) for (int i = 0; i < 4; i++) {
{
if (wf[i]) if (wf[i])
s[i]->wtex = wt; s[i]->wtex = wt;
if (uf[i]) if (uf[i])
@ -210,8 +213,7 @@ save_world(OFString *mname)
sc = 0; \ sc = 0; \
} \ } \
} }
loopk(cubicsize) for (int k = 0; k < cubicsize; k++) {
{
struct sqr *s = &world[k]; struct sqr *s = &world[k];
#define c(f) (s->f == t->f) #define c(f) (s->f == t->f)
// 4 types of blocks, to compress a bit: // 4 types of blocks, to compress a bit:
@ -285,8 +287,7 @@ load_world(OFString *mname) // still supports all map formats that have existed
hdr.waterlevel = -100000; hdr.waterlevel = -100000;
} }
[ents removeAllObjects]; [ents removeAllObjects];
loopi(hdr.numents) for (int i = 0; i < hdr.numents; i++) {
{
struct persistent_entity tmp; struct persistent_entity tmp;
gzread(f, &tmp, sizeof(struct persistent_entity)); gzread(f, &tmp, sizeof(struct persistent_entity));
endianswap(&tmp, sizeof(short), 4); endianswap(&tmp, sizeof(short), 4);
@ -312,10 +313,10 @@ load_world(OFString *mname) // still supports all map formats that have existed
free(world); free(world);
setupworld(hdr.sfactor); setupworld(hdr.sfactor);
char texuse[256]; char texuse[256];
loopi(256) texuse[i] = 0; for (int i = 0; i < 256; i++)
texuse[i] = 0;
struct sqr *t = NULL; struct sqr *t = NULL;
loopk(cubicsize) for (int k = 0; k < cubicsize; k++) {
{
struct sqr *s = &world[k]; struct sqr *s = &world[k];
int type = gzgetc(f); int type = gzgetc(f);
switch (type) { switch (type) {
@ -382,13 +383,14 @@ load_world(OFString *mname) // still supports all map formats that have existed
calclight(); calclight();
settagareas(); settagareas();
int xs, ys; int xs, ys;
loopi(256) if (texuse[i]) lookuptexture(i, &xs, &ys); for (int i = 0; i < 256; i++)
if (texuse[i])
lookuptexture(i, &xs, &ys);
conoutf(@"read map %@ (%d milliseconds)", cgzname, conoutf(@"read map %@ (%d milliseconds)", cgzname,
SDL_GetTicks() - lastmillis); SDL_GetTicks() - lastmillis);
conoutf(@"%s", hdr.maptitle); conoutf(@"%s", hdr.maptitle);
startmap(mname); startmap(mname);
loopl(256) for (int l = 0; l < 256; l++) {
{
// can this be done smarter? // can this be done smarter?
OFString *aliasname = OFString *aliasname =
[OFString stringWithFormat:@"level_trigger_%d", l]; [OFString stringWithFormat:@"level_trigger_%d", l];

View file

@ -61,8 +61,7 @@ lightray(float bx, float by, Entity *light)
stepg /= lightscale; stepg /= lightscale;
b /= lightscale; b /= lightscale;
stepb /= lightscale; stepb /= lightscale;
loopi(steps) for (int i = 0; i < steps; i++) {
{
struct sqr *s = S(x >> PRECBITS, y >> PRECBITS); struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
int tl = (l >> PRECBITS) + s->r; int tl = (l >> PRECBITS) + s->r;
s->r = tl > 255 ? 255 : tl; s->r = tl > 255 ? 255 : tl;
@ -90,8 +89,7 @@ lightray(float bx, float by, Entity *light)
if (OUTBORD(x >> PRECBITS, y >> PRECBITS)) if (OUTBORD(x >> PRECBITS, y >> PRECBITS))
return; return;
loopi(steps) for (int i = 0; i < steps; i++) {
{
struct sqr *s = S(x >> PRECBITS, y >> PRECBITS); struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
int tl = (l >> PRECBITS) + s->r; int tl = (l >> PRECBITS) + s->r;
s->r = s->g = s->b = tl > 255 ? 255 : tl; s->r = s->g = s->b = tl > 255 ? 255 : tl;
@ -106,8 +104,7 @@ lightray(float bx, float by, Entity *light)
} else // the old (white) light code, here for the few people with old } else // the old (white) light code, here for the few people with old
// video cards that don't support overbright // video cards that don't support overbright
{ {
loopi(steps) for (int i = 0; i < steps; i++) {
{
struct sqr *s = S(x >> PRECBITS, y >> PRECBITS); struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
int light = l >> PRECBITS; int light = l >> PRECBITS;
if (light > s->r) if (light > s->r)
@ -150,8 +147,9 @@ calclightsource(Entity *l)
void void
postlightarea(const struct block *a) postlightarea(const struct block *a)
{ {
loop(x, a->xs) loop(y, a->ys) // assumes area not on edge of world // assumes area not on edge of world
{ for (int x = 0; x < a->xs; x++)
for (int y = 0; y < a->ys; y++) {
struct sqr *s = S(x + a->x, y + a->y); struct sqr *s = S(x + a->x, y + a->y);
#define median(m) \ #define median(m) \
s->m = \ s->m = \
@ -170,11 +168,12 @@ postlightarea(const struct block *a)
void void
calclight() calclight()
{ {
loop(x, ssize) loop(y, ssize) for (int x = 0; x < ssize; x++) {
{ for (int y = 0; y < ssize; y++) {
struct sqr *s = S(x, y); struct sqr *s = S(x, y);
s->r = s->g = s->b = 10; s->r = s->g = s->b = 10;
} }
}
for (Entity *e in ents) for (Entity *e in ents)
if (e.type == LIGHT) if (e.type == LIGHT)

View file

@ -33,8 +33,7 @@ computeraytable(float vx, float vy)
float byaw = (player1.yaw - 90 + af) / 360 * PI2; float byaw = (player1.yaw - 90 + af) / 360 * PI2;
float syaw = (player1.yaw - 90 - af) / 360 * PI2; float syaw = (player1.yaw - 90 - af) / 360 * PI2;
loopi(NUMRAYS) for (int i = 0; i < NUMRAYS; i++) {
{
float angle = i * PI2 / NUMRAYS; float angle = i * PI2 / NUMRAYS;
if ((apitch > 45 // must be bigger if fov>120 if ((apitch > 45 // must be bigger if fov>120
|| (angle < byaw && angle > syaw) || || (angle < byaw && angle > syaw) ||

View file

@ -318,7 +318,8 @@ void
render_world( render_world(
float vx, float vy, float vh, int yaw, int pitch, float fov, int w, int h) float vx, float vy, float vh, int yaw, int pitch, float fov, int w, int h)
{ {
loopi(LARGEST_FACTOR) stats[i] = 0; for (int i = 0; i < LARGEST_FACTOR; i++)
stats[i] = 0;
min_lod = MIN_LOD + abs(pitch) / 12; min_lod = MIN_LOD + abs(pitch) / 12;
yaw = 360 - yaw; yaw = 360 - yaw;
float widef = fov / 75.0f; float widef = fov / 75.0f;