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
This commit is contained in:
helixhorned 2012-08-16 21:48:44 +00:00
parent 8ac85eef54
commit 20ccab9022
2 changed files with 68 additions and 40 deletions

View file

@ -6848,11 +6848,13 @@ static int32_t clippoly4(int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
// dorotatesprite (internal) // dorotatesprite (internal)
// //
//JBF 20031206: Thanks to Ken's hunting, s/(rx1|ry1|rx2|ry2)/n\1/ in this function //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, static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum,
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)
{ {
int32_t cosang, sinang, v, nextv, dax1, dax2, oy, bx, by; 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; intptr_t p, bufplc, palookupoffs;
int32_t xsiz, ysiz, xoff, yoff, npoints, yplc, yinc, lx, rx; int32_t xsiz, ysiz, xoff, yoff, npoints, yplc, yinc, lx, rx;
int32_t xv, yv, xv2, yv2; 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); UNREFERENCED_PARAMETER(uniqid);
//============================================================================= //POLYMOST BEGINS //============================================================================= //POLYMOST BEGINS
#ifdef USE_OPENGL #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 #endif
//============================================================================= //POLYMOST ENDS //============================================================================= //POLYMOST ENDS
// bound clipping rectangle to screen
if (cx1 < 0) cx1 = 0; if (cx1 < 0) cx1 = 0;
if (cy1 < 0) cy1 = 0; if (cy1 < 0) cy1 = 0;
if (cx2 > xres-1) cx2 = xres-1; if (cx2 > xres-1) cx2 = xres-1;
if (cy2 > yres-1) cy2 = yres-1; if (cy2 > yres-1) cy2 = yres-1;
xsiz = tilesizx[picnum]; ysiz = tilesizy[picnum]; xsiz = tilesizx[picnum];
if (dastat&16) { xoff = 0; yoff = 0; } ysiz = tilesizy[picnum];
if (dastat&16)
{
// Bit 1<<4 set: origin is top left corner?
xoff = 0;
yoff = 0;
}
else 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); xoff = (int32_t)((int8_t)((picanm[picnum]>>8)&255))+(xsiz>>1);
yoff = (int32_t)((int8_t)((picanm[picnum]>>16)&255))+(ysiz>>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) if ((dastat&8) == 0)
{ {
x = xdimenscale; //= scale(xdimen,yxaspect,320); x = xdimenscale; //= scale(xdimen,yxaspect,320);
sx = ((cx1+cx2+2)<<15)+scale(sx-(320<<15),xdimen,320); sx = ((cx1+cx2+2)<<15) + scale(sx-(320<<15),xdimen,320);
sy = ((cy1+cy2+2)<<15)+mulscale16(sy-(200<<15),x); sy = ((cy1+cy2+2)<<15) + mulscale16(sy-(200<<15),x);
} }
else else
{ {
//If not clipping to startmosts, & auto-scaling on, as a //If not clipping to startmosts, & auto-scaling on, as a
//hard-coded bonus, scale to full screen instead //hard-coded bonus, scale to full screen instead
x = scale(xdim,yxaspect,320); x = scale(xdim,yxaspect,320);
sx = (xdim<<15)+32768+scale(sx-(320<<15),xdim,320); sx = (xdim<<15)+32768 + scale(sx-(320<<15),xdim,320);
sy = (ydim<<15)+32768+mulscale16(sy-(200<<15),x); sy = (ydim<<15)+32768 + mulscale16(sy-(200<<15),x);
} }
z = mulscale16(z,x); z = mulscale16(z,x);
} }
xv = mulscale14(cosang,z); xv = mulscale14(cosang,z);
yv = mulscale14(sinang,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); xv2 = mulscale16(xv,xyaspect);
yv2 = mulscale16(yv,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 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]; 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); i = divscale32(1L,z);
xv = mulscale14(sinang,i); xv = mulscale14(sinang,i);
yv = mulscale14(cosang,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); yv2 = mulscale16(-xv,yxaspect);
xv2 = mulscale16(yv,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; xv2 = yv;
} }
x1 = (lx>>16); x2 = (rx>>16); x1 = (lx>>16);
x2 = (rx>>16);
oy = 0; 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); bx = dmulscale16(x,xv2,y,xv);
by = dmulscale16(x,yv2,y,yv); by = dmulscale16(x,yv2,y,yv);
if (dastat&4) { yv = -yv; yv2 = -yv2; by = (ysiz<<16)-1-by; }
/* if (origbuffermode == 0) if (dastat&4)
{ {
if (dastat&128) yv = -yv;
{ yv2 = -yv2;
obuffermode = buffermode; by = (ysiz<<16)-1-by;
buffermode = 0; }
setactivepage(activepage);
}
}
else if (dastat&8)
permanentupdate = 1; */
#if defined ENGINE_USING_A_C #if defined ENGINE_USING_A_C
if ((dastat&1)==0 && ((a&1023) == 0) && (ysiz <= 256)) //vlineasm4 has 256 high limit! 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 (((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; by <<= 8; yv <<= 8; yv2 <<= 8;
palookupoffse[0] = palookupoffse[1] = palookupoffse[2] = palookupoffse[3] = palookupoffs; palookupoffse[0] = palookupoffse[1] = palookupoffse[2] = palookupoffse[3] = palookupoffs;
@ -13516,7 +13537,9 @@ void flushperms(void)
// //
// rotatesprite // 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; int32_t i;
permfifotype *per, *per2; permfifotype *per, *per2;

