From b2811e4893d38f08992196acfdd03c57ca818db8 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Wed, 17 Sep 2008 01:42:40 +0000 Subject: [PATCH] faster reading of world structure git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2655 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/editing.cpp | 8 ++++---- source/src/physics.cpp | 6 +++--- source/src/world.cpp | 26 +++++++++++++------------- source/src/world.h | 4 ++-- source/src/worldio.cpp | 14 +++++++------- source/src/worldrender.cpp | 29 +++++++++++++++-------------- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/source/src/editing.cpp b/source/src/editing.cpp index 1aed68c1..a7e9299c 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -157,9 +157,9 @@ void cursorupdate() // called every frame fr sqr *s = S(ix,iy); if(SOLID(s)) continue; float h1 = sheight(s, s, z); - float h2 = sheight(s, SWS(s,1,0,ssize), z); - float h3 = sheight(s, SWS(s,1,1,ssize), z); - float h4 = sheight(s, SWS(s,0,1,ssize), z); + float h2 = sheight(s, SWS(s,1,0,sfactor), z); + float h3 = sheight(s, SWS(s,1,1,sfactor), z); + float h4 = sheight(s, SWS(s,0,1,sfactor), z); if(s->tag) linestyle(GRIDW, 0xFF, 0x40, 0x40); else if(s->type==FHF || s->type==CHF) linestyle(GRIDW, 0x80, 0xFF, 0x80); else linestyle(GRIDW, 0x80, 0x80, 0x80); @@ -177,7 +177,7 @@ void cursorupdate() // called every frame fr float ih = sheight(s, s, z); linestyle(GRIDS, 0xFF, 0xFF, 0xFF); block b = { cx, cy, 1, 1 }; - box(b, ih, sheight(s, SWS(s,1,0,ssize), z), sheight(s, SWS(s,1,1,ssize), z), sheight(s, SWS(s,0,1,ssize), z)); + box(b, ih, sheight(s, SWS(s,1,0,sfactor), z), sheight(s, SWS(s,1,1,sfactor), z), sheight(s, SWS(s,0,1,sfactor), z)); linestyle(GRIDS, 0xFF, 0x00, 0x00); dot(cx, cy, ih); ch = (int)ih; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index f8709c38..80eaf984 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -92,12 +92,12 @@ bool plcollide(physent *d, physent *o, float &headspace, float &hi, float &lo) bool cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, int &bs) // recursively collide with a mipmapped corner cube { sqr *w = wmip[mip]; - int sz = ssize>>mip; - bool stest = SOLID(SWS(w, x+dx, y, sz)) && SOLID(SWS(w, x, y+dy, sz)); + int mfactor = sfactor - mip; + bool stest = SOLID(SWS(w, x+dx, y, mfactor)) && SOLID(SWS(w, x, y+dy, mfactor)); mip++; x /= 2; y /= 2; - if(SWS(wmip[mip], x, y, ssize>>mip)->type==CORNER) + if(SWS(wmip[mip], x, y, mfactor-1)->type==CORNER) { bx = x<>level; - int vs = ssize>>(level+1); + int wfactor = sfactor - level; + int vfactor = sfactor - (level+1); block s = b; if(s.x&1) { s.x--; s.xs++; } if(s.y&1) { s.y--; s.ys++; } @@ -32,11 +32,11 @@ void remip(block &b, int level) for(int x = s.x; xtype==CHF || r->type==FHF) // can make a perfect mip out of a hf if slopes lie on one line { - if(o[0]->vdelta-o[1]->vdelta != o[1]->vdelta-SWS(w,x+2,y,ws)->vdelta - || o[0]->vdelta-o[2]->vdelta != o[2]->vdelta-SWS(w,x+2,y+2,ws)->vdelta - || o[0]->vdelta-o[3]->vdelta != o[3]->vdelta-SWS(w,x,y+2,ws)->vdelta - || o[3]->vdelta-o[2]->vdelta != o[2]->vdelta-SWS(w,x+2,y+1,ws)->vdelta - || o[1]->vdelta-o[2]->vdelta != o[2]->vdelta-SWS(w,x+1,y+2,ws)->vdelta) goto c; + if(o[0]->vdelta-o[1]->vdelta != o[1]->vdelta-SWS(w,x+2,y,wfactor)->vdelta + || o[0]->vdelta-o[2]->vdelta != o[2]->vdelta-SWS(w,x+2,y+2,wfactor)->vdelta + || o[0]->vdelta-o[3]->vdelta != o[3]->vdelta-SWS(w,x,y+2,wfactor)->vdelta + || o[3]->vdelta-o[2]->vdelta != o[2]->vdelta-SWS(w,x+2,y+1,wfactor)->vdelta + || o[1]->vdelta-o[2]->vdelta != o[2]->vdelta-SWS(w,x+1,y+2,wfactor)->vdelta) goto c; } } { loopi(4) if(o[i]->defer) goto c; } // if any of the constituents is not perfect, then this one isn't either @@ -306,7 +306,7 @@ void empty_world(int factor, bool force) // main empty world creation routine { loop(x,ssize/2) loop(y,ssize/2) { - *S(x+ssize/4, y+ssize/4) = *SWS(oldworld, x, y, ssize/2); + *S(x+ssize/4, y+ssize/4) = *SWS(oldworld, x, y, sfactor-1); } loopv(ents) { diff --git a/source/src/world.h b/source/src/world.h index a185acde..8e29b50d 100644 --- a/source/src/world.h +++ b/source/src/world.h @@ -47,8 +47,8 @@ struct header // map file format header int reserved[14]; }; -#define SWS(w,x,y,s) (&(w)[(y)*(s)+(x)]) -#define SW(w,x,y) SWS(w,x,y,ssize) +#define SWS(w,x,y,s) (&(w)[((y)<<(s))+(x)]) +#define SW(w,x,y) SWS(w,x,y,sfactor) #define S(x,y) SW(world,x,y) // convenient lookup of a lowest mip cube #define SMALLEST_FACTOR 6 // determines number of mips there can be #define DEFAULT_FACTOR 8 diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 28210d59..f4873d25 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -58,10 +58,10 @@ void voptimize() // reset vdeltas on non-hf cubes void topt(sqr *s, bool &wf, bool &uf, int &wt, int &ut) { sqr *o[4]; - o[0] = SWS(s,0,-1,ssize); - o[1] = SWS(s,0,1,ssize); - o[2] = SWS(s,1,0,ssize); - o[3] = SWS(s,-1,0,ssize); + o[0] = SWS(s,0,-1,sfactor); + o[1] = SWS(s,0,1,sfactor); + o[2] = SWS(s,1,0,sfactor); + o[3] = SWS(s,-1,0,sfactor); wf = true; uf = true; if(SOLID(s)) @@ -93,9 +93,9 @@ void toptimize() // FIXME: only does 2x2, make atleast for 4x4 also s[0] = S(x,y); int wt = s[0]->wtex, ut = s[0]->utex; topt(s[0], wf[0], uf[0], wt, ut); - topt(s[1] = SWS(s[0],0,1,ssize), wf[1], uf[1], wt, 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); + topt(s[1] = SWS(s[0],0,1,sfactor), wf[1], uf[1], wt, ut); + topt(s[2] = SWS(s[0],1,1,sfactor), wf[2], uf[2], wt, ut); + topt(s[3] = SWS(s[0],1,0,sfactor), wf[3], uf[3], wt, ut); loopi(4) { if(wf[i]) s[i]->wtex = wt; diff --git a/source/src/worldrender.cpp b/source/src/worldrender.cpp index fbc314ab..2321b660 100644 --- a/source/src/worldrender.cpp +++ b/source/src/worldrender.cpp @@ -79,17 +79,17 @@ bool issemi(int mip, int x, int y, int x1, int y1, int x2, int y2) { if(!(mip--)) return true; sqr *w = wmip[mip]; - int msize = ssize>>mip; + int mfactor = sfactor - mip; x *= 2; y *= 2; - switch(SWS(w, x+x1, y+y1, msize)->type) + switch(SWS(w, x+x1, y+y1, mfactor)->type) { case SEMISOLID: if(issemi(mip, x+x1, y+y1, x1, y1, x2, y2)) return true; case CORNER: case SOLID: break; default: return true; } - switch(SWS(w, x+x2, y+y2, msize)->type) + switch(SWS(w, x+x2, y+y2, mfactor)->type) { case SEMISOLID: if(issemi(mip, x+x2, y+y2, x1, y1, x2, y2)) return true; case CORNER: @@ -108,7 +108,8 @@ bool render_floor, render_ceil; void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs, int ys) { sqr *w = wmip[mip]; - int sz = ssize>>mip; + int mfactor = sfactor - mip; + int sz = 1<>mip; int vyy = ((int)vy+(1<>mip; int lx = vxx-lodleft; // these mark the rect inside the current rest that we want to render using a lower mip level @@ -119,15 +120,15 @@ void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs, float fsize = (float)(1<occluded = isoccluded(camera1->o.x, camera1->o.y, (float)(ox<occluded = isoccluded(camera1->o.x, camera1->o.y, (float)(ox<>mip; int pvy = (int)vy>>mip; if(pvx>=0 && pvy>=0 && pvxoccluded = 0; - SWS(w, pvx, pvy, sz)->occluded = 0; // player cell never occluded + //SWS(w,vxx,vyy,mfactor)->occluded = 0; + SWS(w, pvx, pvy, mfactor)->occluded = 0; // player cell never occluded } #define df(x) s->floor-(x->vdelta/4.0f) @@ -140,17 +141,17 @@ void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs, // render here. #define LOOPH {for(int xx = x; xxoccluded==1) continue; \ + sqr *s = SWS(w,xx,yy,mfactor); if(s->occluded==1) continue; \ if(s->defer && !s->occluded && mip && xx>=lx && xx=ly && yydefer && !next->occluded) yy++; // collect 2xN rect of lower mip + while(yydefer && !next->occluded) yy++; // collect 2xN rect of lower mip render_seg_new(vx, vy, vh, mip-1, xx*2, start*2, xx*2+2, yy*2+2); continue; } @@ -182,8 +183,8 @@ void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs, // zSt // vu - sqr *w = SWS(s,0,-1,sz); - sqr *z = SWS(s,-1,0,sz); + sqr *w = SWS(s,0,-1,mfactor); + sqr *z = SWS(s,-1,0,mfactor); bool normalwall = true; if(s->type==CORNER)