Keep values in floats longer for visplane drawing

This commit is contained in:
Randy Heit 2016-04-28 21:07:58 -05:00
parent 96228ca15f
commit 8f3921190f
3 changed files with 77 additions and 67 deletions

View file

@ -501,63 +501,61 @@ void R_SetupColormap(player_t *player)
void R_SetupFreelook() void R_SetupFreelook()
{ {
double dy;
if (camera != NULL)
{ {
double dy; dy = FocalLengthY * (-ViewPitch).Tan();
}
else
{
dy = 0;
}
if (camera != NULL) CenterY = (viewheight / 2.0) + dy;
centery = xs_ToInt(CenterY);
globaluclip = -CenterY / InvZtoScale;
globaldclip = (viewheight - CenterY) / InvZtoScale;
//centeryfrac &= 0xffff0000;
int e, i;
i = 0;
e = viewheight;
float focus = float(FocalLengthY);
float den;
float cy = float(CenterY);
if (i < centery)
{
den = cy - i - 0.5f;
if (e <= centery)
{ {
dy = FocalLengthY * (-ViewPitch).Tan(); do {
} yslope[i] = focus / den;
else den -= 1;
{ } while (++i < e);
dy = 0;
}
CenterY = (viewheight / 2.0) + dy;
centery = xs_ToInt(CenterY);
globaluclip = -CenterY / InvZtoScale;
globaldclip = (viewheight - CenterY) / InvZtoScale;
//centeryfrac &= 0xffff0000;
int e, i;
i = 0;
e = viewheight;
float focus = float(FocalLengthY);
float den;
float cy = float(CenterY);
if (i < centery)
{
den = cy - i - 0.5f;
if (e <= centery)
{
do {
yslope[i] = FLOAT2FIXED(focus / den);
den -= 1;
} while (++i < e);
}
else
{
do {
yslope[i] = FLOAT2FIXED(focus / den);
den -= 1;
} while (++i < centery);
den = i - cy + 0.5f;
do {
yslope[i] = FLOAT2FIXED(focus / den);
den += 1;
} while (++i < e);
}
} }
else else
{ {
do {
yslope[i] = focus / den;
den -= 1;
} while (++i < centery);
den = i - cy + 0.5f; den = i - cy + 0.5f;
do { do {
yslope[i] = FLOAT2FIXED(focus / den); yslope[i] = focus / den;
den += 1; den += 1;
} while (++i < e); } while (++i < e);
} }
} }
else
{
den = i - cy + 0.5f;
do {
yslope[i] = focus / den;
den += 1;
} while (++i < e);
}
} }
//========================================================================== //==========================================================================

View file