View file

@ -5334,7 +5334,7 @@ void polymost_drawsprite(int32_t snum)
tilesizy[globalpicnum]=oldsizy; 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 //z zoom*65536. > is zoomed in
//a angle (0 is default) //a angle (0 is default)
//dastat&1 1:translucence //dastat&1 1:translucence
@ -5347,10 +5347,12 @@ void polymost_drawsprite(int32_t snum)
//dastat&128 1:draw all pages (permanent) //dastat&128 1:draw all pages (permanent)
//cx1,... clip window (actual screen coords) //cx1,... clip window (actual screen coords)
void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, 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; 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; int32_t ogpicnum, ogshade, ogpal, ofoffset, oxdimen, oydimen, oldviewingrange;
double ogxyaspect; double ogxyaspect;
double ogchang, ogshang, ogctang, ogstang, oghalfx, oghoriz, fx, fy, x1, y1, z1, x2, y2; 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; int32_t olddetailmapping = r_detailmapping, oldglowmapping = r_glowmapping;
#endif #endif
#ifdef USE_OPENGL #ifdef USE_OPENGL
if (rendmode >= 3 && usemodels && hudmem[(dastat&4)>>2][picnum].angadd) 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; spritetype tspr;
memset(&tspr,0,sizeof(spritetype)); 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 #else
mddraw(&tspr); mddraw(&tspr);
#endif #endif
viewingrange = oldviewingrange; viewingrange = oldviewingrange;
gxyaspect = ogxyaspect; gxyaspect = ogxyaspect;
globalshade = ogshade; globalshade = ogshade;
@ -5556,6 +5559,7 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16
gshang = ogshang; gshang = ogshang;
gctang = ogctang; gctang = ogctang;
gstang = ogstang; gstang = ogstang;
return; return;
} }
} }
@ -5738,7 +5742,7 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16
nn = z = 0; nn = z = 0;
do 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++; } 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 (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++; } 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; z = zz;
} }
while (z); while (z);
if (nn >= 3) if (nn >= 3)
{ {
n = z = 0; n = z = 0;
do 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++; } 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 (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++; } if ((d < y2) != (d < 0)) { py[n] = fy; px[n] = (px2[zz]-px2[z])*d/y2 + px2[z]; n++; }