From 20ccab90225c94c85087fde116ddf6cf3383506f Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 16 Aug 2012 21:48:44 +0000 Subject: [PATCH] Clean up classic's and Polymost's dorotatesprite functions (triv. changes only) git-svn-id: https://svn.eduke32.com/eduke32@2909 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/engine.c | 87 ++++++++++++++++++---------- polymer/eduke32/build/src/polymost.c | 21 ++++--- 2 files changed, 68 insertions(+), 40 deletions(-) diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index f2a691dc5..6645ddf23 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -6848,11 +6848,13 @@ static int32_t clippoly4(int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2) // dorotatesprite (internal) // //JBF 20031206: Thanks to Ken's hunting, s/(rx1|ry1|rx2|ry2)/n\1/ in this function -static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, - char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid) +static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, + int8_t dashade, char dapalnum, int32_t dastat, + int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, + int32_t uniqid) { int32_t cosang, sinang, v, nextv, dax1, dax2, oy, bx, by; - int32_t i, x, y, x1, y1, x2, y2, gx1, gy1 ; + int32_t i, x, y, x1, y1, x2, y2, gx1, gy1; intptr_t p, bufplc, palookupoffs; int32_t xsiz, ysiz, xoff, yoff, npoints, yplc, yinc, lx, rx; int32_t xv, yv, xv2, yv2; @@ -6860,49 +6862,67 @@ static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t UNREFERENCED_PARAMETER(uniqid); //============================================================================= //POLYMOST BEGINS #ifdef USE_OPENGL - if (rendmode >= 3 && qsetmode == 200) { polymost_dorotatesprite(sx,sy,z,a,picnum,dashade,dapalnum,dastat,cx1,cy1,cx2,cy2,uniqid); return; } + if (rendmode >= 3 && qsetmode == 200) + { + polymost_dorotatesprite(sx,sy,z,a,picnum,dashade,dapalnum,dastat,cx1,cy1,cx2,cy2,uniqid); + return; + } #endif //============================================================================= //POLYMOST ENDS + // bound clipping rectangle to screen if (cx1 < 0) cx1 = 0; if (cy1 < 0) cy1 = 0; if (cx2 > xres-1) cx2 = xres-1; if (cy2 > yres-1) cy2 = yres-1; - xsiz = tilesizx[picnum]; ysiz = tilesizy[picnum]; - if (dastat&16) { xoff = 0; yoff = 0; } + xsiz = tilesizx[picnum]; + ysiz = tilesizy[picnum]; + + if (dastat&16) + { + // Bit 1<<4 set: origin is top left corner? + xoff = 0; + yoff = 0; + } else { + // Bit 1<<4 clear: origin is center of tile, and per-tile offset is applied. + // TODO: split the two? xoff = (int32_t)((int8_t)((picanm[picnum]>>8)&255))+(xsiz>>1); yoff = (int32_t)((int8_t)((picanm[picnum]>>16)&255))+(ysiz>>1); } - if (dastat&4) yoff = ysiz-yoff; + // Bit 1<<2: invert y + if (dastat&4) + yoff = ysiz-yoff; - cosang = sintable[(a+512)&2047]; sinang = sintable[a&2047]; + cosang = sintable[(a+512)&2047]; + sinang = sintable[a&2047]; - if ((dastat&2) != 0) //Auto window size scaling + if (dastat&2) //Auto window size scaling { if ((dastat&8) == 0) { x = xdimenscale; //= scale(xdimen,yxaspect,320); - sx = ((cx1+cx2+2)<<15)+scale(sx-(320<<15),xdimen,320); - sy = ((cy1+cy2+2)<<15)+mulscale16(sy-(200<<15),x); + sx = ((cx1+cx2+2)<<15) + scale(sx-(320<<15),xdimen,320); + sy = ((cy1+cy2+2)<<15) + mulscale16(sy-(200<<15),x); } else { //If not clipping to startmosts, & auto-scaling on, as a //hard-coded bonus, scale to full screen instead x = scale(xdim,yxaspect,320); - sx = (xdim<<15)+32768+scale(sx-(320<<15),xdim,320); - sy = (ydim<<15)+32768+mulscale16(sy-(200<<15),x); + sx = (xdim<<15)+32768 + scale(sx-(320<<15),xdim,320); + sy = (ydim<<15)+32768 + mulscale16(sy-(200<<15),x); } + z = mulscale16(z,x); } xv = mulscale14(cosang,z); yv = mulscale14(sinang,z); - if (((dastat&2) != 0) || ((dastat&8) == 0)) //Don't aspect unscaled perms + if ((dastat&2) || (dastat&8) == 0) //Don't aspect unscaled perms { xv2 = mulscale16(xv,xyaspect); yv2 = mulscale16(yv,xyaspect); @@ -6929,7 +6949,8 @@ static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t gx1 = nrx1[0]; gy1 = nry1[0]; //back up these before clipping - if ((npoints = clippoly4(cx1<<16,cy1<<16,(cx2+1)<<16,(cy2+1)<<16)) < 3) return; + npoints = clippoly4(cx1<<16,cy1<<16,(cx2+1)<<16,(cy2+1)<<16); + if (npoints < 3) return; lx = nrx1[0]; rx = nrx1[0]; @@ -6967,7 +6988,7 @@ static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t i = divscale32(1L,z); xv = mulscale14(sinang,i); yv = mulscale14(cosang,i); - if (((dastat&2) != 0) || ((dastat&8) == 0)) //Don't aspect unscaled perms + if ((dastat&2) || (dastat&8)==0) //Don't aspect unscaled perms { yv2 = mulscale16(-xv,yxaspect); xv2 = mulscale16(yv,yxaspect); @@ -6978,25 +6999,21 @@ static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t xv2 = yv; } - x1 = (lx>>16); x2 = (rx>>16); + x1 = (lx>>16); + x2 = (rx>>16); oy = 0; - x = (x1<<16)-1-gx1; y = (oy<<16)+65535-gy1; + x = (x1<<16)-1-gx1; + y = (oy<<16)+65535-gy1; bx = dmulscale16(x,xv2,y,xv); by = dmulscale16(x,yv2,y,yv); - if (dastat&4) { yv = -yv; yv2 = -yv2; by = (ysiz<<16)-1-by; } - /* if (origbuffermode == 0) - { - if (dastat&128) - { - obuffermode = buffermode; - buffermode = 0; - setactivepage(activepage); - } - } - else if (dastat&8) - permanentupdate = 1; */ + if (dastat&4) + { + yv = -yv; + yv2 = -yv2; + by = (ysiz<<16)-1-by; + } #if defined ENGINE_USING_A_C if ((dastat&1)==0 && ((a&1023) == 0) && (ysiz <= 256)) //vlineasm4 has 256 high limit! @@ -7009,7 +7026,11 @@ static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t if (((a&1023) == 0) && (ysiz <= 256)) //vlineasm4 has 256 high limit! { - if (dastat&64) setupvlineasm(24L); else setupmvlineasm(24L); + if (dastat&64) + setupvlineasm(24L); + else + setupmvlineasm(24L); + by <<= 8; yv <<= 8; yv2 <<= 8; palookupoffse[0] = palookupoffse[1] = palookupoffse[2] = palookupoffse[3] = palookupoffs; @@ -13516,7 +13537,9 @@ void flushperms(void) // // rotatesprite // -void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2) +void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, + int8_t dashade, char dapalnum, int32_t dastat, + int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2) { int32_t i; permfifotype *per, *per2; diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 96ecff202..1b2127e3f 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -5334,7 +5334,7 @@ void polymost_drawsprite(int32_t snum) tilesizy[globalpicnum]=oldsizy; } -//sx,sy center of sprite; screen coods*65536 +//sx,sy center of sprite; screen coords*65536 //z zoom*65536. > is zoomed in //a angle (0 is default) //dastat&1 1:translucence @@ -5347,10 +5347,12 @@ void polymost_drawsprite(int32_t snum) //dastat&128 1:draw all pages (permanent) //cx1,... clip window (actual screen coords) void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, - int8_t dashade, char dapalnum, int32_t dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid) + int8_t dashade, char dapalnum, int32_t dastat, + int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, int32_t uniqid) { static int32_t onumframes = 0; - int32_t n, nn, x, zz, xoff, yoff, xsiz, ysiz, method; + + int32_t n, nn, xoff, yoff, xsiz, ysiz, method; int32_t ogpicnum, ogshade, ogpal, ofoffset, oxdimen, oydimen, oldviewingrange; double ogxyaspect; double ogchang, ogshang, ogctang, ogstang, oghalfx, oghoriz, fx, fy, x1, y1, z1, x2, y2; @@ -5362,11 +5364,13 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 int32_t olddetailmapping = r_detailmapping, oldglowmapping = r_glowmapping; #endif - #ifdef USE_OPENGL if (rendmode >= 3 && usemodels && hudmem[(dastat&4)>>2][picnum].angadd) { - if ((tile2model[Ptile2tile(picnum,dapalnum)].modelid >= 0) && (tile2model[Ptile2tile(picnum,dapalnum)].framenum >= 0)) + const int32_t tilenum = Ptile2tile(picnum,dapalnum); + + if (tile2model[tilenum].modelid >= 0 && + tile2model[tilenum].framenum >= 0) { spritetype tspr; memset(&tspr,0,sizeof(spritetype)); @@ -5547,7 +5551,6 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 #else mddraw(&tspr); #endif - viewingrange = oldviewingrange; gxyaspect = ogxyaspect; globalshade = ogshade; @@ -5556,6 +5559,7 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 gshang = ogshang; gctang = ogctang; gstang = ogstang; + return; } } @@ -5738,7 +5742,7 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 nn = z = 0; do { - zz = z+1; if (zz == n) zz = 0; + int32_t zz = z+1; if (zz == n) zz = 0; x1 = px[z]; x2 = px[zz]-x1; if ((cx1 <= x1) && (x1 <= cx2)) { px2[nn] = x1; py2[nn] = py[z]; nn++; } if (x2 <= 0) fx = cx2; else fx = cx1; d = fx-x1; if ((d < x2) != (d < 0)) { px2[nn] = fx; py2[nn] = (py[zz]-py[z])*d/x2 + py[z]; nn++; } @@ -5747,12 +5751,13 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 z = zz; } while (z); + if (nn >= 3) { n = z = 0; do { - zz = z+1; if (zz == nn) zz = 0; + int32_t zz = z+1; if (zz == nn) zz = 0; y1 = py2[z]; y2 = py2[zz]-y1; if ((cy1 <= y1) && (y1 <= cy2)) { py[n] = y1; px[n] = px2[z]; n++; } if (y2 <= 0) fy = cy2; else fy = cy1; d = fy-y1; if ((d < y2) != (d < 0)) { py[n] = fy; px[n] = (px2[zz]-px2[z])*d/y2 + px2[z]; n++; }