Clean up engine code by factoring repeated 3-liners into spriteheightofs().

This function also changed: it doesn't handle floor-aligned sprites now,
and the z offset is returned instead of set by pointer.

git-svn-id: https://svn.eduke32.com/eduke32@3205 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-11-17 19:46:43 +00:00
parent 6abb63670c
commit 0316868c75
4 changed files with 38 additions and 65 deletions

View file

@ -848,7 +848,7 @@ int32_t changespritestat(int16_t spritenum, int16_t newstatnum);
int32_t setsprite(int16_t spritenum, const vec3_t *) ATTRIBUTE((nonnull(2)));
int32_t setspritez(int16_t spritenum, const vec3_t *) ATTRIBUTE((nonnull(2)));
void spriteheightofs(int16_t i, int32_t *height, int32_t *zofs, int32_t alsotileyofs);
int32_t spriteheightofs(int16_t i, int32_t *height, int32_t alsotileyofs) ATTRIBUTE((nonnull(2)));
int32_t screencapture(const char *filename, char inverseit, const char *versionstr) ATTRIBUTE((nonnull(1)));

View file

@ -234,7 +234,7 @@ int32_t fillsector(int16_t sectnum, int32_t fillcolor); // fillcolor == -1: def
int32_t ask_if_sure(const char *query, uint32_t flags);
int32_t editor_ask_function(const char *question, const char *dachars, int32_t numchars);
void spriteoncfz(int32_t i, int32_t *czptr, int32_t *fzptr);
void spriteoncfz(int32_t i, int32_t *czptr, int32_t *fzptr) ATTRIBUTE((nonnull(2,3)));
void DoSpriteOrnament(int32_t i);
void getpoint(int32_t searchxe, int32_t searchye, int32_t *x, int32_t *y);

View file

@ -879,15 +879,16 @@ static void loadmhk(int32_t domessage)
// one convenient function
void spriteoncfz(int32_t i, int32_t *czptr, int32_t *fzptr)
{
int32_t cz,fz, height, zofs;
int32_t height, zofs;
getzsofslope(sprite[i].sectnum, sprite[i].x,sprite[i].y, &cz, &fz);
spriteheightofs(i, &height, &zofs, 0);
getzsofslope(sprite[i].sectnum, sprite[i].x,sprite[i].y, czptr, fzptr);
if ((sprite[i].cstat&48)==32)
return;
if (czptr)
*czptr = cz + height - zofs;
if (fzptr)
*fzptr = fz - zofs;
zofs = spriteheightofs(i, &height, 0);
*czptr += height - zofs;
*fzptr -= zofs;
}
static void move_and_update(int32_t xvect, int32_t yvect, int32_t addshr)

View file

