From 006dba8370c7278be7875747fcef7e4cfc023889 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 23 Mar 2025 02:47:40 +0000 Subject: [PATCH] Remove loop[ijkl] They confused clang-format a lot. FossilOrigin-Name: 6b85eefc857c74c00d7ef693e312cc15df53201a6712aee8ba8d57c643c1703b --- src/MD2.m | 12 ++- src/clientgame.m | 7 +- src/clients.m | 7 +- src/commands.m | 9 +- src/console.m | 4 +- src/editing.m | 100 ++++++++++++++-------- src/menus.m | 6 +- src/physics.m | 12 +-- src/renderextras.m | 6 +- src/rendergl.m | 17 ++-- src/renderparticles.m | 9 +- src/savegamedemo.m | 19 +++-- src/server.m | 9 +- src/sound.m | 14 +-- src/tools.h | 12 +-- src/tools.m | 14 +-- src/weapon.m | 14 +-- src/world.m | 193 ++++++++++++++++++++++++------------------ src/worldio.m | 72 ++++++++-------- src/worldlight.m | 33 ++++---- src/worldocull.m | 3 +- src/worldrender.m | 3 +- 22 files changed, 318 insertions(+), 257 deletions(-) diff --git a/src/MD2.m b/src/MD2.m index cf4d70e..2924467 100644 --- a/src/MD2.m +++ b/src/MD2.m @@ -127,8 +127,7 @@ snap(int sn, float f) struct md2_frame *cf = (struct md2_frame *)((char *)_frames + _frameSize * frame); float sc = 16.0f / scale; - loop(vi, _numVerts) - { + for (int vi = 0; vi < _numVerts; vi++) { uchar *cv = (uchar *)&cf->vertices[vi].vertex; OFVector3D *v = &(_mverts[frame])[vi]; 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 basetime:(int)basetime { - loopi(range) if (!_mverts[frame + i])[self scaleWithFrame:frame + i - scale:sc - snap:sn]; + for (int i = 0; i < range; i++) + if (!_mverts[frame + i]) + [self scaleWithFrame:frame + i scale:sc snap:sn]; glPushMatrix(); glTranslatef(position.x, position.y, position.z); @@ -192,8 +191,7 @@ snap(int sn, float f) numVertex = -numVertex; } - loopi(numVertex) - { + for (int i = 0; i < numVertex; i++) { float tu = *((float *)command++); float tv = *((float *)command++); glTexCoord2f(tu, tv); diff --git a/src/clientgame.m b/src/clientgame.m index cbb4cca..e13c2af 100644 --- a/src/clientgame.m +++ b/src/clientgame.m @@ -198,8 +198,8 @@ updateworld(int millis) // main game update loop void 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 dy = (rnd(21) - 10) / 10.0f * i; OFVector3D old = d.origin; @@ -221,7 +221,8 @@ void spawnplayer(DynamicEntity *d) { 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) { d.origin = OFMakeVector3D( ents[spawncycle].x, ents[spawncycle].y, ents[spawncycle].z); diff --git a/src/clients.m b/src/clients.m index d52416c..6857e57 100644 --- a/src/clients.m +++ b/src/clients.m @@ -213,8 +213,7 @@ addmsg(int rel, int num, int type, ...) va_list marker; va_start(marker, type); - loopi(num - 1) - { + for (int i = 0; i < num - 1; i++) { int tmp = va_arg(marker, int); [msg addItem:&tmp]; } @@ -345,8 +344,8 @@ c2sinfo(DynamicEntity *d) // send messages collected during the previous frames if (*(int *)[msg itemAtIndex:1]) packet->flags = ENET_PACKET_FLAG_RELIABLE; - loopi(*(int *)[msg itemAtIndex:0]) - putint(&p, *(int *)[msg itemAtIndex:i + 2]); + for (int i = 0; i < *(int *)[msg itemAtIndex:0]; i++) + putint(&p, *(int *)[msg itemAtIndex:i + 2]); } [messages removeAllObjects]; if (lastmillis - lastping > 250) { diff --git a/src/commands.m b/src/commands.m index 34cd0ce..6ae5a7a 100644 --- a/src/commands.m +++ b/src/commands.m @@ -240,8 +240,7 @@ execute(OFString *string, bool isDown) for (bool cont = true; cont;) { // for each ; seperated statement int numargs = MAXWORDS; - loopi(MAXWORDS) - { + for (int i = 0; i < MAXWORDS; i++) { // collect all argument values w[i] = @""; if (i > numargs) @@ -421,8 +420,7 @@ loopa(OFString *times, OFString *body) { int t = times.cube_intValue; - loopi(t) - { + for (int i = 0; i < t; i++) { intset(@"i", i); execute(body, true); } @@ -477,8 +475,7 @@ at(OFString *s_, OFString *pos) char *copy __attribute__((__cleanup__(cleanup))) = strdup(s_.UTF8String); char *s = copy; - loopi(n) - { + for (int i = 0; i < n; i++) { s += strcspn(s, " \0"); s += strspn(s, " "); } diff --git a/src/console.m b/src/console.m index 209c283..376fa00 100644 --- a/src/console.m +++ b/src/console.m @@ -95,11 +95,9 @@ renderconsole() i++; } - loopj(nd) - { + for (int j = 0; j < nd; j++) draw_text(refs[j], FONTH / 3, (FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2); - } } // keymap is defined externally in keymap.cfg diff --git a/src/editing.m b/src/editing.m index bb5674a..d9799db 100644 --- a/src/editing.m +++ b/src/editing.m @@ -30,15 +30,16 @@ OF_CONSTRUCTOR() int selh = 0; bool selset = false; -#define loopselxy(b) \ - { \ - makeundo(); \ - loop(x, sel->xs) loop(y, sel->ys) \ - { \ - struct sqr *s = S(sel->x + x, sel->y + y); \ - b; \ - } \ - remip(sel, 0); \ +#define loopselxy(b) \ + { \ + makeundo(); \ + 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); \ + b; \ + } \ + } \ + remip(sel, 0); \ } int cx, cy, ch; @@ -291,8 +292,10 @@ void copy() { EDITSELMP; + if (copybuf) OFFreeMemory(copybuf); + copybuf = blockcopy(&sel); } @@ -321,8 +324,7 @@ void tofronttex() // maintain most recently used of the texture lists when applying // texture { - loopi(3) - { + for (int i = 0; i < 3; i++) { int c = curedittex[i]; if (c >= 0) { uchar *p = hdr.texlists[i]; @@ -371,6 +373,7 @@ void editheight(int flr, int amount) { EDITSEL; + bool isfloor = flr == 0; editheightxy(isfloor, amount, &sel); 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) { EDITSEL; + if (type < 0 || type > 3) return; + if (type != lasttype) { tofronttex(); lasttype = type; } + int atype = type == 3 ? 1 : type; int i = curedittex[atype]; i = i < 0 ? 0 : i + dir; @@ -419,28 +425,31 @@ void replace() { EDITSELMP; - loop(x, ssize) loop(y, ssize) - { - struct sqr *s = S(x, y); - switch (lasttype) { - case 0: - if (s->ftex == rtex.ftex) - s->ftex = lasttex; - break; - case 1: - if (s->wtex == rtex.wtex) - s->wtex = lasttex; - break; - case 2: - if (s->ctex == rtex.ctex) - s->ctex = lasttex; - break; - case 3: - if (s->utex == rtex.utex) - s->utex = lasttex; - break; + + for (int x = 0; x < ssize; x++) { + for (int y = 0; y < ssize; y++) { + struct sqr *s = S(x, y); + switch (lasttype) { + case 0: + if (s->ftex == rtex.ftex) + s->ftex = lasttex; + break; + case 1: + if (s->wtex == rtex.wtex) + s->wtex = lasttex; + break; + case 2: + if (s->ctex == rtex.ctex) + s->ctex = lasttex; + break; + case 3: + if (s->utex == rtex.utex) + s->utex = lasttex; + break; + } } } + struct block b = { 0, 0, ssize, ssize }; remip(&b, 0); } @@ -455,12 +464,14 @@ void edittype(int type) { EDITSEL; + if (type == CORNER && (sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 && sel.xs != 8) || sel.x & ~-sel.xs || sel.y & ~-sel.ys)) { conoutf(@"corner selection must be power of 2 aligned"); return; } + edittypexy(type, &sel); 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 equalize(int flr) { - bool isfloor = flr == 0; + bool isfloor = (flr == 0); + EDITSEL; + editequalisexy(isfloor, &sel); addmsg(1, 6, SV_EDITE, sel.x, sel.y, sel.xs, sel.ys, isfloor); } @@ -527,6 +540,7 @@ void setvdelta(int delta) { EDITSEL; + setvdeltaxy(delta, &sel); 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) { 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) return; @@ -551,12 +567,15 @@ void arch(int sidedelta, int _a) { EDITSELMP; + sel.xs++; sel.ys++; + if (sel.xs > MAXARCHVERT) sel.xs = MAXARCHVERT; if (sel.ys > MAXARCHVERT) sel.ys = MAXARCHVERT; + struct block *sel_ = &sel; // Ugly hack to make the macro work. struct block *sel = sel_; @@ -572,13 +591,16 @@ void slope(int xd, int yd) { EDITSELMP; + int off = 0; if (xd < 0) off -= xd * sel.xs; if (yd < 0) off -= yd * sel.ys; + sel.xs++; sel.ys++; + struct block *sel_ = &sel; // Ugly hack to make the macro work. struct block *sel = sel_; @@ -590,15 +612,22 @@ void perlin(int scale, int seed, int psize) { EDITSELMP; + sel.xs++; sel.ys++; + makeundo(); + sel.xs--; sel.ys--; + perlinarea(&sel, scale, seed, psize); + sel.xs++; sel.ys++; + remipmore(&sel, 0); + sel.xs--; sel.ys--; } @@ -607,13 +636,15 @@ VARF( fullbright, 0, 0, 1, if (fullbright) { if (noteditmode()) 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 edittag(int tag) { EDITSELMP; + struct block *sel_ = &sel; // Ugly hack to make the macro work. struct block *sel = sel_; @@ -624,6 +655,7 @@ void newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4) { EDITSEL; + newentity(sel.x, sel.y, (int)player1.origin.z, what, [a1 cube_intValueWithBase:0], [a2 cube_intValueWithBase:0], [a3 cube_intValueWithBase:0], [a4 cube_intValueWithBase:0]); diff --git a/src/menus.m b/src/menus.m index 7954e65..472800d 100644 --- a/src/menus.m +++ b/src/menus.m @@ -61,8 +61,7 @@ rendermenu() title = m.name; int mdisp = m.items.count; int w = 0; - loopi(mdisp) - { + for (int i = 0; i < mdisp; i++) { int x = text_width(m.items[i].text); if (x > w) w = x; @@ -83,8 +82,7 @@ rendermenu() blendbox( 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); y += step; } diff --git a/src/physics.m b/src/physics.m index 8b7eff1..538ba10 100644 --- a/src/physics.m +++ b/src/physics.m @@ -358,8 +358,8 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime) // extra smoothness when lifting up stairs 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 pl.origin = OFAddVector3D(pl.origin, OFMakeVector3D(f * d.x, f * d.y, f * d.z)); @@ -441,7 +441,9 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime) void moveplayer(DynamicEntity *pl, int moveres, bool local) { - loopi(physicsrepeat) moveplayer4(pl, moveres, local, - i ? curtime / physicsrepeat - : curtime - curtime / physicsrepeat * (physicsrepeat - 1)); + for (int i = 0; i < physicsrepeat; i++) + moveplayer4(pl, moveres, local, + i ? curtime / physicsrepeat + : curtime - + curtime / physicsrepeat * (physicsrepeat - 1)); } diff --git a/src/renderextras.m b/src/renderextras.m index ecaaa32..ca0a5cc 100644 --- a/src/renderextras.m +++ b/src/renderextras.m @@ -95,8 +95,7 @@ void newsphere(const OFVector3D *o, float max, int type) { if (!sinit) { - loopi(MAXSPHERES) - { + for (int i = 0; i < MAXSPHERES; i++) { spheres[i].next = sempty; sempty = &spheres[i]; } @@ -218,8 +217,7 @@ loadsky(OFString *basename) static const OFString *side[] = { @"ft", @"bk", @"lf", @"rt", @"dn", @"up" }; int texnum = 14; - loopi(6) - { + for (int i = 0; i < 6; i++) { OFString *path = [OFString stringWithFormat:@"packages/%@_%@.jpg", basename, side[i]]; diff --git a/src/rendergl.m b/src/rendergl.m index 68cb14d..f131964 100644 --- a/src/rendergl.m +++ b/src/rendergl.m @@ -112,11 +112,10 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp) } #if 0 - loopi(s->w * s->h * 3) - { - uchar *p = (uchar *)s->pixels + i; - *p = 255 - *p; - } + for (int i = 0; i < s->w * s->h * 3; i++) { + uchar *p = (uchar *)s->pixels + i; + *p = 255 - *p; + } #endif glBindTexture(GL_TEXTURE_2D, tnum); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -179,7 +178,9 @@ static OFString *mapname[256][MAXFRAMES]; void 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; @@ -221,8 +222,8 @@ lookuptexture(int tex, int *xs, int *ys) if (tid == 0) 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]]) { mapping[tex][frame] = tid = i + FIRSTTEX; *xs = texx[i]; diff --git a/src/renderparticles.m b/src/renderparticles.m index 77a7b5f..3af1c62 100644 --- a/src/renderparticles.m +++ b/src/renderparticles.m @@ -21,8 +21,7 @@ static void newparticle(const OFVector3D *o, const OFVector3D *d, int fade, int type) { if (!parinit) { - loopi(MAXPARTICLES) - { + for (int i = 0; i < MAXPARTICLES; i++) { particles[i].next = parempty; parempty = &particles[i]; } @@ -138,8 +137,7 @@ render_particles(int time) void 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; int x, y, z; do { @@ -158,8 +156,7 @@ particle_trail(int type, int fade, const OFVector3D *s, const OFVector3D *e) vdist(d, v, *s, *e); vdiv(v, d * 2 + 0.1f); OFVector3D p = *s; - loopi((int)d * 2) - { + for (int i = 0; i < ((int)d * 2); i++) { vadd(p, v); OFVector3D d = OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5); diff --git a/src/savegamedemo.m b/src/savegamedemo.m index d69037d..4d759e7 100644 --- a/src/savegamedemo.m +++ b/src/savegamedemo.m @@ -245,12 +245,13 @@ loadgamerest() [Monster restoreAll]; int nplayers = gzgeti(); - loopi(nplayers) if (!gzget()) - { - DynamicEntity *d = getclient(i); - assert(d); - gzread(f, data.mutableItems, data.count); - [d setFromSerializedData:data]; + for (int i = 0; i < nplayers; i++) { + if (!gzget()) { + DynamicEntity *d = getclient(i); + assert(d); + gzread(f, data.mutableItems, data.count); + [d setFromSerializedData:data]; + } } conoutf(@"savegame restored"); @@ -321,7 +322,8 @@ incomingdemodata(uchar *buf, int len, bool extras) gzputi(player1.health); gzputi(player1.armour); gzput(player1.armourType); - loopi(NUMGUNS) gzput(player1.ammo[i]); + for (int i = 0; i < NUMGUNS; i++) + gzput(player1.ammo[i]); gzput(player1.state); gzputi(bdamage); bdamage = 0; @@ -448,7 +450,8 @@ demoplaybackstep() target.health = gzgeti(); target.armour = gzgeti(); target.armourType = gzget(); - loopi(NUMGUNS) target.ammo[i] = gzget(); + for (int i = 0; i < NUMGUNS; i++) + target.ammo[i] = gzget(); target.state = gzget(); target.lastMove = playbacktime; if ((bdamage = gzgeti())) diff --git a/src/server.m b/src/server.m index e316576..99a1321 100644 --- a/src/server.m +++ b/src/server.m @@ -253,7 +253,8 @@ process(ENetPacket *packet, int sender) // sender may be -1 } int size = msgsizelookup(type); assert(size != -1); - loopi(size - 2) getint(&p); + for (int i = 0; i < size - 2; i++) + getint(&p); break; } @@ -280,7 +281,8 @@ process(ENetPacket *packet, int sender) // sender may be -1 disconnect_client(sender, @"tag type"); 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); if (!serverhost) 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(); diff --git a/src/sound.m b/src/sound.m index a3a07a2..5164eb5 100644 --- a/src/sound.m +++ b/src/sound.m @@ -146,12 +146,14 @@ updatevol() { if (nosound) return; - loopi(MAXCHAN) if (soundlocs[i].inuse) - { - if (Mix_Playing(i)) - updatechanvol(i, &soundlocs[i].loc); - else - soundlocs[i].inuse = false; + + for (int i = 0; i < MAXCHAN; i++) { + if (soundlocs[i].inuse) { + if (Mix_Playing(i)) + updatechanvol(i, &soundlocs[i].loc); + else + soundlocs[i].inuse = false; + } } } diff --git a/src/tools.h b/src/tools.h index 51efe54..d4a3026 100644 --- a/src/tools.h +++ b/src/tools.h @@ -30,15 +30,11 @@ typedef unsigned int uint; #define min(a, b) (((a) < (b)) ? (a) : (b)) #define rnd(max) (rand() % (max)) #define rndreset() (srand(1)) -#define rndtime() \ - { \ - loopi(lastmillis & 0xF) rnd(i + 1); \ +#define rndtime() \ + { \ + 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 # define __cdecl diff --git a/src/tools.m b/src/tools.m index ca402d6..73d40a8 100644 --- a/src/tools.m +++ b/src/tools.m @@ -10,11 +10,13 @@ endianswap( { if (*((char *)&stride)) return; - loop(w, length) loop(i, stride / 2) - { - uchar *p = (uchar *)memory + w * stride; - uchar t = p[i]; - p[i] = p[stride - i - 1]; - p[stride - i - 1] = t; + + for (int w = 0; w < length; w++) { + for (int i = 0; i < stride / 2; i++) { + uchar *p = (uchar *)memory + w * stride; + uchar t = p[i]; + p[i] = p[stride - i - 1]; + p[stride - i - 1] = t; + } } } diff --git a/src/weapon.m b/src/weapon.m index bd570ce..9c8e085 100644 --- a/src/weapon.m +++ b/src/weapon.m @@ -77,8 +77,7 @@ createrays(const OFVector3D *from, const OFVector3D *to) { vdist(dist, dvec, *from, *to); float f = dist * SGSPREAD / 1000; - loopi(SGRAYS) - { + for (int i = 0; i < SGRAYS; i++) { #define RNDD (rnd(101) - 50) * f OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD); 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) { OFVector3D o = d.origin; @@ -205,7 +204,7 @@ radialeffect( } } -void +static void splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold, int notthisplayer, int notthismonster, int qdam) { @@ -322,7 +321,8 @@ shootv(int gun, const OFVector3D *from, const OFVector3D *to, DynamicEntity *d, break; 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; } @@ -371,7 +371,9 @@ raydamage(DynamicEntity *o, const OFVector3D *from, const OFVector3D *to, qdam /= MONSTERDAMAGEFACTOR; if (d.gunSelect == GUN_SG) { 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) hitpush(i, damage, o, d, from, to); } else if (intersect(o, from, to)) diff --git a/src/world.m b/src/world.m index 568dfc4..a352888 100644 --- a/src/world.m +++ b/src/world.m @@ -19,38 +19,47 @@ void settag(int tag, int type) { int maxx = 0, maxy = 0, minx = ssize, miny = ssize; - loop(x, ssize) loop(y, ssize) - { - struct sqr *s = S(x, y); - if (s->tag) { - if (tag) { - if (tag == s->tag) - s->type = SPACE; - else - continue; - } else { - s->type = type ? SOLID : SPACE; + for (int x = 0; x < ssize; x++) { + for (int y = 0; y < ssize; y++) { + struct sqr *s = S(x, y); + + if (s->tag) { + if (tag) { + if (tag == s->tag) + s->type = SPACE; + else + continue; + } else + s->type = type ? SOLID : SPACE; + + if (x > maxx) + maxx = x; + if (y > maxy) + maxy = y; + if (x < minx) + minx = x; + if (y < miny) + miny = y; } - if (x > maxx) - maxx = x; - if (y > maxy) - maxy = y; - if (x < minx) - minx = x; - if (y < miny) - 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 resettagareas() { settag(0, 0); -} // reset for editing or map saving +} + +// set for playing void settagareas() { @@ -60,7 +69,7 @@ settagareas() if (ents[i].type == CARROT) setspawn(i, true); }]; -} // set for playing +} void trigger(int tag, int type, bool savegame) @@ -123,42 +132,56 @@ remip(const struct block *b, int level) struct sqr *r = SWS(v, x / 2, y / 2, vs); *r = *o[0]; uchar nums[MAXTYPE]; - loopi(MAXTYPE) nums[i] = 0; - loopj(4) nums[o[j]->type]++; + for (int i = 0; i < MAXTYPE; i++) + nums[i] = 0; + for (int j = 0; j < 4; j++) + nums[o[j]->type]++; // cube contains both solid and space, treated // specially in the renderer 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)) { int floor = 127, ceil = -128; - loopi(4) if (!SOLID(o[i])) - { - int fh = o[i]->floor; - int ch = o[i]->ceil; - if (r->type == SEMISOLID) { - if (o[i]->type == FHF) - // crap hack, needed - // for rendering large - // mips next to hfs - fh -= o[i]->vdelta / 4 + - 2; - if (o[i]->type == CHF) - // FIXME: needs to - // somehow take into - // account middle - // vertices on higher - // mips - ch += o[i]->vdelta / 4 + - 2; + for (int i = 0; i < 4; i++) { + if (!SOLID(o[i])) { + int fh = o[i]->floor; + int ch = o[i]->ceil; + if (r->type == SEMISOLID) { + if (o[i]->type == FHF) + // crap hack, + // needed for + // rendering + // large mips + // next to hfs + fh -= + o[i]->vdelta / + 4 + + 2; + if (o[i]->type == CHF) + // FIXME: needs + // to somehow + // take into + // account + // middle + // vertices on + // higher mips + ch += + o[i]->vdelta / + 4 + + 2; + } + if (fh < floor) + // take lowest floor and + // highest ceil, so we + // never have to see + // missing lower/upper + // from the side + floor = fh; + if (ch > ceil) + ceil = ch; } - if (fh < floor) - // take lowest floor and - // highest ceil, so we never - // have to see missing - // lower/upper from the side - floor = fh; - if (ch > ceil) - ceil = ch; } r->floor = floor; r->ceil = ceil; @@ -169,8 +192,7 @@ remip(const struct block *b, int level) goto mip; r->defer = 1; if (SOLID(r)) { - loopi(3) - { + for (int i = 0; i < 3; i++) { if (o[i]->wtex != o[3]->wtex) // on an all solid cube, only // thing that needs to be equal @@ -179,8 +201,7 @@ remip(const struct block *b, int level) goto c; } } else { - loopi(3) - { + for (int i = 0; i < 3; i++) { // perfect mip even if light is not // exactly equal 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, // 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: r->defer = 0; @@ -322,7 +345,9 @@ delent() int 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); return NOTUSED; } @@ -428,7 +453,9 @@ findentity(int type, int index) for (int i = index; i < ents.count; i++) if (ents[i].type == type) 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; } @@ -442,8 +469,7 @@ setupworld(int factor) mipsize = cubicsize * 134 / 100; struct sqr *w = world = OFAllocZeroedMemory(mipsize, sizeof(struct sqr)); - loopi(LARGEST_FACTOR * 2) - { + for (int i = 0; i < LARGEST_FACTOR * 2; i++) { wmip[i] = w; w += cubicsize >> (i * 2); } @@ -470,18 +496,19 @@ empty_world(int factor, bool force) factor = LARGEST_FACTOR; setupworld(factor); - loop(x, ssize) loop(y, ssize) - { - struct sqr *s = S(x, y); - s->r = s->g = s->b = 150; - s->ftex = DEFAULT_FLOOR; - s->ctex = DEFAULT_CEIL; - s->wtex = s->utex = DEFAULT_WALL; - s->type = SOLID; - s->floor = 0; - s->ceil = 16; - s->vdelta = 0; - s->defer = 0; + for (int x = 0; x < ssize; x++) { + for (int y = 0; y < ssize; y++) { + struct sqr *s = S(x, y); + s->r = s->g = s->b = 150; + s->ftex = DEFAULT_FLOOR; + s->ctex = DEFAULT_CEIL; + s->wtex = s->utex = DEFAULT_WALL; + s->type = SOLID; + s->floor = 0; + s->ceil = 16; + s->vdelta = 0; + s->defer = 0; + } } strncpy(hdr.head, "CUBE", 4); @@ -490,10 +517,11 @@ empty_world(int factor, bool force) hdr.sfactor = sfactor; if (copy) { - loop(x, ssize / 2) loop(y, ssize / 2) - { - *S(x + ssize / 4, y + ssize / 4) = - *SWS(oldworld, x, 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) = + *SWS(oldworld, x, y, ssize / 2); + } } for (Entity *e in ents) { @@ -504,8 +532,11 @@ empty_world(int factor, bool force) char buffer[128] = "Untitled Map by Unknown"; memcpy(hdr.maptitle, buffer, 128); hdr.waterlevel = -100000; - loopi(15) hdr.reserved[i] = 0; - loopk(3) loopi(256) hdr.texlists[k][i] = i; + for (int i = 0; i < 15; 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]; struct block b = { 8, 8, ssize - 16, ssize - 16 }; edittypexy(SPACE, &b); diff --git a/src/worldio.m b/src/worldio.m index 99fe90d..459b154 100644 --- a/src/worldio.m +++ b/src/worldio.m @@ -61,15 +61,17 @@ nhf(struct sqr *s) void voptimize() // reset vdeltas on non-hf cubes { - loop(x, ssize) loop(y, ssize) - { - struct sqr *s = S(x, y); - if (x && y) { - if (nhf(s) && nhf(S(x - 1, y)) && - nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1))) + for (int x = 0; x < ssize; x++) { + for (int y = 0; y < ssize; y++) { + struct sqr *s = S(x, y); + + if (x && y) { + if (nhf(s) && nhf(S(x - 1, y)) && + nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1))) + s->vdelta = 0; + } else s->vdelta = 0; - } else - s->vdelta = 0; + } } } @@ -84,23 +86,25 @@ topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut) *wf = true; *uf = true; if (SOLID(s)) { - loopi(4) if (!SOLID(o[i])) - { - *wf = false; - *wt = s->wtex; - *ut = s->utex; - return; + for (int i = 0; i < 4; i++) { + if (!SOLID(o[i])) { + *wf = false; + *wt = s->wtex; + *ut = s->utex; + return; + } } } else { - loopi(4) if (!SOLID(o[i])) - { - if (o[i]->floor < s->floor) { - *wt = s->wtex; - *wf = false; - } - if (o[i]->ceil > s->ceil) { - *ut = s->utex; - *uf = false; + for (int i = 0; i < 4; i++) { + if (!SOLID(o[i])) { + if (o[i]->floor < s->floor) { + *wt = s->wtex; + *wf = false; + } + if (o[i]->ceil > s->ceil) { + *ut = s->utex; + *uf = false; + } } } } @@ -122,8 +126,7 @@ toptimize() // FIXME: only does 2x2, make atleast for 4x4 also &ut); topt(s[3] = SWS(s[0], 1, 0, ssize), &wf[3], &uf[3], &wt, &ut); - loopi(4) - { + for (int i = 0; i < 4; i++) { if (wf[i]) s[i]->wtex = wt; if (uf[i]) @@ -210,8 +213,7 @@ save_world(OFString *mname) sc = 0; \ } \ } - loopk(cubicsize) - { + for (int k = 0; k < cubicsize; k++) { struct sqr *s = &world[k]; #define c(f) (s->f == t->f) // 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; } [ents removeAllObjects]; - loopi(hdr.numents) - { + for (int i = 0; i < hdr.numents; i++) { struct persistent_entity tmp; gzread(f, &tmp, sizeof(struct persistent_entity)); endianswap(&tmp, sizeof(short), 4); @@ -312,10 +313,10 @@ load_world(OFString *mname) // still supports all map formats that have existed free(world); setupworld(hdr.sfactor); char texuse[256]; - loopi(256) texuse[i] = 0; + for (int i = 0; i < 256; i++) + texuse[i] = 0; struct sqr *t = NULL; - loopk(cubicsize) - { + for (int k = 0; k < cubicsize; k++) { struct sqr *s = &world[k]; int type = gzgetc(f); switch (type) { @@ -382,13 +383,14 @@ load_world(OFString *mname) // still supports all map formats that have existed calclight(); settagareas(); 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, SDL_GetTicks() - lastmillis); conoutf(@"%s", hdr.maptitle); startmap(mname); - loopl(256) - { + for (int l = 0; l < 256; l++) { // can this be done smarter? OFString *aliasname = [OFString stringWithFormat:@"level_trigger_%d", l]; diff --git a/src/worldlight.m b/src/worldlight.m index 521e7b9..fd30abc 100644 --- a/src/worldlight.m +++ b/src/worldlight.m @@ -61,8 +61,7 @@ lightray(float bx, float by, Entity *light) stepg /= lightscale; b /= lightscale; stepb /= lightscale; - loopi(steps) - { + for (int i = 0; i < steps; i++) { struct sqr *s = S(x >> PRECBITS, y >> PRECBITS); int tl = (l >> PRECBITS) + s->r; s->r = tl > 255 ? 255 : tl; @@ -90,8 +89,7 @@ lightray(float bx, float by, Entity *light) if (OUTBORD(x >> PRECBITS, y >> PRECBITS)) return; - loopi(steps) - { + for (int i = 0; i < steps; i++) { struct sqr *s = S(x >> PRECBITS, y >> PRECBITS); int tl = (l >> PRECBITS) + s->r; 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 // video cards that don't support overbright { - loopi(steps) - { + for (int i = 0; i < steps; i++) { struct sqr *s = S(x >> PRECBITS, y >> PRECBITS); int light = l >> PRECBITS; if (light > s->r) @@ -150,19 +147,20 @@ calclightsource(Entity *l) void postlightarea(const struct block *a) { - loop(x, a->xs) loop(y, a->ys) // assumes area not on edge of world - { - struct sqr *s = S(x + a->x, y + a->y); + // 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); #define median(m) \ s->m = \ (s->m * 2 + SW(s, 1, 0)->m * 2 + SW(s, 0, 1)->m * 2 + \ SW(s, -1, 0)->m * 2 + SW(s, 0, -1)->m * 2 + SW(s, 1, 1)->m + \ SW(s, 1, -1)->m + SW(s, -1, 1)->m + SW(s, -1, -1)->m) / \ 14; // median is 4/2/1 instead - median(r); - median(g); - median(b); - } + median(r); + median(g); + median(b); + } remip(a, 0); } @@ -170,10 +168,11 @@ postlightarea(const struct block *a) void calclight() { - loop(x, ssize) loop(y, ssize) - { - struct sqr *s = S(x, y); - s->r = s->g = s->b = 10; + for (int x = 0; x < ssize; x++) { + for (int y = 0; y < ssize; y++) { + struct sqr *s = S(x, y); + s->r = s->g = s->b = 10; + } } for (Entity *e in ents) diff --git a/src/worldocull.m b/src/worldocull.m index bde4386..060587c 100644 --- a/src/worldocull.m +++ b/src/worldocull.m @@ -33,8 +33,7 @@ computeraytable(float vx, float vy) float byaw = (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; if ((apitch > 45 // must be bigger if fov>120 || (angle < byaw && angle > syaw) || diff --git a/src/worldrender.m b/src/worldrender.m index 0618d13..3dd2089 100644 --- a/src/worldrender.m +++ b/src/worldrender.m @@ -318,7 +318,8 @@ void render_world( 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; yaw = 360 - yaw; float widef = fov / 75.0f;