mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-02-17 17:41:23 +00:00
Store FTransform in visplanes instead of converting to fixed_t
This commit is contained in:
parent
ac69ed3361
commit
31d842a894
2 changed files with 55 additions and 80 deletions
122
src/r_plane.cpp
122
src/r_plane.cpp
|
@ -582,29 +582,21 @@ static visplane_t *new_visplane (unsigned hash)
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive,
|
visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightlevel, double Alpha, bool additive,
|
||||||
const FTransform &xform,
|
const FTransform &xxform,
|
||||||
int sky, FSectorPortal *portal)
|
int sky, FSectorPortal *portal)
|
||||||
{
|
{
|
||||||
secplane_t plane;
|
secplane_t plane;
|
||||||
visplane_t *check;
|
visplane_t *check;
|
||||||
unsigned hash; // killough
|
unsigned hash; // killough
|
||||||
bool isskybox;
|
bool isskybox;
|
||||||
fixed_t xoffs = FLOAT2FIXED(xform.xOffs);
|
const FTransform *xform = &xxform;
|
||||||
fixed_t yoffs = FLOAT2FIXED(xform.yOffs + xform.baseyOffs);
|
|
||||||
fixed_t xscale = FLOAT2FIXED(xform.xScale);
|
|
||||||
fixed_t yscale = FLOAT2FIXED(xform.yScale);
|
|
||||||
fixed_t alpha = FLOAT2FIXED(Alpha);
|
fixed_t alpha = FLOAT2FIXED(Alpha);
|
||||||
angle_t angle = (xform.Angle + xform.baseAngle).BAMs();
|
//angle_t angle = (xform.Angle + xform.baseAngle).BAMs();
|
||||||
|
|
||||||
if (picnum == skyflatnum) // killough 10/98
|
if (picnum == skyflatnum) // killough 10/98
|
||||||
{ // most skies map together
|
{ // most skies map together
|
||||||
lightlevel = 0;
|
lightlevel = 0;
|
||||||
xoffs = 0;
|
xform = NULL;
|
||||||
yoffs = 0;
|
|
||||||
xscale = 0;
|
|
||||||
yscale = 0;
|
|
||||||
angle = 0;
|
|
||||||
alpha = 0;
|
|
||||||
additive = false;
|
additive = false;
|
||||||
// [RH] Map floor skies and ceiling skies to separate visplanes. This isn't
|
// [RH] Map floor skies and ceiling skies to separate visplanes. This isn't
|
||||||
// always necessary, but it is needed if a floor and ceiling sky are in the
|
// always necessary, but it is needed if a floor and ceiling sky are in the
|
||||||
|
@ -656,13 +648,10 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl
|
||||||
(plane == check->height &&
|
(plane == check->height &&
|
||||||
picnum == check->picnum &&
|
picnum == check->picnum &&
|
||||||
lightlevel == check->lightlevel &&
|
lightlevel == check->lightlevel &&
|
||||||
|
|
||||||
xoffs == check->xoffs && // killough 2/28/98: Add offset checks
|
|
||||||
yoffs == check->yoffs &&
|
|
||||||
basecolormap == check->colormap && // [RH] Add more checks
|
basecolormap == check->colormap && // [RH] Add more checks
|
||||||
xscale == check->xscale &&
|
|
||||||
yscale == check->yscale &&
|
(xform == check->xform ||
|
||||||
angle == check->angle
|
(xform != NULL && check->xform != NULL && *xform == *check->xform))
|
||||||
)
|
)
|
||||||
) &&
|
) &&
|
||||||
check->viewangle == stacked_angle
|
check->viewangle == stacked_angle
|
||||||
|
@ -683,12 +672,9 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl
|
||||||
if (plane == check->height &&
|
if (plane == check->height &&
|
||||||
picnum == check->picnum &&
|
picnum == check->picnum &&
|
||||||
lightlevel == check->lightlevel &&
|
lightlevel == check->lightlevel &&
|
||||||
xoffs == check->xoffs && // killough 2/28/98: Add offset checks
|
|
||||||
yoffs == check->yoffs &&
|
|
||||||
basecolormap == check->colormap && // [RH] Add more checks
|
basecolormap == check->colormap && // [RH] Add more checks
|
||||||
xscale == check->xscale &&
|
(xform == check->xform ||
|
||||||
yscale == check->yscale &&
|
(xform != NULL && check->xform != NULL && *xform == *check->xform)) &&
|
||||||
angle == check->angle &&
|
|
||||||
sky == check->sky &&
|
sky == check->sky &&
|
||||||
CurrentPortalUniq == check->CurrentPortalUniq &&
|
CurrentPortalUniq == check->CurrentPortalUniq &&
|
||||||
MirrorFlags == check->MirrorFlags &&
|
MirrorFlags == check->MirrorFlags &&
|
||||||
|
@ -705,11 +691,7 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl
|
||||||
check->height = plane;
|
check->height = plane;
|
||||||
check->picnum = picnum;
|
check->picnum = picnum;
|
||||||
check->lightlevel = lightlevel;
|
check->lightlevel = lightlevel;
|
||||||
check->xoffs = xoffs; // killough 2/28/98: Save offsets
|
check->xform = xform;
|
||||||
check->yoffs = yoffs;
|
|
||||||
check->xscale = xscale;
|
|
||||||
check->yscale = yscale;
|
|
||||||
check->angle = angle;
|
|
||||||
check->colormap = basecolormap; // [RH] Save colormap
|
check->colormap = basecolormap; // [RH] Save colormap
|
||||||
check->sky = sky;
|
check->sky = sky;
|
||||||
check->portal = portal;
|
check->portal = portal;
|
||||||
|
@ -794,11 +776,7 @@ visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop)
|
||||||
new_pl->height = pl->height;
|
new_pl->height = pl->height;
|
||||||
new_pl->picnum = pl->picnum;
|
new_pl->picnum = pl->picnum;
|
||||||
new_pl->lightlevel = pl->lightlevel;
|
new_pl->lightlevel = pl->lightlevel;
|
||||||
new_pl->xoffs = pl->xoffs; // killough 2/28/98
|
new_pl->xform = pl->xform;
|
||||||
new_pl->yoffs = pl->yoffs;
|
|
||||||
new_pl->xscale = pl->xscale; // [RH] copy these, too
|
|
||||||
new_pl->yscale = pl->yscale;
|
|
||||||
new_pl->angle = pl->angle;
|
|
||||||
new_pl->colormap = pl->colormap;
|
new_pl->colormap = pl->colormap;
|
||||||
new_pl->portal = pl->portal;
|
new_pl->portal = pl->portal;
|
||||||
new_pl->extralight = pl->extralight;
|
new_pl->extralight = pl->extralight;
|
||||||
|
@ -1117,8 +1095,8 @@ void R_DrawSinglePlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
|
||||||
masked = false;
|
masked = false;
|
||||||
}
|
}
|
||||||
R_SetupSpanBits(tex);
|
R_SetupSpanBits(tex);
|
||||||
pl->xscale = fixed_t(pl->xscale * tex->Scale.X);
|
double xscale = pl->xform->xScale * tex->Scale.X;
|
||||||
pl->yscale = fixed_t(pl->yscale * tex->Scale.Y);
|
double yscale = pl->xform->yScale * tex->Scale.Y;
|
||||||
ds_source = tex->GetPixels ();
|
ds_source = tex->GetPixels ();
|
||||||
|
|
||||||
basecolormap = pl->colormap;
|
basecolormap = pl->colormap;
|
||||||
|
@ -1126,11 +1104,11 @@ void R_DrawSinglePlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
|
||||||
|
|
||||||
if (r_drawflat || (!pl->height.isSlope() && !tilt))
|
if (r_drawflat || (!pl->height.isSlope() && !tilt))
|
||||||
{
|
{
|
||||||
R_DrawNormalPlane (pl, alpha, additive, masked);
|
R_DrawNormalPlane(pl, xscale, yscale, alpha, additive, masked);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
R_DrawTiltedPlane (pl, alpha, additive, masked);
|
R_DrawTiltedPlane(pl, xscale, yscale, alpha, additive, masked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NetUpdate ();
|
NetUpdate ();
|
||||||
|
@ -1502,7 +1480,7 @@ void R_DrawSkyPlane (visplane_t *pl)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool masked)
|
void R_DrawNormalPlane (visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked)
|
||||||
{
|
{
|
||||||
#ifdef X86_ASM
|
#ifdef X86_ASM
|
||||||
if (ds_source != ds_cursource)
|
if (ds_source != ds_cursource)
|
||||||
|
@ -1516,31 +1494,29 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
angle_t planeang = pl->angle;
|
DAngle planeang = pl->xform->Angle + pl->xform->baseAngle;
|
||||||
xscale = pl->xscale << (16 - ds_xbits);
|
xscale = xs_ToFixed(32 - ds_xbits, _xscale);
|
||||||
yscale = pl->yscale << (16 - ds_ybits);
|
yscale = xs_ToFixed(32 - ds_ybits, _yscale);
|
||||||
if (planeang != 0)
|
if (planeang != 0)
|
||||||
{
|
{
|
||||||
double rad = planeang * (M_PI / ANGLE_180);
|
double cosine = planeang.Cos(), sine = planeang.Sin();
|
||||||
double cosine = cos(rad), sine = sin(rad);
|
pviewx = FLOAT2FIXED(pl->xform->xOffs + ViewPos.X * cosine - ViewPos.Y * sine);
|
||||||
|
pviewy = FLOAT2FIXED(pl->xform->yOffs - ViewPos.X * sine - ViewPos.Y * cosine);
|
||||||
pviewx = xs_RoundToInt(pl->xoffs + FLOAT2FIXED(ViewPos.X * cosine - ViewPos.Y * sine));
|
|
||||||
pviewy = xs_RoundToInt(pl->yoffs - FLOAT2FIXED(ViewPos.X * sine - ViewPos.Y * cosine));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pviewx = pl->xoffs + FLOAT2FIXED(ViewPos.X);
|
pviewx = FLOAT2FIXED(pl->xform->xOffs + ViewPos.X);
|
||||||
pviewy = pl->yoffs - FLOAT2FIXED(ViewPos.Y);
|
pviewy = FLOAT2FIXED(pl->xform->yOffs - ViewPos.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
pviewx = FixedMul (xscale, pviewx);
|
pviewx = FixedMul (xscale, pviewx);
|
||||||
pviewy = FixedMul (yscale, pviewy);
|
pviewy = FixedMul (yscale, pviewy);
|
||||||
|
|
||||||
// left to right mapping
|
// left to right mapping
|
||||||
planeang = (ViewAngle.BAMs() - ANG90 + planeang) >> ANGLETOFINESHIFT;
|
planeang = ViewAngle - 90 + planeang;
|
||||||
// Scale will be unit scale at FocalLengthX (normally SCREENWIDTH/2) distance
|
// Scale will be unit scale at FocalLengthX (normally SCREENWIDTH/2) distance
|
||||||
xstepscale = fixed_t(FixedMul(xscale, finecosine[planeang]) / FocalLengthX);
|
xstepscale = xs_RoundToInt(xscale * planeang.Cos() / FocalLengthX);
|
||||||
ystepscale = fixed_t(FixedMul(yscale, -finesine[planeang]) / FocalLengthX);
|
ystepscale = xs_RoundToInt(yscale * -planeang.Sin() / FocalLengthX);
|
||||||
|
|
||||||
// [RH] flip for mirrors
|
// [RH] flip for mirrors
|
||||||
if (MirrorFlags & RF_XFLIP)
|
if (MirrorFlags & RF_XFLIP)
|
||||||
|
@ -1550,9 +1526,9 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = pl->right - halfviewwidth - 1;
|
int x = pl->right - halfviewwidth - 1;
|
||||||
planeang = (planeang + (ANG90 >> ANGLETOFINESHIFT)) & FINEMASK;
|
planeang += 90;
|
||||||
basexfrac = FixedMul (xscale, finecosine[planeang]) + x*xstepscale;
|
basexfrac = xs_RoundToInt(xscale * planeang.Cos()) + x*xstepscale;
|
||||||
baseyfrac = FixedMul (yscale, -finesine[planeang]) + x*ystepscale;
|
baseyfrac = xs_RoundToInt(yscale * -planeang.Sin()) + x*ystepscale;
|
||||||
|
|
||||||
planeheight = fabs(pl->height.Zat0() - ViewPos.Z);
|
planeheight = fabs(pl->height.Zat0() - ViewPos.Z);
|
||||||
|
|
||||||
|
@ -1620,7 +1596,7 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool masked)
|
void R_DrawTiltedPlane (visplane_t *pl, double _xscale, double _yscale, fixed_t alpha, bool additive, bool masked)
|
||||||
{
|
{
|
||||||
static const float ifloatpow2[16] =
|
static const float ifloatpow2[16] =
|
||||||
{
|
{
|
||||||
|
@ -1634,7 +1610,7 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
|
||||||
double lxscale, lyscale;
|
double lxscale, lyscale;
|
||||||
double xscale, yscale;
|
double xscale, yscale;
|
||||||
FVector3 p, m, n;
|
FVector3 p, m, n;
|
||||||
double ang;
|
DAngle ang;
|
||||||
double zeroheight;
|
double zeroheight;
|
||||||
|
|
||||||
if (alpha <= 0)
|
if (alpha <= 0)
|
||||||
|
@ -1642,44 +1618,44 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lxscale = FIXED2DBL(pl->xscale) * ifloatpow2[ds_xbits];
|
lxscale = _xscale * ifloatpow2[ds_xbits];
|
||||||
lyscale = FIXED2DBL(pl->yscale) * ifloatpow2[ds_ybits];
|
lyscale = _yscale * ifloatpow2[ds_ybits];
|
||||||
xscale = 64.f / lxscale;
|
xscale = 64.f / lxscale;
|
||||||
yscale = 64.f / lyscale;
|
yscale = 64.f / lyscale;
|
||||||
zeroheight = pl->height.ZatPoint(ViewPos);
|
zeroheight = pl->height.ZatPoint(ViewPos);
|
||||||
|
|
||||||
pviewx = MulScale (pl->xoffs, pl->xscale, ds_xbits);
|
pviewx = xs_ToFixed(32 - ds_xbits, pl->xform->xOffs * pl->xform->xScale);
|
||||||
pviewy = MulScale (pl->yoffs, pl->yscale, ds_ybits);
|
pviewy = xs_ToFixed(32 - ds_ybits, pl->xform->yOffs * pl->xform->yScale);
|
||||||
|
|
||||||
// p is the texture origin in view space
|
// p is the texture origin in view space
|
||||||
// Don't add in the offsets at this stage, because doing so can result in
|
// Don't add in the offsets at this stage, because doing so can result in
|
||||||
// errors if the flat is rotated.
|
// errors if the flat is rotated.
|
||||||
ang = (DAngle(270.) - ViewAngle).Radians();
|
ang = DAngle(270.) - ViewAngle;
|
||||||
p[0] = ViewPos.X * cos(ang) - ViewPos.Y * sin(ang);
|
p[0] = ViewPos.X * ang.Cos() - ViewPos.Y * ang.Sin();
|
||||||
p[2] = ViewPos.X * sin(ang) + ViewPos.Y * cos(ang);
|
p[2] = ViewPos.X * ang.Sin() + ViewPos.Y * ang.Cos();
|
||||||
p[1] = pl->height.ZatPoint(0.0, 0.0) - ViewPos.Z;
|
p[1] = pl->height.ZatPoint(0.0, 0.0) - ViewPos.Z;
|
||||||
|
|
||||||
// m is the v direction vector in view space
|
// m is the v direction vector in view space
|
||||||
ang = (DAngle(180.) - ViewAngle).Radians();
|
ang = DAngle(180.) - ViewAngle;
|
||||||
m[0] = yscale * cos(ang);
|
m[0] = yscale * ang.Cos();
|
||||||
m[2] = yscale * sin(ang);
|
m[2] = yscale * ang.Sin();
|
||||||
// m[1] = pl->height.ZatPointF (0, iyscale) - pl->height.ZatPointF (0,0));
|
// m[1] = pl->height.ZatPointF (0, iyscale) - pl->height.ZatPointF (0,0));
|
||||||
// VectorScale2 (m, 64.f/VectorLength(m));
|
// VectorScale2 (m, 64.f/VectorLength(m));
|
||||||
|
|
||||||
// n is the u direction vector in view space
|
// n is the u direction vector in view space
|
||||||
ang += PI/2;
|
ang += 90;
|
||||||
n[0] = -xscale * cos(ang);
|
n[0] = -xscale * ang.Cos();
|
||||||
n[2] = -xscale * sin(ang);
|
n[2] = -xscale * ang.Sin();
|
||||||
// n[1] = pl->height.ZatPointF (ixscale, 0) - pl->height.ZatPointF (0,0));
|
// n[1] = pl->height.ZatPointF (ixscale, 0) - pl->height.ZatPointF (0,0));
|
||||||
// VectorScale2 (n, 64.f/VectorLength(n));
|
// VectorScale2 (n, 64.f/VectorLength(n));
|
||||||
|
|
||||||
// This code keeps the texture coordinates constant across the x,y plane no matter
|
// This code keeps the texture coordinates constant across the x,y plane no matter
|
||||||
// how much you slope the surface. Use the commented-out code above instead to keep
|
// how much you slope the surface. Use the commented-out code above instead to keep
|
||||||
// the textures a constant size across the surface's plane instead.
|
// the textures a constant size across the surface's plane instead.
|
||||||
ang = pl->angle * (M_PI / ANGLE_180);
|
ang = pl->xform->Angle + pl->xform->baseAngle;
|
||||||
m[1] = pl->height.ZatPoint(ViewPos.X + yscale * sin(ang), ViewPos.Y + yscale * cos(ang)) - zeroheight;
|
m[1] = pl->height.ZatPoint(ViewPos.X + yscale * ang.Sin(), ViewPos.Y + yscale * ang.Cos()) - zeroheight;
|
||||||
ang += PI/2;
|
ang += 90;
|
||||||
n[1] = pl->height.ZatPoint(ViewPos.X + xscale * sin(ang), ViewPos.Y + xscale * cos(ang)) - zeroheight;
|
n[1] = pl->height.ZatPoint(ViewPos.X + xscale * ang.Sin(), ViewPos.Y + xscale * ang.Cos()) - zeroheight;
|
||||||
|
|
||||||
plane_su = p ^ m;
|
plane_su = p ^ m;
|
||||||
plane_sv = p ^ n;
|
plane_sv = p ^ n;
|
||||||
|
|
|
@ -34,16 +34,15 @@ struct visplane_s
|
||||||
{
|
{
|
||||||
struct visplane_s *next; // Next visplane in hash chain -- killough
|
struct visplane_s *next; // Next visplane in hash chain -- killough
|
||||||
|
|
||||||
|
const FTransform *xform;
|
||||||
|
FDynamicColormap *colormap; // [RH] Support multiple colormaps
|
||||||
|
FSectorPortal *portal; // [RH] Support sky boxes
|
||||||
|
|
||||||
secplane_t height;
|
secplane_t height;
|
||||||
FTextureID picnum;
|
FTextureID picnum;
|
||||||
int lightlevel;
|
int lightlevel;
|
||||||
fixed_t xoffs, yoffs; // killough 2/28/98: Support scrolling flats
|
|
||||||
int left, right;
|
int left, right;
|
||||||
FDynamicColormap *colormap; // [RH] Support multiple colormaps
|
|
||||||
fixed_t xscale, yscale; // [RH] Support flat scaling
|
|
||||||
angle_t angle; // [RH] Support flat rotation
|
|
||||||
int sky;
|
int sky;
|
||||||
FSectorPortal *portal; // [RH] Support sky boxes
|
|
||||||
|
|
||||||
// [RH] This set of variables copies information from the time when the
|
// [RH] This set of variables copies information from the time when the
|
||||||
// visplane is created. They are only used by stacks so that you can
|
// visplane is created. They are only used by stacks so that you can
|
||||||
|
@ -90,8 +89,8 @@ void R_ClearPlanes (bool fullclear);
|
||||||
int R_DrawPlanes ();
|
int R_DrawPlanes ();
|
||||||
void R_DrawPortals ();
|
void R_DrawPortals ();
|
||||||
void R_DrawSkyPlane (visplane_t *pl);
|
void R_DrawSkyPlane (visplane_t *pl);
|
||||||
void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool masked);
|
void R_DrawNormalPlane (visplane_t *pl, double xscale, double yscale, fixed_t alpha, bool additive, bool masked);
|
||||||
void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool masked);
|
void R_DrawTiltedPlane (visplane_t *pl, double xscale, double yscale, fixed_t alpha, bool additive, bool masked);
|
||||||
void R_MapVisPlane (visplane_t *pl, void (*mapfunc)(int y, int x1));
|
void R_MapVisPlane (visplane_t *pl, void (*mapfunc)(int y, int x1));
|
||||||
|
|
||||||
visplane_t *R_FindPlane
|
visplane_t *R_FindPlane
|
||||||
|
|
Loading…
Reference in a new issue