@ -2492,7 +2492,7 @@ int32_t engine_addtsprite(int16_t z, int16_t sectnum)
if (cb < 0 && fb < 0)
return 0;
spriteheightofs(z, &spheight, &spzofs, 1);
spzofs = spriteheightofs(z, &spheight, 1);
// TODO: get*zofslope?
if (cb>=0 && spr->z+spzofs-spheight < sector[sectnum].ceilingz)
@ -10881,7 +10881,6 @@ int32_t ksqrt(uint32_t num)
return(nsqrtasm(num));
}
//
// krecip
//
@ -10890,33 +10889,25 @@ int32_t krecip(int32_t num)
return(krecipasm(num));
}
void spriteheightofs(int16_t i, int32_t *height, int32_t *zofs, int32_t alsotileyofs)
// Gets the BUILD unit height and z offset of a sprite.
// Returns the z offset, 'height' may be NULL.
int32_t spriteheightofs(int16_t i, int32_t *height, int32_t alsotileyofs)
{
int32_t hei, flooraligned=((sprite[i].cstat&48)==32);
int32_t picnum = sprite[i].picnum;
if (zofs)
*zofs = 0;
if (flooraligned)
{
if (height)
*height = 0;
return;
}
hei = (tilesizy[picnum]*sprite[i].yrepeat)<<2;
if (zofs)
{
if (sprite[i].cstat&128)
*zofs = hei>>1;
if (alsotileyofs)
if (picanm[picnum].yofs)
*zofs -= picanm[picnum].yofs*sprite[i].yrepeat<<2;
}
int32_t hei, zofs=0;
const int32_t picnum=sprite[i].picnum, yrepeat=sprite[i].yrepeat;
hei = (tilesizy[picnum]*yrepeat)<<2;
*height = hei;
if (sprite[i].cstat&128)
zofs = hei>>1;
// NOTE: a positive per-tile yoffset translates the sprite into the
// negative world z direction (i.e. upward).
if (alsotileyofs)
zofs -= picanm[picnum].yofs*yrepeat<<2;
return zofs;
}
//
@ -11456,9 +11447,7 @@ restart_grand:
intz = sv->z+scale(vz,topt,bot);
i = (tilesizy[spr->picnum]*spr->yrepeat<<2);
if (cstat&128) z1 += (i>>1);
if (picanm[spr->picnum].yofs) z1 -= (picanm[spr->picnum].yofs*spr->yrepeat<<2);
z1 += spriteheightofs(z, &i, 1);
if ((intz > z1) || (intz < z1-i)) continue;
topu = vx*(y1-sv->y) - vy*(x1-sv->x);
@ -11499,9 +11488,7 @@ restart_grand:
if (klabs(intx-sv->x)+klabs(inty-sv->y) > klabs((hit->pos.x)-sv->x)+klabs((hit->pos.y)-sv->y)) continue;
k = ((tilesizy[tilenum]*spr->yrepeat)<<2);
if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z;
if (picanm[tilenum].yofs) daz -= (picanm[tilenum].yofs*spr->yrepeat<<2);
daz = spr->z + spriteheightofs(z, &k, 1);
if (intz > daz-k && intz < daz)
{
if (picanm[tilenum].sf&PICANM_TEXHITSCAN_BIT)
@ -11744,10 +11731,8 @@ void neartag(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange,
if (bot != 0)
{
intz = zs+scale(vz,topt,bot);
i = tilesizy[spr->picnum]*spr->yrepeat;
if (spr->cstat&128) z1 += (i<<1);
if (picanm[spr->picnum].yofs) z1 -= (picanm[spr->picnum].yofs*spr->yrepeat<<2);
if ((intz <= z1) && (intz >= z1-(i<<2)))
z1 += spriteheightofs(z, &i, 1);
if (intz >= z1-i && intz <= z1)
{
topu = vx*(y1-ys) - vy*(x1-xs);
@ -12313,9 +12298,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
case 0:
if ((x1 >= xmin) && (x1 <= xmax) && (y1 >= ymin) && (y1 <= ymax))
{
k = ((tilesizy[spr->picnum]*spr->yrepeat)<<2);
if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z;
if (picanm[spr->picnum].yofs) daz -= (picanm[spr->picnum].yofs*spr->yrepeat<<2);
daz = spr->z + spriteheightofs(j, &k, 1);
if (((pos->z) < daz+ceildist) && ((pos->z) > daz-k-flordist))
{
bsz = (spr->clipdist<<2)+walldist; if (gx < 0) bsz = -bsz;
@ -12326,9 +12309,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
}
break;
case 16:
k = ((tilesizy[spr->picnum]*spr->yrepeat)<<2);
if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z;
if (picanm[spr->picnum].yofs) daz -= (picanm[spr->picnum].yofs*spr->yrepeat<<2);
daz = spr->z + spriteheightofs(j, &k, 1);
daz2 = daz-k;
daz += ceildist; daz2 -= flordist;
if (((pos->z) < daz) && ((pos->z) > daz2))
@ -12572,9 +12553,7 @@ int32_t pushmove(vec3_t *vect, int16_t *sectnum,
t = (spr->clipdist<<2)+walldist;
if ((klabs(dax) < t) && (klabs(day) < t))
{
t = ((tilesizy[spr->picnum]*spr->yrepeat)<<2);
if (spr->cstat&128) daz = spr->z+(t>>1); else daz = spr->z;
if (picanm[spr->picnum].yofs) daz -= ((int32_t)picanm[spr->picnum].yofs*spr->yrepeat<<2);
daz = spr->z + spriteheightofs(i, &t, 1);
if (((vect->z) < daz+ceildist) && ((vect->z) > daz-t-flordist))
{
t = (spr->clipdist<<2)+walldist;
@ -13223,12 +13202,8 @@ restart_grand:
k = walldist+(spr->clipdist<<2)+1;
if ((klabs(x1-pos->x) <= k) && (klabs(y1-pos->y) <= k))
{
daz = spr->z;
k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1);
if (cstat&128) daz += k;
if (picanm[spr->picnum].yofs)
daz -= (picanm[spr->picnum].yofs*spr->yrepeat<<2);
daz2 = daz - (k<<1);
daz = spr->z + spriteheightofs(j, &k, 1);
daz2 = daz - k;
clipyou = 1;
}
break;
@ -13243,11 +13218,8 @@ restart_grand:
y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l);
if (clipinsideboxline(pos->x,pos->y,x1,y1,x2,y2,walldist+1) != 0)
{
daz = spr->z; k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1);
if (cstat&128) daz += k;
if (picanm[spr->picnum].yofs)
daz -= (picanm[spr->picnum].yofs*spr->yrepeat<<2);
daz2 = daz-(k<<1);
daz = spr->z + spriteheightofs(j, &k, 1);
daz2 = daz-k;
clipyou = 1;
}
break;