@ -141,10 +141,10 @@ fixed_t pviewx, pviewy;
void R_DrawTiltedPlane_ASM (int y, int x1); void R_DrawTiltedPlane_ASM (int y, int x1);
} }
fixed_t yslope[MAXHEIGHT]; float yslope[MAXHEIGHT];
static fixed_t xscale, yscale; static fixed_t xscale, yscale;
static DWORD xstepscale, ystepscale; static double xstepscale, ystepscale;
static DWORD basexfrac, baseyfrac; static double basexfrac, baseyfrac;
#ifdef X86_ASM #ifdef X86_ASM
extern "C" void R_SetSpanSource_ASM (const BYTE *flat); extern "C" void R_SetSpanSource_ASM (const BYTE *flat);
@ -205,7 +205,7 @@ void R_DeinitPlanes ()
void R_MapPlane (int y, int x1) void R_MapPlane (int y, int x1)
{ {
int x2 = spanend[y]; int x2 = spanend[y];
fixed_t distance; double distance;
#ifdef RANGECHECK #ifdef RANGECHECK
if (x2 < x1 || x1<0 || x2>=viewwidth || (unsigned)y>=(unsigned)viewheight) if (x2 < x1 || x1<0 || x2>=viewwidth || (unsigned)y>=(unsigned)viewheight)
@ -217,12 +217,12 @@ void R_MapPlane (int y, int x1)
// [RH] Notice that I dumped the caching scheme used by Doom. // [RH] Notice that I dumped the caching scheme used by Doom.
// It did not offer any appreciable speedup. // It did not offer any appreciable speedup.
distance = xs_ToInt(planeheight * yslope[y]); distance = planeheight * yslope[y];
ds_xstep = FixedMul (distance, xstepscale); ds_xstep = xs_ToFixed(32-ds_xbits, distance * xstepscale);
ds_ystep = FixedMul (distance, ystepscale); ds_ystep = xs_ToFixed(32-ds_ybits, distance * ystepscale);
ds_xfrac = FixedMul (distance, basexfrac) + pviewx; ds_xfrac = xs_ToFixed(32-ds_xbits, distance * basexfrac) + pviewx;
ds_yfrac = FixedMul (distance, baseyfrac) + pviewy; ds_yfrac = xs_ToFixed(32-ds_ybits, distance * baseyfrac) + pviewy;
if (plane_shade) if (plane_shade)
{ {
@ -1495,12 +1495,15 @@ void R_DrawNormalPlane (visplane_t *pl, double _xscale, double _yscale, fixed_t
return; return;
} }
DAngle planeang = pl->xform.Angle + pl->xform.baseAngle; double planeang = (pl->xform.Angle + pl->xform.baseAngle).Radians();
double xstep, ystep, leftxfrac, leftyfrac, rightxfrac, rightyfrac;
double x;
xscale = xs_ToFixed(32 - ds_xbits, _xscale); xscale = xs_ToFixed(32 - ds_xbits, _xscale);
yscale = xs_ToFixed(32 - ds_ybits, _yscale); yscale = xs_ToFixed(32 - ds_ybits, _yscale);
if (planeang != 0) if (planeang != 0)
{ {
double cosine = cos(planeang.Radians()), sine = sin(planeang.Radians()); double cosine = cos(planeang), sine = sin(planeang);
pviewx = FLOAT2FIXED(pl->xform.xOffs + ViewPos.X * cosine - ViewPos.Y * sine); pviewx = FLOAT2FIXED(pl->xform.xOffs + ViewPos.X * cosine - ViewPos.Y * sine);
pviewy = FLOAT2FIXED(pl->xform.yOffs - ViewPos.X * sine - ViewPos.Y * cosine); pviewy = FLOAT2FIXED(pl->xform.yOffs - ViewPos.X * sine - ViewPos.Y * cosine);
} }
@ -1514,23 +1517,32 @@ void R_DrawNormalPlane (visplane_t *pl, double _xscale, double _yscale, fixed_t
pviewy = FixedMul (yscale, pviewy); pviewy = FixedMul (yscale, pviewy);
// left to right mapping // left to right mapping
planeang = ViewAngle - 90 + planeang; planeang += (ViewAngle - 90).Radians();
// Scale will be unit scale at FocalLengthX (normally SCREENWIDTH/2) distance // Scale will be unit scale at FocalLengthX (normally SCREENWIDTH/2) distance
xstepscale = xs_RoundToInt(xscale * cos(planeang.Radians()) / FocalLengthX); xstep = cos(planeang) / FocalLengthX;
ystepscale = xs_RoundToInt(yscale * -sin(planeang.Radians()) / FocalLengthX); ystep = -sin(planeang) / FocalLengthX;
// [RH] flip for mirrors // [RH] flip for mirrors
if (MirrorFlags & RF_XFLIP) if (MirrorFlags & RF_XFLIP)
{ {
xstepscale = (DWORD)(-(SDWORD)xstepscale); xstep = -xstep;
ystepscale = (DWORD)(-(SDWORD)ystepscale); ystep = -ystep;
} }
int x = pl->right - centerx; planeang += M_PI/2;
planeang += 90; double cosine = cos(planeang), sine = -sin(planeang);
basexfrac = xs_RoundToInt(xscale * cos(planeang.Radians())) + x*xstepscale; x = pl->right - centerx - 0.5;
baseyfrac = xs_RoundToInt(yscale * -sin(planeang.Radians())) + x*ystepscale; rightxfrac = _xscale * (cosine + x * xstep);
rightyfrac = _yscale * (sine + x * ystep);
x = pl->left - centerx - 0.5;
leftxfrac = _xscale * (cosine + x * xstep);
leftyfrac = _yscale * (sine + x * ystep);
basexfrac = rightxfrac;
baseyfrac = rightyfrac;
xstepscale = (rightxfrac - leftxfrac) / (pl->right - pl->left);
ystepscale = (rightyfrac - leftyfrac) / (pl->right - pl->left);
planeheight = fabs(pl->height.Zat0() - ViewPos.Z); planeheight = fabs(pl->height.Zat0() - ViewPos.Z);

View file

@ -80,7 +80,7 @@ extern planefunction_t ceilingfunc_t;
extern short floorclip[MAXWIDTH]; extern short floorclip[MAXWIDTH];
extern short ceilingclip[MAXWIDTH]; extern short ceilingclip[MAXWIDTH];
extern fixed_t yslope[MAXHEIGHT]; extern float yslope[MAXHEIGHT];
void R_InitPlanes (); void R_InitPlanes ();
void R_DeinitPlanes (); void R_DeinitPlanes ();