Index: src/MD2.m ================================================================== --- src/MD2.m +++ src/MD2.m @@ -125,12 +125,11 @@ _mverts[frame] = OFAllocMemory(_numVerts, sizeof(OFVector3D)); 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; v->y = -(snap(sn, cv[1] * cf->scale[1]) + cf->translate[1]) / sc; @@ -147,13 +146,13 @@ scale:(float)sc speed:(float)speed 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); glRotatef(yaw + 180, 0, -1, 0); glRotatef(pitch, 0, 0, 1); @@ -190,12 +189,11 @@ } else { glBegin(GL_TRIANGLE_FAN); numVertex = -numVertex; } - loopi(numVertex) - { + for (int i = 0; i < numVertex; i++) { float tu = *((float *)command++); float tv = *((float *)command++); glTexCoord2f(tu, tv); int vn = *command++; #define ip(c) verts1[vn].c *frac2 + verts2[vn].c *frac1 Index: src/clientgame.m ================================================================== --- src/clientgame.m +++ src/clientgame.m @@ -196,12 +196,12 @@ // brute force but effective way to find a free spawn spot in the map 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; d.origin = OFAddVector3D(d.origin, OFMakeVector3D(dx, dy, 0)); if (collide(d, true, 0, 0)) @@ -219,11 +219,12 @@ // place at random spawn. also used by monsters! 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); d.yaw = ents[spawncycle].attr1; d.pitch = 0; Index: src/clients.m ================================================================== --- src/clients.m +++ src/clients.m @@ -211,12 +211,11 @@ [msg addItem:&rel]; [msg addItem:&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]; } va_end(marker); [msg makeImmutable]; @@ -343,12 +342,12 @@ } for (OFData *msg in messages) { // 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) { putint(&p, SV_PING); putint(&p, lastmillis); Index: src/commands.m ================================================================== --- src/commands.m +++ src/commands.m @@ -238,12 +238,11 @@ OFString *w[MAXWORDS]; int val = 0; 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) continue; // parse and evaluate exps @@ -419,12 +418,11 @@ void 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); } } @@ -475,12 +473,11 @@ { int n = pos.cube_intValue; 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, " "); } s[strcspn(s, " \0")] = 0; concat(@(s)); Index: src/console.m ================================================================== --- src/console.m +++ src/console.m @@ -93,15 +93,13 @@ } 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 static OFMutableArray *keyMappings = nil; Index: src/editing.m ================================================================== --- src/editing.m +++ src/editing.m @@ -28,19 +28,20 @@ } 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; int curedittex[] = { -1, -1, -1 }; @@ -289,12 +290,14 @@ void copy() { EDITSELMP; + if (copybuf) OFFreeMemory(copybuf); + copybuf = blockcopy(&sel); } void paste() @@ -319,12 +322,11 @@ 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]; int t = p[c]; for (int a = c - 1; a >= 0; a--) @@ -369,10 +371,11 @@ 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); } COMMAND(editheight, ARG_2INT) @@ -398,16 +401,19 @@ 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; curedittex[atype] = i = min(max(i, 0), 255); int t = lasttex = hdr.texlists[atype][i]; @@ -417,32 +423,35 @@ 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); } void @@ -453,16 +462,18 @@ 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); } void @@ -507,12 +518,14 @@ } 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); } COMMAND(equalize, ARG_1INT) @@ -525,10 +538,11 @@ void setvdelta(int delta) { EDITSEL; + setvdeltaxy(delta, &sel); addmsg(1, 6, SV_EDITD, sel.x, sel.y, sel.xs, sel.ys, delta); } #define MAXARCHVERT 50 @@ -538,11 +552,13 @@ void 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; archverts[span][vert] = delta; } @@ -549,16 +565,19 @@ 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_; loopselxy(s->vdelta = sel->xs > sel->ys ? (archverts[sel->xs - 1][x] + @@ -570,17 +589,20 @@ 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_; loopselxy(s->vdelta = xd * x + yd * y + off); remipmore(sel, 0); @@ -588,34 +610,43 @@ 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--; } 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_; loopselxy(s->tag = tag); } @@ -622,10 +653,11 @@ 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]); } Index: src/menus.m ================================================================== --- src/menus.m +++ src/menus.m @@ -59,12 +59,11 @@ title = [OFString stringWithFormat:@"[ %@ menu ]", m.name]; else 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; } int tw = text_width(title); @@ -81,12 +80,11 @@ if (vmenu) { int bh = y + m.menusel * step; 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; } return true; } Index: src/physics.m ================================================================== --- src/physics.m +++ src/physics.m @@ -356,12 +356,12 @@ // at high fps, gravity kicks in too fast const float drop = dropf * curtime / gravity / 100 / moveres; // 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)); if (collide(pl, false, drop, rise)) continue; @@ -439,9 +439,11 @@ } 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)); } Index: src/renderextras.m ================================================================== --- src/renderextras.m +++ src/renderextras.m @@ -93,12 +93,11 @@ 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]; } sinit = true; } @@ -216,12 +215,11 @@ return; 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]]; int xs, ys; if (!installtex(texnum + i, Index: src/rendergl.m ================================================================== --- src/rendergl.m +++ src/rendergl.m @@ -110,15 +110,14 @@ SDL_FreeFormat(format); } } #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); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT); @@ -177,11 +176,13 @@ 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; void @@ -219,12 +220,12 @@ *xs = *ys = 16; 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]; *ys = texy[i]; return tid; Index: src/renderparticles.m ================================================================== --- src/renderparticles.m +++ src/renderparticles.m @@ -19,12 +19,11 @@ 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]; } parinit = true; } @@ -136,12 +135,11 @@ } 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 { x = rnd(radius * 2) - radius; y = rnd(radius * 2) - radius; @@ -156,13 +154,12 @@ 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); newparticle(&p, &d, rnd(fade) + fade, type); } } Index: src/savegamedemo.m ================================================================== --- src/savegamedemo.m +++ src/savegamedemo.m @@ -243,16 +243,17 @@ monster.lastAction = 0; } [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"); if (demoloading) startdemo(); @@ -319,11 +320,12 @@ gzputi(player1.lastAction - starttime); gzputi(player1.gunWait); 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; gzputi(ddamage); if (ddamage) { @@ -446,11 +448,12 @@ target.lastAction = scaletime(gzgeti()); target.gunWait = gzgeti(); 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())) damageblend(bdamage); if ((ddamage = gzgeti())) { Index: src/server.m ================================================================== --- src/server.m +++ src/server.m @@ -251,11 +251,12 @@ disconnect_client(sender, @"client num"); return; } int size = msgsizelookup(type); assert(size != -1); - loopi(size - 2) getint(&p); + for (int i = 0; i < size - 2; i++) + getint(&p); break; } case SV_SENDMAP: { sgetstr(); @@ -278,11 +279,12 @@ int size = msgsizelookup(type); if (size == -1) { disconnect_client(sender, @"tag type"); return; } - loopi(size - 1) getint(&p); + for (int i = 0; i < size - 1; i++) + getint(&p); } } } if (p > end) { @@ -544,11 +546,12 @@ enet_address_set_host(&address, ip.UTF8String) < 0) printf("WARNING: server ip not resolved"); 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(); // do not return, this becomes main loop Index: src/sound.m ================================================================== --- src/sound.m +++ src/sound.m @@ -144,16 +144,18 @@ void 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; + } } } void playsoundc(int n) Index: src/tools.h ================================================================== --- src/tools.h +++ src/tools.h @@ -28,19 +28,15 @@ #define max(a, b) (((a) > (b)) ? (a) : (b)) #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 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) +#define rndtime() \ + { \ + for (int i = 0; i < (lastmillis & 0xF); i++) \ + rnd(i + 1); \ + } #ifndef OF_WINDOWS # define __cdecl #endif Index: src/tools.m ================================================================== --- src/tools.m +++ src/tools.m @@ -8,13 +8,15 @@ endianswap( void *memory, int stride, int length) // little indians as storage format { 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; + } } } Index: src/weapon.m ================================================================== --- src/weapon.m +++ src/weapon.m @@ -75,12 +75,11 @@ void 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; vadd(sg[i], r); } @@ -166,11 +165,11 @@ p.gun = gun; return; } } -void +static void hit(int target, int damage, __kindof DynamicEntity *d, DynamicEntity *at) { OFVector3D o = d.origin; if (d == player1) selfdamage(damage, at == player1 ? -1 : -2, at); @@ -203,11 +202,11 @@ vmul(temp, (RL_DAMRAD - dist) * damage / 800); vadd(o.velocity, temp); } } -void +static void splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold, int notthisplayer, int notthismonster, int qdam) { particle_splash(0, 50, 300, v); p.inuse = false; @@ -320,11 +319,12 @@ switch (gun) { case GUN_FIST: 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; } case GUN_CG: particle_splash(0, 100, 250, to); @@ -369,11 +369,13 @@ qdam *= 4; if ([d isKindOfClass:Monster.class]) 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)) hitpush(i, qdam, o, d, from, to); } Index: src/world.m ================================================================== --- src/world.m +++ src/world.m @@ -17,52 +17,61 @@ // according to type 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; - } - 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 -} - + 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 (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() { settag(0, 1); [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { if (ents[i].type == CARROT) setspawn(i, true); }]; -} // set for playing +} void trigger(int tag, int type, bool savegame) { if (!tag) @@ -121,46 +130,60 @@ o[3] = SWS(w, x, y + 1, ws); // the target cube in the higher mip 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; - } - 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; + 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; + } } r->floor = floor; r->ceil = ceil; } if (r->type == CORNER) @@ -167,22 +190,20 @@ // special case: don't ever split even if // textures etc are different 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 // for a perfect mip is the // wall texture 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 || o[i]->floor != o[3]->floor || o[i]->ceil != o[3]->ceil || @@ -226,11 +247,13 @@ } } { // 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; c:; } @@ -320,11 +343,13 @@ } 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; } Entity * @@ -426,11 +451,13 @@ 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; } struct sqr *wmip[LARGEST_FACTOR * 2]; @@ -440,12 +467,11 @@ ssize = 1 << (sfactor = factor); cubicsize = ssize * ssize; 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); } } @@ -468,34 +494,36 @@ factor = SMALLEST_FACTOR; if (factor > LARGEST_FACTOR) 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); hdr.version = MAPVERSION; hdr.headersize = sizeof(struct header); 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) { e.x += ssize / 4; e.y += ssize / 4; @@ -502,12 +530,15 @@ } } else { 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); } Index: src/worldio.m ================================================================== --- src/worldio.m +++ src/worldio.m @@ -59,19 +59,21 @@ } 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))) - s->vdelta = 0; - } else - s->vdelta = 0; + 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; + } } } static void topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut) @@ -82,27 +84,29 @@ o[2] = SWS(s, 1, 0, ssize); o[3] = SWS(s, -1, 0, ssize); *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; + } } } } } @@ -120,12 +124,11 @@ &ut); topt(s[2] = SWS(s[0], 1, 1, ssize), &wf[2], &uf[2], &wt, &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]) s[i]->utex = ut; } @@ -208,12 +211,11 @@ } else { \ gzputc(f, sc); \ 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: // 255 (2): same as previous block + count // 254 (3): same as previous, except light // deprecated @@ -283,12 +285,11 @@ endianswap(&hdr.waterlevel, sizeof(int), 16); } else { 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); Entity *e = [Entity entity]; @@ -310,14 +311,14 @@ } } 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) { case 255: { int n = gzgetc(f); @@ -380,17 +381,18 @@ } gzclose(f); 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]; if (identexists(aliasname)) alias(aliasname, @""); Index: src/worldlight.m ================================================================== --- src/worldlight.m +++ src/worldlight.m @@ -59,12 +59,11 @@ int stepb = fast_f2nat(b / (float)steps); g /= lightscale; 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; tl = (g >> PRECBITS) + s->g; s->g = tl > 255 ? 255 : tl; @@ -88,12 +87,11 @@ y += stepy * dimness; 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; if (SOLID(s)) return; @@ -104,12 +102,11 @@ } } } 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) s->r = s->g = s->b = (uchar)light; if (SOLID(s)) @@ -148,34 +145,36 @@ // median filter, smooths out random noise in light and makes it more mipable 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); } 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) if (e.type == LIGHT) calclightsource(e); Index: src/worldocull.m ================================================================== --- src/worldocull.m +++ src/worldocull.m @@ -31,12 +31,11 @@ float apitch = (float)fabs(player1.pitch); float af = getvar(@"fov") / 2 + apitch / 1.5f + 3; 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) || (angle < byaw - PI2 && angle > syaw - PI2) || (angle < byaw + PI2 && angle > syaw + PI2)) && Index: src/worldrender.m ================================================================== --- src/worldrender.m +++ src/worldrender.m @@ -316,11 +316,12 @@ 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; int cdist = abs(yaw % 90 - 45); // hack to avoid popup at high fovs at 45 yaw