ref: 18337d7e1454d9ef237e3715f52a1526ec659002
parent: 2852fc75b203598e781db315ea6b2a7735d2db4a
author: qwx <qwx@sciops.net>
date: Thu Mar 25 19:48:47 EDT 2021
better names for basic enums for tile and path grids
--- a/dat.h
+++ b/dat.h
@@ -19,12 +19,11 @@
Nteam = 8,
Nselect = 12,
Nrot = 32,
- Tlwidth = 32,
- Tlheight = Tlwidth,
- Tlsubshift = 2,
- Tlsubwidth = Tlwidth >> Tlsubshift,
- Tlsubheight = Tlheight >> Tlsubshift,
- Tlnsub = Tlwidth / Tlsubwidth,
+ Tilewidth = 32,
+ Tileheight = Tilewidth,
+ Node2Tile = 4,
+ Nodewidth = Tilewidth / Node2Tile,
+ Nodeheight = Tileheight / Node2Tile,
Subpxshift = 16,
Subpxmask = (1 << Subpxshift) - 1,
};
--- a/drw.c
+++ b/drw.c
@@ -62,8 +62,8 @@
return;
}
p = divpt(addpt(subpt(p, selr.min), pan), scale);
- p.x /= Tlsubwidth;
- p.y /= Tlsubheight;
+ p.x /= Nodewidth;
+ p.y /= Nodeheight;
moveone(p, selected[0], mo);
}
@@ -215,7 +215,7 @@
u32int v, *p, *e;
Rectangle r;
- r = Rect(x * Tlsubwidth, y * Tlsubheight, Tlsubwidth, Tlsubheight);
+ r = Rect(x * Nodewidth, y * Nodeheight, Nodewidth, Nodeheight);
if(boundpic(&r, nil) < 0)
return;
p = fb + r.min.y * fbws + r.min.x;
@@ -264,7 +264,7 @@
}
if((mo = selected[0]) != nil && mo->pathp != nil){
for(p=mo->paths; p<mo->pathe; p++)
- compose(p->x / Tlsubwidth, p->y / Tlsubheight, 0x00ff00);
+ compose(p->x / Nodewidth, p->y / Nodeheight, 0x00ff00);
compose(mo->target.x, mo->target.y, 0x00ffff);
}
}
@@ -307,23 +307,23 @@
Mobjl *ml;
clearvis();
- tr.min.x = pan.x / scale / Tlwidth;
- tr.min.y = pan.y / scale / Tlheight;
- tr.max.x = tr.min.x + (pan.x / scale % Tlwidth != 0);
- tr.max.x += fbw / Tlwidth + (fbw % Tlwidth != 0);
+ tr.min.x = pan.x / scale / Tilewidth;
+ tr.min.y = pan.y / scale / Tileheight;
+ tr.max.x = tr.min.x + (pan.x / scale % Tilewidth != 0);
+ tr.max.x += fbw / Tilewidth + (fbw % Tilewidth != 0);
if(tr.max.x > terwidth)
tr.max.x = terwidth;
- tr.max.y = tr.min.y + (pan.y / scale % Tlheight != 0);
- tr.max.y += fbh / Tlheight + (fbh % Tlwidth != 0);
+ tr.max.y = tr.min.y + (pan.y / scale % Tileheight != 0);
+ tr.max.y += fbh / Tileheight + (fbh % Tilewidth != 0);
if(tr.max.y > terheight)
tr.max.y = terheight;
- mr.min.x = max(tr.min.x - 3, 0) * Tlnsub;
- mr.min.y = max(tr.min.y - 3, 0) * Tlnsub;
- mr.max.x = tr.max.x * Tlnsub;
- mr.max.y = tr.max.y * Tlnsub;
+ mr.min.x = max(tr.min.x - 3, 0) * Node2Tile;
+ mr.min.y = max(tr.min.y - 3, 0) * Node2Tile;
+ mr.max.x = tr.max.x * Node2Tile;
+ mr.max.y = tr.max.y * Node2Tile;
for(y=tr.min.y, t=terrain+y*terwidth+tr.min.x; y<tr.max.y; y++){
for(x=tr.min.x; x<tr.max.x; x++, t++)
- drawpic(x*Tlwidth, y*Tlheight, (*t)->p, -1);
+ drawpic(x*Tilewidth, y*Tileheight, (*t)->p, -1);
t += terwidth - (tr.max.x - tr.min.x);
}
for(y=mr.min.y, m=map+y*mapwidth+mr.min.x; y<mr.max.y; y++){
@@ -391,13 +391,13 @@
void
resetfb(void)
{
- fbws = min(mapwidth * Tlsubwidth * scale, Dx(screen->r));
- fbh = min(mapheight * Tlsubheight * scale, Dy(screen->r));
+ fbws = min(mapwidth * Nodewidth * scale, Dx(screen->r));
+ fbh = min(mapheight * Nodeheight * scale, Dy(screen->r));
selr = Rpt(screen->r.min, addpt(screen->r.min, Pt(fbws, fbh)));
p0 = Pt(screen->r.min.x + 8, screen->r.max.y - 3 * font->height);
p0.y -= (p0.y - screen->r.min.y) % scale;
- panmax.x = max(Tlsubwidth * mapwidth * scale - Dx(screen->r), 0);
- panmax.y = max(Tlsubheight * mapheight * scale - Dy(screen->r), 0);
+ panmax.x = max(Nodewidth * mapwidth * scale - Dx(screen->r), 0);
+ panmax.y = max(Nodeheight * mapheight * scale - Dy(screen->r), 0);
if(p0.y < selr.max.y){
panmax.y += selr.max.y - p0.y;
fbh -= selr.max.y - p0.y;
--- a/fs.c
+++ b/fs.c
@@ -400,7 +400,7 @@
o->accel /= 256.0;
o->halt /= 256.0;
/* halting distance in path node units */
- o->halt /= Tlsubwidth;
+ o->halt /= Nodewidth;
if(o->w < 1 || o->h < 1)
sysfatal("readobj: %s invalid dimensions %d,%d", o->name, o->w, o->h);
}
@@ -546,7 +546,7 @@
Objp *op;
for(op=objp; op<objp+nobjp; op++)
- if(spawn(op->x * Tlnsub, op->y * Tlnsub, op->o, op->team) < 0)
+ if(spawn(op->x * Node2Tile, op->y * Node2Tile, op->o, op->team) < 0)
sysfatal("initmapobj: %s team %d: %r", op->o->name, op->team);
free(objp);
}
--- a/map.c
+++ b/map.c
@@ -86,7 +86,7 @@
{
Mobj *mo;
- if(o->f & Fbuild && (x & Tlnsub-1 || y & Tlnsub-1)){
+ if(o->f & Fbuild && (x & Node2Tile-1 || y & Node2Tile-1)){
werrstr("mapspawn: building spawn %d,%d not aligned to terrain map", x, y);
return nil;
}
@@ -95,8 +95,8 @@
mo = emalloc(sizeof *mo);
mo->x = x;
mo->y = y;
- mo->px = x * Tlsubwidth;
- mo->py = y * Tlsubheight;
+ mo->px = x * Nodewidth;
+ mo->py = y * Nodeheight;
mo->subpx = mo->px << Subpxshift;
mo->subpy = mo->py << Subpxshift;
mo->o = o;
@@ -113,8 +113,8 @@
int n;
Map *m;
- mapwidth = terwidth * Tlnsub;
- mapheight = terheight * Tlnsub;
+ mapwidth = terwidth * Node2Tile;
+ mapheight = terheight * Node2Tile;
n = mapwidth * mapheight;
map = emalloc(n * sizeof *map);
node = emalloc(n * sizeof *node);
--- a/path.c
+++ b/path.c
@@ -81,10 +81,10 @@
int w, h;
w = mo->o->w;
- if((mo->subpx & Subpxmask) != 0 && mo->x != (mo->px + 1) / Tlsubwidth)
+ if((mo->subpx & Subpxmask) != 0 && mo->x != (mo->px + 1) / Nodewidth)
w++;
h = mo->o->h;
- if((mo->subpy & Subpxmask) != 0 && mo->y != (mo->py + 1) / Tlsubwidth)
+ if((mo->subpy & Subpxmask) != 0 && mo->y != (mo->py + 1) / Nodewidth)
h++;
bset(mo->x, mo->y, w, h, set);
}
@@ -381,8 +381,8 @@
p = mo->paths + n->step;
mo->pathe = p--;
for(; n!=a; n=n->from){
- x = n->x * Tlsubwidth;
- y = n->y * Tlsubheight;
+ x = n->x * Nodewidth;
+ y = n->y * Nodeheight;
*p-- = (Point){x, y};
}
assert(p == mo->paths - 1);
--- a/sim.c
+++ b/sim.c
@@ -215,7 +215,7 @@
if(Δrx < 0)
sx += mo->u < 0 ? -Δrx : Δrx;
x = (sx >> Subpxshift) + ((sx & Subpxmask) != 0);
- x /= Tlsubwidth;
+ x /= Nodewidth;
}
if(Δry > 0){
sy += Δv;
@@ -223,7 +223,7 @@
if(Δry < 0)
sy += mo->v < 0 ? -Δry : Δry;
y = (sy >> Subpxshift) + ((sy & Subpxmask) != 0);
- y /= Tlsubwidth;
+ y /= Nodewidth;
}
if(isblocked(x, y, mo->o))
goto end;
@@ -238,8 +238,8 @@
mo->subpy = sy;
mo->px = sx >> Subpxshift;
mo->py = sy >> Subpxshift;
- mo->x = mo->px / Tlsubwidth;
- mo->y = mo->py / Tlsubheight;
+ mo->x = mo->px / Nodewidth;
+ mo->y = mo->py / Nodeheight;
}
markmobj(mo, 1);
dx = mo->px - px;
@@ -246,7 +246,7 @@
dx *= dx;
dy = mo->py - py;
dy *= dy;
- mo->pathlen -= sqrt(dx + dy) / Tlsubwidth;
+ mo->pathlen -= sqrt(dx + dy) / Nodewidth;
return 0;
end:
werrstr("trymove: can't move to %d,%d", x, y);
@@ -257,7 +257,7 @@
dx *= dx;
dy = mo->py - py;
dy *= dy;
- mo->pathlen -= sqrt(dx + dy) / Tlsubwidth;
+ mo->pathlen -= sqrt(dx + dy) / Nodewidth;
return -1;
}