Commence renderer floatification

This commit is contained in:
Randy Heit 2016-04-14 12:40:14 -05:00
commit ded3f92452
17 changed files with 672 additions and 733 deletions

View file

@ -113,24 +113,22 @@ fixed_t r_SkyVisibility;
fixed_t GlobVis;
fixed_t viewingrangerecip;
fixed_t FocalLengthX;
fixed_t FocalLengthY;
float FocalLengthXfloat;
double FocalLengthX;
double FocalLengthY;
FDynamicColormap*basecolormap; // [RH] colormap currently drawing with
int fixedlightlev;
lighttable_t *fixedcolormap;
FSpecialColormap *realfixedcolormap;
float WallTMapScale2;
double WallTMapScale2;
bool bRenderingToCanvas; // [RH] True if rendering to a special canvas
fixed_t globaluclip, globaldclip;
fixed_t centerxfrac;
fixed_t centeryfrac;
fixed_t yaspectmul;
fixed_t baseyaspectmul; // yaspectmul without a forced aspect ratio
float iyaspectmulfloat;
fixed_t InvZtoScale;
double globaluclip, globaldclip;
double CenterX, CenterY;
double YaspectMul;
double BaseYaspectMul; // yaspectmul without a forced aspect ratio
double IYaspectMul;
double InvZtoScale;
// just for profiling purposes
int linecount;
@ -188,9 +186,8 @@ static inline int viewangletox(int i)
}
else
{
int t = FixedMul(finetangent[i], FocalLengthX);
t = (centerxfrac - t + FRACUNIT-1) >> FRACBITS;
return clamp(t, -1, viewwidth+1);
double t = FIXED2DBL(finetangent[i]) * FocalLengthX;
return clamp(xs_CeilToInt(CenterX - t), -1, viewwidth+1);
}
}
@ -205,9 +202,8 @@ void R_InitTextureMapping ()
int i, x;
// Calc focallength so FieldOfView fineangles covers viewwidth.
FocalLengthX = FixedDiv (centerxfrac, FocalTangent);
FocalLengthY = Scale (centerxfrac, yaspectmul, FocalTangent);
FocalLengthXfloat = (float)FocalLengthX / 65536.f;
FocalLengthX = CenterX / FocalTangent;
FocalLengthY = FocalLengthX * YaspectMul;
// This is 1/FocalTangent before the widescreen extension of FOV.
viewingrangerecip = DivScale32(1, finetangent[FINEANGLES/4+(FieldOfView/2)]);
@ -224,13 +220,13 @@ void R_InitTextureMapping ()
// the drawn sky texture.
// The remaining arcs are done with tantoangle instead.
const int t1 = MAX<int>(centerx - (FocalLengthX >> FRACBITS), 0);
const int t2 = MIN<int>(centerx + (FocalLengthX >> FRACBITS), viewwidth);
const fixed_t dfocus = FocalLengthX >> DBITS;
const int t1 = MAX(int(CenterX - FocalLengthX), 0);
const int t2 = MIN(int(CenterX + FocalLengthX), viewwidth);
const fixed_t dfocus = FLOAT2FIXED(FocalLengthX) >> DBITS;
for (i = 0, x = t2; x >= t1; --x)
{
while(viewangletox(i) > x)
while (viewangletox(i) > x)
{
++i;
}
@ -278,8 +274,8 @@ void R_SetVisibility (float vis)
else
r_WallVisibility = r_BaseVisibility;
r_WallVisibility = FixedMul (Scale (InvZtoScale, SCREENWIDTH*BaseRatioSizes[WidescreenRatio][1],
viewwidth*SCREENHEIGHT*3), FixedMul (r_WallVisibility, FocalTangent));
r_WallVisibility = FixedMul (FLOAT2FIXED(InvZtoScale * SCREENWIDTH*BaseRatioSizes[WidescreenRatio][1] /
(viewwidth*SCREENHEIGHT*3)), xs_ToInt(r_WallVisibility * FocalTangent));
// Prevent overflow on floors/ceilings. Note that the calculation of
// MaxVisForFloor means that planes less than two units from the player's
@ -292,7 +288,7 @@ void R_SetVisibility (float vis)
else
r_FloorVisibility = r_BaseVisibility;
r_FloorVisibility = Scale (160*FRACUNIT, r_FloorVisibility, FocalLengthY);
r_FloorVisibility = xs_ToInt(160.0 * r_FloorVisibility / FocalLengthY);
r_TiltVisibility = vis * (float)FocalTangent * (16.f * 320.f) / (float)viewwidth;
r_SpriteVisibility = r_WallVisibility;
@ -359,8 +355,8 @@ void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight,
halfviewwidth = (viewwidth >> 1) - 1;
lastcenteryfrac = 1<<30;
centerxfrac = centerx<<FRACBITS;
centeryfrac = centery<<FRACBITS;
CenterX = centerx;
CenterY = centery;
virtwidth = virtwidth2 = fullWidth;
virtheight = virtheight2 = fullHeight;
@ -383,27 +379,27 @@ void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight,
virtwidth = virtwidth * BaseRatioSizes[WidescreenRatio][3] / 48;
}
baseyaspectmul = Scale(320 << FRACBITS, virtheight2, r_Yaspect * virtwidth2);
yaspectmul = Scale ((320<<FRACBITS), virtheight, r_Yaspect * virtwidth);
iyaspectmulfloat = (float)virtwidth * r_Yaspect / 320.f / (float)virtheight;
InvZtoScale = yaspectmul * centerx;
BaseYaspectMul = 320.0 * virtheight2 / (r_Yaspect * virtwidth2);
YaspectMul = 320.0 * virtheight / (r_Yaspect * virtwidth);
IYaspectMul = (double)virtwidth * r_Yaspect / 320.0 / virtheight;
InvZtoScale = YaspectMul * CenterX;
WallTMapScale2 = iyaspectmulfloat * 64.f / (float)centerx;
WallTMapScale2 = IYaspectMul * (1 << 18) / CenterX;
// psprite scales
pspritexscale = (centerxwide << FRACBITS) / 160;
pspriteyscale = FixedMul (pspritexscale, yaspectmul);
pspritexiscale = FixedDiv (FRACUNIT, pspritexscale);
pspriteyscale = FLOAT2FIXED(pspritexscale * YaspectMul);
pspritexiscale = FixedDiv(FRACUNIT, pspritexscale);
// thing clipping
clearbufshort (screenheightarray, viewwidth, (short)viewheight);
R_InitTextureMapping ();
MaxVisForWall = FixedMul (Scale (InvZtoScale, SCREENWIDTH*r_Yaspect,
viewwidth*SCREENHEIGHT), FocalTangent);
MaxVisForWall = FLOAT2FIXED((InvZtoScale * (SCREENWIDTH*r_Yaspect) /
(viewwidth*SCREENHEIGHT * FocalTangent)));
MaxVisForWall = FixedDiv (0x7fff0000, MaxVisForWall);
MaxVisForFloor = Scale (FixedDiv (0x7fff0000, viewheight<<(FRACBITS-2)), FocalLengthY, 160*FRACUNIT);
MaxVisForFloor = int(0x7fff0000 / (viewheight * FocalLengthY / 160));
// Reset r_*Visibility vars
R_SetVisibility (R_GetVisibility ());
@ -489,10 +485,8 @@ static void R_ShutdownRenderer()
void R_CopyStackedViewParameters()
{
stacked_viewx = viewx;
stacked_viewy = viewy;
stacked_viewz = viewz;
stacked_angle = viewangle;
stacked_viewpos = ViewPos;
stacked_angle = ViewAngle;
stacked_extralight = extralight;
stacked_visibility = R_GetVisibility();
}
@ -552,58 +546,59 @@ void R_SetupColormap(player_t *player)
void R_SetupFreelook()
{
{
fixed_t dy;
double dy;
if (camera != NULL)
{
dy = FixedMul (FocalLengthY, finetangent[(ANGLE_90-viewpitch)>>ANGLETOFINESHIFT]);
dy = FocalLengthY * (-ViewPitch).Tan();
}
else
{
dy = 0;
}
centeryfrac = (viewheight << (FRACBITS-1)) + dy;
centery = centeryfrac >> FRACBITS;
globaluclip = FixedDiv (-centeryfrac, InvZtoScale);
globaldclip = FixedDiv ((viewheight<<FRACBITS)-centeryfrac, InvZtoScale);
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;
fixed_t focus = FocalLengthY;
fixed_t den;
float focus = float(FocalLengthY);
float den;
float cy = float(CenterY);
if (i < centery)
{
den = centeryfrac - (i << FRACBITS) - FRACUNIT/2;
den = cy - i - 0.5f;
if (e <= centery)
{
do {
yslope[i] = FixedDiv (focus, den);
den -= FRACUNIT;
yslope[i] = FLOAT2FIXED(focus / den);
den -= 1;
} while (++i < e);
}
else
{
do {
yslope[i] = FixedDiv (focus, den);
den -= FRACUNIT;
yslope[i] = FLOAT2FIXED(focus / den);
den -= 1;
} while (++i < centery);
den = (i << FRACBITS) - centeryfrac + FRACUNIT/2;
den = i - cy + 0.5f;
do {
yslope[i] = FixedDiv (focus, den);
den += FRACUNIT;
yslope[i] = FLOAT2FIXED(focus / den);
den += 1;
} while (++i < e);
}
}
else
{
den = (i << FRACBITS) - centeryfrac + FRACUNIT/2;
den = i - cy + 0.5f;
do {
yslope[i] = FixedDiv (focus, den);
den += FRACUNIT;
yslope[i] = FLOAT2FIXED(focus / den);
den += 1;
} while (++i < e);
}
}
@ -688,10 +683,8 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
return;
}
angle_t startang = viewangle;
fixed_t startx = viewx;
fixed_t starty = viewy;
fixed_t startz = viewz;
DAngle startang = ViewAngle;
DVector3 startpos = ViewPos;
DVector3 savedpath[2] = { ViewPath[0], ViewPath[1] };
ActorRenderFlags savedvisibility = camera? camera->renderflags & RF_INVISIBLE : ActorRenderFlags::FromInt(0);
@ -707,44 +700,40 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
// Reflect the current view behind the mirror.
if (pds->src->Delta().X == 0)
{ // vertical mirror
viewx = v1->fixX() - startx + v1->fixX();
ViewPos.X = v1->fX() - startpos.X + v1->fX();
}
else if (pds->src->Delta().Y == 0)
{ // horizontal mirror
viewy = v1->fixY() - starty + v1->fixY();
ViewPos.Y = v1->fY() - startpos.Y + v1->fY();
}
else
{ // any mirror--use floats to avoid integer overflow
{ // any mirror
vertex_t *v2 = pds->src->v2;
double dx = v2->fX() - v1->fX();
double dy = v2->fY() - v1->fY();
double x1 = v1->fX();
double y1 = v1->fY();
double x = FIXED2DBL(startx);
double y = FIXED2DBL(starty);
double x = startpos.X;
double y = startpos.Y;
// the above two cases catch len == 0
double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy);
viewx = FLOAT2FIXED((x1 + r * dx)*2 - x);
viewy = FLOAT2FIXED((y1 + r * dy)*2 - y);
ViewPos.X = (x1 + r * dx)*2 - x;
ViewPos.Y = (y1 + r * dy)*2 - y;
}
viewangle = pds->src->Delta().Angle().BAMs() - startang;
ViewAngle = pds->src->Delta().Angle() - startang;
}
else
{
DVector3 view(FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz));
DAngle va = ANGLE2DBL(viewangle);
DVector3 view(ViewPos);
DAngle va = ViewAngle;
P_TranslatePortalXY(pds->src, view.X, view.Y);
P_TranslatePortalZ(pds->src, view.Z);
P_TranslatePortalAngle(pds->src, va);
P_TranslatePortalXY(pds->src, ViewPath[0].X, ViewPath[0].Y);
P_TranslatePortalXY(pds->src, ViewPath[1].X, ViewPath[1].Y);
viewx = FLOAT2FIXED(view.X);
viewy = FLOAT2FIXED(view.Y);
viewz = FLOAT2FIXED(view.Z);
viewangle = va.BAMs();
if (!r_showviewer && camera)
{
@ -760,15 +749,15 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
}
}
}
ViewPos = view;
ViewAngle = va;
}
ViewAngle = AngleToFloat(viewangle);
ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) };
viewsin = finesine[viewangle>>ANGLETOFINESHIFT];
viewcos = finecosine[viewangle>>ANGLETOFINESHIFT];
ViewSin = ViewAngle.Sin();
ViewCos = ViewAngle.Cos();
viewtansin = FixedMul (FocalTangent, viewsin);
viewtancos = FixedMul (FocalTangent, viewcos);
ViewTanSin = FocalTangent * ViewSin;
ViewTanCos = FocalTangent * ViewCos;
R_CopyStackedViewParameters();
@ -809,7 +798,7 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
R_DrawPortals ();
PlaneCycles.Unclock();
fixed_t vzp = viewz;
double vzp = ViewPos.Z;
int prevuniq = CurrentPortalUniq;
// depth check is in another place right now
@ -838,14 +827,10 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
CurrentPortal = prevpds;
MirrorFlags = prevmf;
viewangle = startang;
viewx = startx;
viewy = starty;
viewz = startz;
ViewAngle = startang;
ViewPos = startpos;
ViewPath[0] = savedpath[0];
ViewPath[1] = savedpath[1];
ViewAngle = AngleToFloat(viewangle);
ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) };
}
//==========================================================================