Commence renderer floatification

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

View file

@ -21,8 +21,8 @@ F3DFloor *fakeFloor;
fixed_t fakeHeight; fixed_t fakeHeight;
fixed_t fakeAlpha; fixed_t fakeAlpha;
int fakeActive = 0; int fakeActive = 0;
fixed_t sclipBottom; double sclipBottom;
fixed_t sclipTop; double sclipTop;
HeightLevel *height_top = NULL; HeightLevel *height_top = NULL;
HeightLevel *height_cur = NULL; HeightLevel *height_cur = NULL;
int CurrentMirror = 0; int CurrentMirror = 0;

View file

@ -7,7 +7,7 @@
struct HeightLevel struct HeightLevel
{ {
fixed_t height; double height;
struct HeightLevel *prev; struct HeightLevel *prev;
struct HeightLevel *next; struct HeightLevel *next;
}; };
@ -51,8 +51,8 @@ extern int fake3D;
extern F3DFloor *fakeFloor; extern F3DFloor *fakeFloor;
extern fixed_t fakeAlpha; extern fixed_t fakeAlpha;
extern int fakeActive; extern int fakeActive;
extern fixed_t sclipBottom; extern double sclipBottom;
extern fixed_t sclipTop; extern double sclipTop;
extern HeightLevel *height_top; extern HeightLevel *height_top;
extern HeightLevel *height_cur; extern HeightLevel *height_cur;
extern int CurrentMirror; extern int CurrentMirror;

View file

@ -336,7 +336,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
{ {
sector_t *heightsec = viewsector->heightsec; sector_t *heightsec = viewsector->heightsec;
bool underwater = r_fakingunderwater || bool underwater = r_fakingunderwater ||
(heightsec && heightsec->floorplane.PointOnSide(viewx, viewy, viewz) <= 0); (heightsec && heightsec->floorplane.PointOnSide(ViewPos) <= 0);
bool doorunderwater = false; bool doorunderwater = false;
int diffTex = (s->MoreFlags & SECF_CLIPFAKEPLANES); int diffTex = (s->MoreFlags & SECF_CLIPFAKEPLANES);
@ -395,8 +395,8 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
} }
} }
fixed_t refceilz = s->ceilingplane.ZatPointFixed (viewx, viewy); double refceilz = s->ceilingplane.ZatPoint(ViewPos);
fixed_t orgceilz = sec->ceilingplane.ZatPointFixed(viewx, viewy); double orgceilz = sec->ceilingplane.ZatPoint(ViewPos);
#if 1 #if 1
// [RH] Allow viewing underwater areas through doors/windows that // [RH] Allow viewing underwater areas through doors/windows that
@ -405,8 +405,8 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
// sectors at the same time. // sectors at the same time.
if (back && !r_fakingunderwater && curline->frontsector->heightsec == NULL) if (back && !r_fakingunderwater && curline->frontsector->heightsec == NULL)
{ {
if (rw_frontcz1 <= s->floorplane.ZatPointFixed (curline->v1) && if (rw_frontcz1 <= s->floorplane.ZatPoint(curline->v1) &&
rw_frontcz2 <= s->floorplane.ZatPointFixed(curline->v2)) rw_frontcz2 <= s->floorplane.ZatPoint(curline->v2))
{ {
// Check that the window is actually visible // Check that the window is actually visible
for (int z = WallC.sx1; z < WallC.sx2; ++z) for (int z = WallC.sx1; z < WallC.sx2; ++z)
@ -470,7 +470,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
} }
FakeSide = FAKED_BelowFloor; FakeSide = FAKED_BelowFloor;
} }
else if (heightsec && heightsec->ceilingplane.PointOnSide(viewx, viewy, viewz) <= 0 && else if (heightsec && heightsec->ceilingplane.PointOnSide(ViewPos) <= 0 &&
orgceilz > refceilz && !(s->MoreFlags & SECF_FAKEFLOORONLY)) orgceilz > refceilz && !(s->MoreFlags & SECF_FAKEFLOORONLY))
{ // Above-ceiling hack { // Above-ceiling hack
tempsec->ceilingplane = s->ceilingplane; tempsec->ceilingplane = s->ceilingplane;
@ -540,23 +540,21 @@ void R_AddLine (seg_t *line)
{ {
static sector_t tempsec; // killough 3/8/98: ceiling/water hack static sector_t tempsec; // killough 3/8/98: ceiling/water hack
bool solid; bool solid;
fixed_t tx1, tx2, ty1, ty2; DVector2 pt1, pt2;
curline = line; curline = line;
// [RH] Color if not texturing line // [RH] Color if not texturing line
dc_color = (((int)(line - segs) * 8) + 4) & 255; dc_color = (((int)(line - segs) * 8) + 4) & 255;
tx1 = line->v1->fixX() - viewx; pt1 = line->v1->fPos() - ViewPos;
tx2 = line->v2->fixX() - viewx; pt2 = line->v2->fPos() - ViewPos;
ty1 = line->v1->fixY() - viewy;
ty2 = line->v2->fixY() - viewy;
// Reject lines not facing viewer // Reject lines not facing viewer
if (DMulScale32 (ty1, tx1-tx2, tx1, ty2-ty1) >= 0) if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0)
return; return;
if (WallC.Init(tx1, ty1, tx2, ty2, 32)) if (WallC.Init(pt1, pt2, 32.0 / (1 << 12)))
return; return;
if (WallC.sx1 >= WindowRight || WallC.sx2 <= WindowLeft) if (WallC.sx1 >= WindowRight || WallC.sx2 <= WindowLeft)
@ -591,7 +589,7 @@ void R_AddLine (seg_t *line)
{ {
swapvalues (v1, v2); swapvalues (v1, v2);
} }
WallT.InitFromLine(v1->fixX() - viewx, v1->fixY() - viewy, v2->fixX() - viewx, v2->fixY() - viewy); WallT.InitFromLine(v1->fPos() - ViewPos, v2->fPos() - ViewPos);
} }
if (!(fake3D & FAKE3D_FAKEBACK)) if (!(fake3D & FAKE3D_FAKEBACK))
@ -773,57 +771,57 @@ void R_AddLine (seg_t *line)
// //
// Transform and clip coordinates. Returns true if it was clipped away // Transform and clip coordinates. Returns true if it was clipped away
// //
bool FWallCoords::Init(int x1, int y1, int x2, int y2, int too_close) bool FWallCoords::Init(const DVector2 &pt1, const DVector2 &pt2, double too_close)
{ {
tx1 = DMulScale20(x1, viewsin, -y1, viewcos); tleft.X = float(pt1.X * ViewSin - pt1.Y * ViewCos);
tx2 = DMulScale20(x2, viewsin, -y2, viewcos); tright.X = float(pt2.X * ViewSin - pt2.Y * ViewCos);
ty1 = DMulScale20(x1, viewtancos, y1, viewtansin); tleft.Y = float(pt1.X * ViewTanCos + pt1.Y * ViewTanSin);
ty2 = DMulScale20(x2, viewtancos, y2, viewtansin); tright.Y = float(pt2.X * ViewTanCos + pt2.Y * ViewTanSin);
if (MirrorFlags & RF_XFLIP) if (MirrorFlags & RF_XFLIP)
{ {
int t = 256 - tx1; float t = -tleft.X;
tx1 = 256 - tx2; tleft.X = -tright.X;
tx2 = t; tright.X = t;
swapvalues(ty1, ty2); swapvalues(tleft.Y, tright.Y);
} }
if (tx1 >= -ty1) if (tleft.X >= -tleft.Y)
{ {
if (tx1 > ty1) return true; // left edge is off the right side if (tleft.X > tleft.Y) return true; // left edge is off the right side
if (ty1 == 0) return true; if (tleft.Y == 0) return true;
sx1 = (centerxfrac + Scale(tx1, centerxfrac, ty1)) >> FRACBITS; sx1 = xs_ToInt(CenterX + tleft.X * CenterX / tleft.Y);
if (tx1 >= 0) sx1 = MIN(viewwidth, sx1+1); // fix for signed divide if (tleft.X >= 0) sx1 = MIN(viewwidth, sx1+1); // fix for signed divide
sz1 = ty1; sz1 = tleft.Y;
} }
else else
{ {
if (tx2 < -ty2) return true; // wall is off the left side if (tright.X < -tright.Y) return true; // wall is off the left side
fixed_t den = tx1 - tx2 - ty2 + ty1; float den = tleft.X - tright.X - tright.Y + tleft.Y;
if (den == 0) return true; if (den == 0) return true;
sx1 = 0; sx1 = 0;
sz1 = ty1 + Scale(ty2 - ty1, tx1 + ty1, den); sz1 = tleft.Y + (tright.Y - tleft.Y) * (tleft.X + tleft.Y) / den;
} }
if (sz1 < too_close) if (sz1 < too_close)
return true; return true;
if (tx2 <= ty2) if (tright.X <= tright.Y)
{ {
if (tx2 < -ty2) return true; // right edge is off the left side if (tright.X < -tright.Y) return true; // right edge is off the left side
if (ty2 == 0) return true; if (tright.Y == 0) return true;
sx2 = (centerxfrac + Scale(tx2, centerxfrac, ty2)) >> FRACBITS; sx2 = xs_ToInt(CenterX + tright.X * CenterX / tright.Y);
if (tx2 >= 0) sx2 = MIN(viewwidth, sx2+1); // fix for signed divide if (tright.X >= 0) sx2 = MIN(viewwidth, sx2+1); // fix for signed divide
sz2 = ty2; sz2 = tright.Y;
} }
else else
{ {
if (tx1 > ty1) return true; // wall is off the right side if (tleft.X > tleft.Y) return true; // wall is off the right side
fixed_t den = ty2 - ty1 - tx2 + tx1; float den = tright.Y - tleft.Y - tright.X + tleft.X;
if (den == 0) return true; if (den == 0) return true;
sx2 = viewwidth; sx2 = viewwidth;
sz2 = ty1 + Scale(ty2 - ty1, tx1 - ty1, den); sz2 = tleft.Y + (tright.Y - tleft.Y) * (tleft.X - tleft.Y) / den;
} }
if (sz2 < too_close || sx2 <= sx1) if (sz2 < too_close || sx2 <= sx1)
@ -834,28 +832,25 @@ bool FWallCoords::Init(int x1, int y1, int x2, int y2, int too_close)
void FWallTmapVals::InitFromWallCoords(const FWallCoords *wallc) void FWallTmapVals::InitFromWallCoords(const FWallCoords *wallc)
{ {
const FVector2 *left = &wallc->tleft;
const FVector2 *right = &wallc->tright;
if (MirrorFlags & RF_XFLIP) if (MirrorFlags & RF_XFLIP)
{ {
UoverZorg = (float)wallc->tx2 * centerx; swapvalues(left, right);
UoverZstep = (float)(-wallc->ty2);
InvZorg = (float)(wallc->tx2 - wallc->tx1) * centerx;
InvZstep = (float)(wallc->ty1 - wallc->ty2);
}
else
{
UoverZorg = (float)wallc->tx1 * centerx;
UoverZstep = (float)(-wallc->ty1);
InvZorg = (float)(wallc->tx1 - wallc->tx2) * centerx;
InvZstep = (float)(wallc->ty2 - wallc->ty1);
} }
UoverZorg = left->X * centerx;
UoverZstep = -left->Y;
InvZorg = (left->X - right->X) * centerx;
InvZstep = right->Y - left->Y;
} }
void FWallTmapVals::InitFromLine(int tx1, int ty1, int tx2, int ty2) void FWallTmapVals::InitFromLine(const DVector2 &left, const DVector2 &right)
{ // Coordinates should have already had viewx,viewy subtracted { // Coordinates should have already had viewx,viewy subtracted
fixed_t fullx1 = DMulScale20 (tx1, viewsin, -ty1, viewcos); double fullx1 = left.X * ViewSin - left.Y * ViewCos;
fixed_t fullx2 = DMulScale20 (tx2, viewsin, -ty2, viewcos); double fullx2 = right.X * ViewSin - right.Y * ViewCos;
fixed_t fully1 = DMulScale20 (tx1, viewtancos, ty1, viewtansin); double fully1 = left.X * ViewTanCos + left.Y * ViewTanSin;
fixed_t fully2 = DMulScale20 (tx2, viewtancos, ty2, viewtansin); double fully2 = right.X * ViewTanCos + right.Y * ViewTanSin;
if (MirrorFlags & RF_XFLIP) if (MirrorFlags & RF_XFLIP)
{ {
@ -863,10 +858,10 @@ void FWallTmapVals::InitFromLine(int tx1, int ty1, int tx2, int ty2)
fullx2 = -fullx2; fullx2 = -fullx2;
} }
UoverZorg = (float)fullx1 * centerx; UoverZorg = float(fullx1 * centerx);
UoverZstep = (float)(-fully1); UoverZstep = float(-fully1);
InvZorg = (float)(fullx1 - fullx2) * centerx; InvZorg = float((fullx1 - fullx2) * centerx);
InvZstep = (float)(fully2 - fully1); InvZstep = float(fully2 - fully1);
} }
// //
@ -896,24 +891,24 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static
int boxy; int boxy;
int boxpos; int boxpos;
fixed_t x1, y1, x2, y2; double x1, y1, x2, y2;
fixed_t rx1, ry1, rx2, ry2; double rx1, ry1, rx2, ry2;
int sx1, sx2; int sx1, sx2;
cliprange_t* start; cliprange_t* start;
// Find the corners of the box // Find the corners of the box
// that define the edges from current viewpoint. // that define the edges from current viewpoint.
if (viewx <= bspcoord[BOXLEFT]) if (ViewPos.X <= FIXED2DBL(bspcoord[BOXLEFT]))
boxx = 0; boxx = 0;
else if (viewx < bspcoord[BOXRIGHT]) else if (ViewPos.X < FIXED2DBL(bspcoord[BOXRIGHT]))
boxx = 1; boxx = 1;
else else
boxx = 2; boxx = 2;
if (viewy >= bspcoord[BOXTOP]) if (ViewPos.Y >= FIXED2DBL(bspcoord[BOXTOP]))
boxy = 0; boxy = 0;
else if (viewy > bspcoord[BOXBOTTOM]) else if (ViewPos.Y > FIXED2DBL(bspcoord[BOXBOTTOM]))
boxy = 1; boxy = 1;
else else
boxy = 2; boxy = 2;
@ -922,26 +917,26 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static
if (boxpos == 5) if (boxpos == 5)
return true; return true;
x1 = bspcoord[checkcoord[boxpos][0]] - viewx; x1 = FIXED2DBL(bspcoord[checkcoord[boxpos][0]]) - ViewPos.X;
y1 = bspcoord[checkcoord[boxpos][1]] - viewy; y1 = FIXED2DBL(bspcoord[checkcoord[boxpos][1]]) - ViewPos.Y;
x2 = bspcoord[checkcoord[boxpos][2]] - viewx; x2 = FIXED2DBL(bspcoord[checkcoord[boxpos][2]]) - ViewPos.X;
y2 = bspcoord[checkcoord[boxpos][3]] - viewy; y2 = FIXED2DBL(bspcoord[checkcoord[boxpos][3]]) - ViewPos.Y;
// check clip list for an open space // check clip list for an open space
// Sitting on a line? // Sitting on a line?
if (DMulScale32 (y1, x1-x2, x1, y2-y1) >= 0) if (y1 * (x1 - x2) + x1 * (y2 - y1) >= -EQUAL_EPSILON)
return true; return true;
rx1 = DMulScale20 (x1, viewsin, -y1, viewcos); rx1 = x1 * ViewSin - y1 * ViewCos;
rx2 = DMulScale20 (x2, viewsin, -y2, viewcos); rx2 = x2 * ViewSin - y2 * ViewCos;
ry1 = DMulScale20 (x1, viewtancos, y1, viewtansin); ry1 = x1 * ViewTanCos + y1 * ViewTanSin;
ry2 = DMulScale20 (x2, viewtancos, y2, viewtansin); ry2 = x2 * ViewTanCos + y2 * ViewTanSin;
if (MirrorFlags & RF_XFLIP) if (MirrorFlags & RF_XFLIP)
{ {
int t = 256-rx1; double t = -rx1;
rx1 = 256-rx2; rx1 = -rx2;
rx2 = t; rx2 = t;
swapvalues(ry1, ry2); swapvalues(ry1, ry2);
} }
@ -950,7 +945,7 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static
{ {
if (rx1 > ry1) return false; // left edge is off the right side if (rx1 > ry1) return false; // left edge is off the right side
if (ry1 == 0) return false; if (ry1 == 0) return false;
sx1 = (centerxfrac + Scale (rx1, centerxfrac, ry1)) >> FRACBITS; sx1 = xs_ToInt(CenterX + rx1 * CenterX / ry1);
if (rx1 >= 0) sx1 = MIN<int>(viewwidth, sx1+1); // fix for signed divide if (rx1 >= 0) sx1 = MIN<int>(viewwidth, sx1+1); // fix for signed divide
} }
else else
@ -964,7 +959,7 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static
{ {
if (rx2 < -ry2) return false; // right edge is off the left side if (rx2 < -ry2) return false; // right edge is off the left side
if (ry2 == 0) return false; if (ry2 == 0) return false;
sx2 = (centerxfrac + Scale (rx2, centerxfrac, ry2)) >> FRACBITS; sx2 = xs_ToInt(CenterX + rx2 * CenterX / ry2);
if (rx2 >= 0) sx2 = MIN<int>(viewwidth, sx2+1); // fix for signed divide if (rx2 >= 0) sx2 = MIN<int>(viewwidth, sx2+1); // fix for signed divide
} }
else else
@ -1116,7 +1111,7 @@ void R_Subsector (subsector_t *sub)
portal = frontsector->ValidatePortal(sector_t::ceiling); portal = frontsector->ValidatePortal(sector_t::ceiling);
ceilingplane = frontsector->ceilingplane.PointOnSide(viewx, viewy, viewz) > 0 || ceilingplane = frontsector->ceilingplane.PointOnSide(ViewPos) > 0 ||
frontsector->GetTexture(sector_t::ceiling) == skyflatnum || frontsector->GetTexture(sector_t::ceiling) == skyflatnum ||
portal != NULL || portal != NULL ||
(frontsector->heightsec && (frontsector->heightsec &&
@ -1157,7 +1152,7 @@ void R_Subsector (subsector_t *sub)
// killough 10/98: add support for skies transferred from sidedefs // killough 10/98: add support for skies transferred from sidedefs
portal = frontsector->ValidatePortal(sector_t::floor); portal = frontsector->ValidatePortal(sector_t::floor);
floorplane = frontsector->floorplane.PointOnSide(viewx, viewy, viewz) > 0 || // killough 3/7/98 floorplane = frontsector->floorplane.PointOnSide(ViewPos) > 0 || // killough 3/7/98
frontsector->GetTexture(sector_t::floor) == skyflatnum || frontsector->GetTexture(sector_t::floor) == skyflatnum ||
portal != NULL || portal != NULL ||
(frontsector->heightsec && (frontsector->heightsec &&
@ -1408,7 +1403,7 @@ void R_RenderBSPNode (void *node)
node_t *bsp = (node_t *)node; node_t *bsp = (node_t *)node;
// Decide which side the view point is on. // Decide which side the view point is on.
int side = R_PointOnSide (viewx, viewy, bsp); int side = R_PointOnSide (ViewPos, bsp);
// Recursively divide front space (toward the viewer). // Recursively divide front space (toward the viewer).
R_RenderBSPNode (bsp->children[side]); R_RenderBSPNode (bsp->children[side]);

View file

@ -30,17 +30,17 @@
// The 3072 below is just an arbitrary value picked to avoid // The 3072 below is just an arbitrary value picked to avoid
// drawing lines the player is too close to that would overflow // drawing lines the player is too close to that would overflow
// the texture calculations. // the texture calculations.
#define TOO_CLOSE_Z 3072 #define TOO_CLOSE_Z (3072.0 / (1<<12))
struct FWallCoords struct FWallCoords
{ {
fixed_t tx1, tx2; // x coords at left, right of wall in view space rx1,rx2 FVector2 tleft; // coords at left of wall in view space rx1,ry1
fixed_t ty1, ty2; // y coords at left, right of wall in view space ry1,ry2 FVector2 tright; // coords at right of wall in view space rx2,ry2
float sz1, sz2; // depth at left, right of wall in screen space yb1,yb2
short sx1, sx2; // x coords at left, right of wall in screen space xb1,xb2 short sx1, sx2; // x coords at left, right of wall in screen space xb1,xb2
fixed_t sz1, sz2; // depth at left, right of wall in screen space yb1,yb2
bool Init(int x1, int y1, int x2, int y2, int too_close); bool Init(const DVector2 &pt1, const DVector2 &pt2, double too_close);
}; };
struct FWallTmapVals struct FWallTmapVals
@ -49,7 +49,7 @@ struct FWallTmapVals
float InvZorg, InvZstep; float InvZorg, InvZstep;
void InitFromWallCoords(const FWallCoords *wallc); void InitFromWallCoords(const FWallCoords *wallc);
void InitFromLine(int x1, int y1, int x2, int y2); void InitFromLine(const DVector2 &left, const DVector2 &right);
}; };
extern FWallCoords WallC; extern FWallCoords WallC;
@ -69,9 +69,9 @@ struct drawseg_t
fixed_t iscale, iscalestep; fixed_t iscale, iscalestep;
short x1, x2; // Same as sx1 and sx2, but clipped to the drawseg short x1, x2; // Same as sx1 and sx2, but clipped to the drawseg
short sx1, sx2; // left, right of parent seg on screen short sx1, sx2; // left, right of parent seg on screen
fixed_t sz1, sz2; // z for left, right of parent seg on screen float sz1, sz2; // z for left, right of parent seg on screen
fixed_t siz1, siz2; // 1/z for left, right of parent seg on screen float siz1, siz2; // 1/z for left, right of parent seg on screen
fixed_t cx, cy, cdx, cdy; float cx, cy, cdx, cdy;
fixed_t yrepeat; fixed_t yrepeat;
BYTE silhouette; // 0=none, 1=bottom, 2=top, 3=both BYTE silhouette; // 0=none, 1=bottom, 2=top, 3=both
BYTE bFogBoundary; BYTE bFogBoundary;

View file

@ -326,9 +326,9 @@ public:
} }
// Returns the value of z at (0,0) This is used by the 3D floor code which does not handle slopes // Returns the value of z at (0,0) This is used by the 3D floor code which does not handle slopes
fixed_t Zat0 () const double Zat0() const
{ {
return FLOAT2FIXED(negiC*D); return negiC*D;
} }
// Returns the value of z at (x,y) // Returns the value of z at (x,y)
@ -362,6 +362,10 @@ public:
return (D + normal.X*pos.X + normal.Y*pos.Y) * negiC; return (D + normal.X*pos.X + normal.Y*pos.Y) * negiC;
} }
double ZatPoint(const FVector2 &pos) const
{
return (D + normal.X*pos.X + normal.Y*pos.Y) * negiC;
}
double ZatPoint(const vertex_t *v) const double ZatPoint(const vertex_t *v) const
{ {

View file

@ -1136,7 +1136,7 @@ void R_DrawMaskedColumnHoriz (const BYTE *column, const FTexture::Span *span)
if (sprflipvert) if (sprflipvert)
{ {
dc_texturefrac = (dc_yl*dc_iscale) - (top << FRACBITS) dc_texturefrac = (dc_yl*dc_iscale) - (top << FRACBITS)
- FixedMul (centeryfrac, dc_iscale) - dc_texturemid; - fixed_t(CenterY * dc_iscale) - dc_texturemid;
const fixed_t maxfrac = length << FRACBITS; const fixed_t maxfrac = length << FRACBITS;
while (dc_texturefrac >= maxfrac) while (dc_texturefrac >= maxfrac)
{ {
@ -1155,7 +1155,7 @@ void R_DrawMaskedColumnHoriz (const BYTE *column, const FTexture::Span *span)
else else
{ {
dc_texturefrac = dc_texturemid - (top << FRACBITS) dc_texturefrac = dc_texturemid - (top << FRACBITS)
+ (dc_yl*dc_iscale) - FixedMul (centeryfrac-FRACUNIT, dc_iscale); + (dc_yl*dc_iscale) - fixed_t((CenterY-1) * dc_iscale);
while (dc_texturefrac < 0) while (dc_texturefrac < 0)
{ {
if (++dc_yl > dc_yh) if (++dc_yl > dc_yh)

View file

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

View file

@ -35,22 +35,21 @@ typedef BYTE lighttable_t; // This could be wider for >8 bit display.
// POV related. // POV related.
// //
extern bool bRenderingToCanvas; extern bool bRenderingToCanvas;
extern fixed_t viewcos; extern double ViewCos;
extern fixed_t viewsin; extern double ViewSin;
extern fixed_t viewingrangerecip; extern fixed_t viewingrangerecip;
extern fixed_t FocalLengthX, FocalLengthY; extern double FocalLengthX, FocalLengthY;
extern float FocalLengthXfloat; extern double InvZtoScale;
extern fixed_t InvZtoScale;
extern float WallTMapScale2; extern double WallTMapScale2;
extern int viewwindowx; extern int viewwindowx;
extern int viewwindowy; extern int viewwindowy;
extern fixed_t centerxfrac; extern double CenterX;
extern fixed_t centeryfrac; extern double CenterY;
extern fixed_t yaspectmul; extern double YaspectMul;
extern float iyaspectmulfloat; extern double IYaspectMul;
extern FDynamicColormap*basecolormap; // [RH] Colormap for sector currently being drawn extern FDynamicColormap*basecolormap; // [RH] Colormap for sector currently being drawn
@ -139,8 +138,8 @@ void R_MultiresInit (void);
extern int stacked_extralight; extern int stacked_extralight;
extern float stacked_visibility; extern float stacked_visibility;
extern fixed_t stacked_viewx, stacked_viewy, stacked_viewz; extern DVector3 stacked_viewpos;
extern angle_t stacked_angle; extern DAngle stacked_angle;
extern void R_CopyStackedViewParameters(); extern void R_CopyStackedViewParameters();

View file

@ -99,8 +99,8 @@ visplane_t *ceilingplane;
// won't draw in skyboxes properly. // won't draw in skyboxes properly.
int stacked_extralight; int stacked_extralight;
float stacked_visibility; float stacked_visibility;
fixed_t stacked_viewx, stacked_viewy, stacked_viewz; DVector3 stacked_viewpos;
angle_t stacked_angle; DAngle stacked_angle;
// //
@ -228,7 +228,7 @@ void R_MapPlane (int y, int x1)
{ {
// Determine lighting based on the span's distance from the viewer. // Determine lighting based on the span's distance from the viewer.
ds_colormap = basecolormap->Maps + (GETPALOOKUP ( ds_colormap = basecolormap->Maps + (GETPALOOKUP (
FixedMul (GlobVis, abs (centeryfrac - (y << FRACBITS))), planeshade) << COLORMAPSHIFT); xs_ToInt(GlobVis * fabs(CenterY - y)), planeshade) << COLORMAPSHIFT);
} }
#ifdef X86_ASM #ifdef X86_ASM
@ -640,9 +640,7 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl
// check even more. // check even more.
if (check->extralight == stacked_extralight && if (check->extralight == stacked_extralight &&
check->visibility == stacked_visibility && check->visibility == stacked_visibility &&
check->viewx == stacked_viewx && check->viewpos == stacked_viewpos &&
check->viewy == stacked_viewy &&
check->viewz == stacked_viewz &&
( (
// headache inducing logic... :( // headache inducing logic... :(
(portal->mType != PORTS_STACKEDSECTORTHING) || (portal->mType != PORTS_STACKEDSECTORTHING) ||
@ -689,9 +687,7 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl
CurrentPortalUniq == check->CurrentPortalUniq && CurrentPortalUniq == check->CurrentPortalUniq &&
MirrorFlags == check->MirrorFlags && MirrorFlags == check->MirrorFlags &&
CurrentSkybox == check->CurrentSkybox && CurrentSkybox == check->CurrentSkybox &&
viewx == check->viewx && ViewPos == check->viewpos
viewy == check->viewy &&
viewz == check->viewz
) )
{ {
return check; return check;
@ -715,9 +711,7 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl
check->right = 0; check->right = 0;
check->extralight = stacked_extralight; check->extralight = stacked_extralight;
check->visibility = stacked_visibility; check->visibility = stacked_visibility;
check->viewx = stacked_viewx; check->viewpos = stacked_viewpos;
check->viewy = stacked_viewy;
check->viewz = stacked_viewz;
check->viewangle = stacked_angle; check->viewangle = stacked_angle;
check->Alpha = alpha; check->Alpha = alpha;
check->Additive = additive; check->Additive = additive;
@ -803,9 +797,7 @@ visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop)
new_pl->portal = pl->portal; new_pl->portal = pl->portal;
new_pl->extralight = pl->extralight; new_pl->extralight = pl->extralight;
new_pl->visibility = pl->visibility; new_pl->visibility = pl->visibility;
new_pl->viewx = pl->viewx; new_pl->viewpos = pl->viewpos;
new_pl->viewy = pl->viewy;
new_pl->viewz = pl->viewz;
new_pl->viewangle = pl->viewangle; new_pl->viewangle = pl->viewangle;
new_pl->sky = pl->sky; new_pl->sky = pl->sky;
new_pl->Alpha = pl->Alpha; new_pl->Alpha = pl->Alpha;
@ -985,7 +977,7 @@ static void R_DrawSky (visplane_t *pl)
static void R_DrawSkyStriped (visplane_t *pl) static void R_DrawSkyStriped (visplane_t *pl)
{ {
fixed_t centerysave = centeryfrac; double centerysave = CenterY;
short drawheight = (short)MulScale16 (frontskytex->GetHeight(), frontyScale); short drawheight = (short)MulScale16 (frontskytex->GetHeight(), frontyScale);
fixed_t topfrac; fixed_t topfrac;
fixed_t iscale = frontiScale; fixed_t iscale = frontiScale;
@ -995,7 +987,7 @@ static void R_DrawSkyStriped (visplane_t *pl)
// So that I don't have to worry about fractional precision, chop off the // So that I don't have to worry about fractional precision, chop off the
// fractional part of centeryfrac. // fractional part of centeryfrac.
centeryfrac = centery << FRACBITS; CenterY = centery;
topfrac = (skymid + iscale * (1-centery)) % (frontskytex->GetHeight() << FRACBITS); topfrac = (skymid + iscale * (1-centery)) % (frontskytex->GetHeight() << FRACBITS);
if (topfrac < 0) topfrac += frontskytex->GetHeight() << FRACBITS; if (topfrac < 0) topfrac += frontskytex->GetHeight() << FRACBITS;
yl = 0; yl = 0;
@ -1020,7 +1012,7 @@ static void R_DrawSkyStriped (visplane_t *pl)
yh += drawheight; yh += drawheight;
dc_texturemid = iscale * (centery-yl-1); dc_texturemid = iscale * (centery-yl-1);
} }
centeryfrac = centerysave; CenterY = centerysave;
} }
//========================================================================== //==========================================================================
@ -1060,15 +1052,15 @@ int R_DrawPlanes ()
} }
// kg3D - draw all visplanes with "height" // kg3D - draw all visplanes with "height"
void R_DrawHeightPlanes(fixed_t height) void R_DrawHeightPlanes(double height)
{ {
visplane_t *pl; visplane_t *pl;
int i; int i;
ds_color = 3; ds_color = 3;
fixed_t oViewX = viewx, oViewY = viewy, oViewZ = viewz; DVector3 oViewPos = ViewPos;
angle_t oViewAngle = viewangle; DAngle oViewAngle = ViewAngle;
for (i = 0; i < MAXVISPLANES; i++) for (i = 0; i < MAXVISPLANES; i++)
{ {
@ -1078,24 +1070,15 @@ void R_DrawHeightPlanes(fixed_t height)
if(pl->CurrentSkybox != CurrentSkybox || pl->CurrentPortalUniq != CurrentPortalUniq) if(pl->CurrentSkybox != CurrentSkybox || pl->CurrentPortalUniq != CurrentPortalUniq)
continue; continue;
if(pl->sky < 0 && pl->height.Zat0() == height) { if(pl->sky < 0 && pl->height.Zat0() == height) {
viewx = pl->viewx; ViewPos = pl->viewpos;
viewy = pl->viewy; ViewAngle = pl->viewangle;
viewz = pl->viewz;
viewangle = pl->viewangle;
ViewAngle = AngleToFloat(viewangle);
ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) };
MirrorFlags = pl->MirrorFlags; MirrorFlags = pl->MirrorFlags;
R_DrawSinglePlane (pl, pl->sky & 0x7FFFFFFF, pl->Additive, true); R_DrawSinglePlane (pl, pl->sky & 0x7FFFFFFF, pl->Additive, true);
} }
} }
} }
ViewPos = oViewPos;
viewx = oViewX; ViewAngle = oViewAngle;
viewy = oViewY;
viewz = oViewZ;
viewangle = oViewAngle;
ViewAngle = AngleToFloat(viewangle);
ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) };
} }
@ -1186,7 +1169,7 @@ void R_DrawPortals ()
static TArray<size_t> interestingStack; static TArray<size_t> interestingStack;
static TArray<ptrdiff_t> drawsegStack; static TArray<ptrdiff_t> drawsegStack;
static TArray<ptrdiff_t> visspriteStack; static TArray<ptrdiff_t> visspriteStack;
static TArray<fixed_t> viewxStack, viewyStack, viewzStack; static TArray<DVector3> viewposStack;
static TArray<visplane_t *> visplaneStack; static TArray<visplane_t *> visplaneStack;
numskyboxes = 0; numskyboxes = 0;
@ -1198,10 +1181,8 @@ void R_DrawPortals ()
CurrentPortalInSkybox = true; CurrentPortalInSkybox = true;
int savedextralight = extralight; int savedextralight = extralight;
fixed_t savedx = viewx; DVector3 savedpos = ViewPos;
fixed_t savedy = viewy; DAngle savedangle = ViewAngle;
fixed_t savedz = viewz;
angle_t savedangle = viewangle;
ptrdiff_t savedvissprite_p = vissprite_p - vissprites; ptrdiff_t savedvissprite_p = vissprite_p - vissprites;
ptrdiff_t savedds_p = ds_p - drawsegs; ptrdiff_t savedds_p = ds_p - drawsegs;
ptrdiff_t savedlastopening = lastopening; ptrdiff_t savedlastopening = lastopening;
@ -1241,11 +1222,8 @@ void R_DrawPortals ()
extralight = 0; extralight = 0;
R_SetVisibility(sky->args[0] * 0.25f); R_SetVisibility(sky->args[0] * 0.25f);
DVector3 viewpos = sky->InterpolatedPosition(r_TicFracF); ViewPos = sky->InterpolatedPosition(r_TicFracF);
viewx = FLOAT2FIXED(viewpos.X); ViewAngle = savedangle + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_TicFracF);
viewy = FLOAT2FIXED(viewpos.Y);
viewz = FLOAT2FIXED(viewpos.Z);
viewangle = savedangle + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_TicFracF).BAMs();
R_CopyStackedViewParameters(); R_CopyStackedViewParameters();
break; break;
@ -1256,10 +1234,10 @@ void R_DrawPortals ()
case PORTS_LINKEDPORTAL: case PORTS_LINKEDPORTAL:
extralight = pl->extralight; extralight = pl->extralight;
R_SetVisibility (pl->visibility); R_SetVisibility (pl->visibility);
viewx = pl->viewx + FLOAT2FIXED(port->mDisplacement.X); ViewPos.X = pl->viewpos.X + port->mDisplacement.X;
viewy = pl->viewy + FLOAT2FIXED(port->mDisplacement.Y); ViewPos.Y = pl->viewpos.Y + port->mDisplacement.Y;
viewz = pl->viewz; ViewPos.Z = pl->viewpos.Z;
viewangle = pl->viewangle; ViewAngle = pl->viewangle;
break; break;
case PORTS_HORIZON: case PORTS_HORIZON:
@ -1274,9 +1252,6 @@ void R_DrawPortals ()
continue; continue;
} }
ViewAngle = AngleToFloat(viewangle);
ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) };
port->mFlags |= PORTSF_INSKYBOX; port->mFlags |= PORTSF_INSKYBOX;
if (port->mPartner > 0) sectorPortals[port->mPartner].mFlags |= PORTSF_INSKYBOX; if (port->mPartner > 0) sectorPortals[port->mPartner].mFlags |= PORTSF_INSKYBOX;
camera = NULL; camera = NULL;
@ -1332,9 +1307,7 @@ void R_DrawPortals ()
drawsegStack.Push (diffnum); drawsegStack.Push (diffnum);
diffnum = firstvissprite - vissprites; diffnum = firstvissprite - vissprites;
visspriteStack.Push (diffnum); visspriteStack.Push (diffnum);
viewxStack.Push (viewx); viewposStack.Push(ViewPos);
viewyStack.Push (viewy);
viewzStack.Push (viewz);
visplaneStack.Push (pl); visplaneStack.Push (pl);
InSubsector = NULL; InSubsector = NULL;
@ -1357,9 +1330,9 @@ void R_DrawPortals ()
firstdrawseg = drawsegs + pd; firstdrawseg = drawsegs + pd;
visspriteStack.Pop (pd); visspriteStack.Pop (pd);
firstvissprite = vissprites + pd; firstvissprite = vissprites + pd;
viewxStack.Pop (viewx); // Masked textures and planes need the view
viewyStack.Pop (viewy); // coordinates restored for proper positioning. // Masked textures and planes need the view coordinates restored for proper positioning.
viewzStack.Pop (viewz); viewposStack.Pop(ViewPos);
R_DrawMasked (); R_DrawMasked ();
@ -1385,14 +1358,10 @@ void R_DrawPortals ()
camera = savedcamera; camera = savedcamera;
viewsector = savedsector; viewsector = savedsector;
viewx = savedx; ViewPos = savedpos;
viewy = savedy;
viewz = savedz;
R_SetVisibility (savedvisibility); R_SetVisibility (savedvisibility);
extralight = savedextralight; extralight = savedextralight;
viewangle = savedangle; ViewAngle = savedangle;
ViewAngle = AngleToFloat(viewangle);
ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) };
R_SetViewAngle (); R_SetViewAngle ();
CurrentPortalInSkybox = false; CurrentPortalInSkybox = false;
@ -1432,7 +1401,7 @@ void R_DrawSkyPlane (visplane_t *pl)
} }
sky2tex = sky2texture; sky2tex = sky2texture;
skymid = skytexturemid; skymid = skytexturemid;
skyangle = viewangle; skyangle = ViewAngle.BAMs();
if (pl->picnum == skyflatnum) if (pl->picnum == skyflatnum)
{ {
@ -1560,23 +1529,23 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
double rad = planeang * (M_PI / ANGLE_180); double rad = planeang * (M_PI / ANGLE_180);
double cosine = cos(rad), sine = sin(rad); double cosine = cos(rad), sine = sin(rad);
pviewx = xs_RoundToInt(pl->xoffs + viewx * cosine - viewy * sine); pviewx = xs_RoundToInt(pl->xoffs + FLOAT2FIXED(ViewPos.X * cosine - ViewPos.Y * sine));
pviewy = xs_RoundToInt(pl->yoffs - viewx * sine - viewy * cosine); pviewy = xs_RoundToInt(pl->yoffs - FLOAT2FIXED(ViewPos.X * sine - ViewPos.Y * cosine));
} }
else else
{ {
pviewx = pl->xoffs + viewx; pviewx = pl->xoffs + FLOAT2FIXED(ViewPos.X);
pviewy = pl->yoffs - viewy; pviewy = pl->yoffs - FLOAT2FIXED(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 - ANG90 + planeang) >> ANGLETOFINESHIFT; planeang = (ViewAngle.BAMs() - ANG90 + planeang) >> ANGLETOFINESHIFT;
// Scale will be unit scale at FocalLengthX (normally SCREENWIDTH/2) distance // Scale will be unit scale at FocalLengthX (normally SCREENWIDTH/2) distance
xstepscale = Scale (xscale, finecosine[planeang], FocalLengthX); xstepscale = fixed_t(FixedMul(xscale, finecosine[planeang]) / FocalLengthX);
ystepscale = Scale (yscale, -finesine[planeang], FocalLengthX); ystepscale = fixed_t(FixedMul(yscale, -finesine[planeang]) / FocalLengthX);
// [RH] flip for mirrors // [RH] flip for mirrors
if (MirrorFlags & RF_XFLIP) if (MirrorFlags & RF_XFLIP)
@ -1590,7 +1559,7 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
basexfrac = FixedMul (xscale, finecosine[planeang]) + x*xstepscale; basexfrac = FixedMul (xscale, finecosine[planeang]) + x*xstepscale;
baseyfrac = FixedMul (yscale, -finesine[planeang]) + x*ystepscale; baseyfrac = FixedMul (yscale, -finesine[planeang]) + x*ystepscale;
planeheight = abs (pl->height.Zat0() - viewz); planeheight = FLOAT2FIXED(fabs(pl->height.Zat0() - ViewPos.Z));
GlobVis = FixedDiv (r_FloorVisibility, planeheight); GlobVis = FixedDiv (r_FloorVisibility, planeheight);
if (fixedlightlev >= 0) if (fixedlightlev >= 0)
@ -1678,15 +1647,11 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
return; return;
} }
double vx = FIXED2DBL(viewx);
double vy = FIXED2DBL(viewy);
double vz = FIXED2DBL(viewz);
lxscale = FIXED2DBL(pl->xscale) * ifloatpow2[ds_xbits]; lxscale = FIXED2DBL(pl->xscale) * ifloatpow2[ds_xbits];
lyscale = FIXED2DBL(pl->yscale) * ifloatpow2[ds_ybits]; lyscale = FIXED2DBL(pl->yscale) * ifloatpow2[ds_ybits];
xscale = 64.f / lxscale; xscale = 64.f / lxscale;
yscale = 64.f / lyscale; yscale = 64.f / lyscale;
zeroheight = pl->height.ZatPoint(vx, vy); zeroheight = pl->height.ZatPoint(ViewPos);
pviewx = MulScale (pl->xoffs, pl->xscale, ds_xbits); pviewx = MulScale (pl->xoffs, pl->xscale, ds_xbits);
pviewy = MulScale (pl->yoffs, pl->yscale, ds_ybits); pviewy = MulScale (pl->yoffs, pl->yscale, ds_ybits);
@ -1694,13 +1659,13 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
// 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 = (ANG270 - viewangle) * (M_PI / ANGLE_180); ang = (DAngle(270.) - ViewAngle).Radians();
p[0] = vx * cos(ang) - vy * sin(ang); p[0] = ViewPos.X * cos(ang) - ViewPos.Y * sin(ang);
p[2] = vx * sin(ang) + vy * cos(ang); p[2] = ViewPos.X * sin(ang) + ViewPos.Y * cos(ang);
p[1] = pl->height.ZatPoint(0.0, 0.0) - vz; 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 = (ANG180 - viewangle - pl->angle) * (M_PI / ANGLE_180); ang = (DAngle(180.) - ViewAngle).Radians();
m[0] = yscale * cos(ang); m[0] = yscale * cos(ang);
m[2] = yscale * sin(ang); m[2] = yscale * sin(ang);
// m[1] = pl->height.ZatPointF (0, iyscale) - pl->height.ZatPointF (0,0)); // m[1] = pl->height.ZatPointF (0, iyscale) - pl->height.ZatPointF (0,0));
@ -1717,21 +1682,21 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
// 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->angle * (M_PI / ANGLE_180);
m[1] = pl->height.ZatPoint(vx + yscale * sin(ang), vy + yscale * cos(ang)) - zeroheight; m[1] = pl->height.ZatPoint(ViewPos.X + yscale * sin(ang), ViewPos.Y + yscale * cos(ang)) - zeroheight;
ang += PI/2; ang += PI/2;
n[1] = pl->height.ZatPoint(vx + xscale * sin(ang), vy + xscale * cos(ang)) - zeroheight; n[1] = pl->height.ZatPoint(ViewPos.X + xscale * sin(ang), ViewPos.Y + xscale * cos(ang)) - zeroheight;
plane_su = p ^ m; plane_su = p ^ m;
plane_sv = p ^ n; plane_sv = p ^ n;
plane_sz = m ^ n; plane_sz = m ^ n;
plane_su.Z *= FocalLengthXfloat; plane_su.Z *= FocalLengthX;
plane_sv.Z *= FocalLengthXfloat; plane_sv.Z *= FocalLengthX;
plane_sz.Z *= FocalLengthXfloat; plane_sz.Z *= FocalLengthX;
plane_su.Y *= iyaspectmulfloat; plane_su.Y *= IYaspectMul;
plane_sv.Y *= iyaspectmulfloat; plane_sv.Y *= IYaspectMul;
plane_sz.Y *= iyaspectmulfloat; plane_sz.Y *= IYaspectMul;
// Premultiply the texture vectors with the scale factors // Premultiply the texture vectors with the scale factors
plane_su *= 4294967296.f; plane_su *= 4294967296.f;
@ -1744,7 +1709,7 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
plane_sz[0] = -plane_sz[0]; plane_sz[0] = -plane_sz[0];
} }
planelightfloat = (r_TiltVisibility * lxscale * lyscale) / (fabs(pl->height.ZatPoint(FIXED2DBL(viewx), FIXED2DBL(viewy)) - FIXED2DBL(viewz))) / 65536.0; planelightfloat = (r_TiltVisibility * lxscale * lyscale) / (fabs(pl->height.ZatPoint(ViewPos)) / 65536.0);
if (pl->height.fC() > 0) if (pl->height.fC() > 0)
planelightfloat = -planelightfloat; planelightfloat = -planelightfloat;

View file

@ -51,8 +51,8 @@ struct visplane_s
// stack, then they are unused. // stack, then they are unused.
int extralight; int extralight;
float visibility; float visibility;
fixed_t viewx, viewy, viewz; DVector3 viewpos;
angle_t viewangle; DAngle viewangle;
fixed_t Alpha; fixed_t Alpha;
bool Additive; bool Additive;

View file

@ -64,7 +64,7 @@ CVAR(Bool, r_np2, true, 0)
#define HEIGHTBITS 12 #define HEIGHTBITS 12
#define HEIGHTSHIFT (FRACBITS-HEIGHTBITS) #define HEIGHTSHIFT (FRACBITS-HEIGHTBITS)
extern fixed_t globaluclip, globaldclip; extern double globaluclip, globaldclip;
PortalDrawseg* CurrentPortal = NULL; PortalDrawseg* CurrentPortal = NULL;
int CurrentPortalUniq = 0; int CurrentPortalUniq = 0;
@ -93,7 +93,7 @@ short wallupper[MAXWIDTH];
short walllower[MAXWIDTH]; short walllower[MAXWIDTH];
fixed_t swall[MAXWIDTH]; fixed_t swall[MAXWIDTH];
fixed_t lwall[MAXWIDTH]; fixed_t lwall[MAXWIDTH];
fixed_t lwallscale; double lwallscale;
// //
// regular wall // regular wall
@ -114,7 +114,7 @@ fixed_t rw_light; // [RH] Scale lights with viewsize adjustments
fixed_t rw_lightstep; fixed_t rw_lightstep;
fixed_t rw_lightleft; fixed_t rw_lightleft;
static fixed_t rw_frontlowertop; static double rw_frontlowertop;
static int rw_x; static int rw_x;
static int rw_stopx; static int rw_stopx;
@ -123,12 +123,12 @@ static fixed_t rw_scalestep;
static fixed_t rw_midtexturemid; static fixed_t rw_midtexturemid;
static fixed_t rw_toptexturemid; static fixed_t rw_toptexturemid;
static fixed_t rw_bottomtexturemid; static fixed_t rw_bottomtexturemid;
static fixed_t rw_midtexturescalex; static double rw_midtexturescalex;
static fixed_t rw_midtexturescaley; static double rw_midtexturescaley;
static fixed_t rw_toptexturescalex; static double rw_toptexturescalex;
static fixed_t rw_toptexturescaley; static double rw_toptexturescaley;
static fixed_t rw_bottomtexturescalex; static double rw_bottomtexturescalex;
static fixed_t rw_bottomtexturescaley; static double rw_bottomtexturescaley;
FTexture *rw_pic; FTexture *rw_pic;
@ -182,9 +182,9 @@ static void BlastMaskedColumn (void (*blastfunc)(const BYTE *pixels, const FText
dc_iscale = MulScale18 (MaskedSWall[dc_x], MaskedScaleY); dc_iscale = MulScale18 (MaskedSWall[dc_x], MaskedScaleY);
if (sprflipvert) if (sprflipvert)
sprtopscreen = centeryfrac + FixedMul(dc_texturemid, spryscale); sprtopscreen = FLOAT2FIXED(CenterY) + FixedMul(dc_texturemid, spryscale);
else else
sprtopscreen = centeryfrac - FixedMul(dc_texturemid, spryscale); sprtopscreen = FLOAT2FIXED(CenterY) - FixedMul(dc_texturemid, spryscale);
// killough 1/25/98: here's where Medusa came in, because // killough 1/25/98: here's where Medusa came in, because
// it implicitly assumed that the column was all one patch. // it implicitly assumed that the column was all one patch.
@ -228,7 +228,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
FTexture *tex; FTexture *tex;
int i; int i;
sector_t tempsec; // killough 4/13/98 sector_t tempsec; // killough 4/13/98
fixed_t texheight, texheightscale; double texheight, texheightscale;
bool notrelevant = false; bool notrelevant = false;
fixed_t rowoffset; fixed_t rowoffset;
@ -274,7 +274,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
{ {
if (!(fake3D & FAKE3D_CLIPTOP)) if (!(fake3D & FAKE3D_CLIPTOP))
{ {
sclipTop = sec->ceilingplane.ZatPointFixed(viewx, viewy); sclipTop = sec->ceilingplane.ZatPoint(ViewPos);
} }
for (i = frontsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) for (i = frontsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--)
{ {
@ -317,19 +317,19 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
dc_colormap = fixedcolormap; dc_colormap = fixedcolormap;
// find positioning // find positioning
texheight = tex->GetScaledHeight() << FRACBITS; texheight = tex->GetScaledHeightDouble();
texheightscale = abs(curline->sidedef->GetTextureYScale(side_t::mid)); texheightscale = fabs(curline->sidedef->GetTextureYScaleF(side_t::mid));
if (texheightscale != FRACUNIT) if (texheightscale != 1)
{ {
texheight = FixedDiv(texheight, texheightscale); texheight = texheight / texheightscale;
} }
if (curline->linedef->flags & ML_DONTPEGBOTTOM) if (curline->linedef->flags & ML_DONTPEGBOTTOM)
{ {
dc_texturemid = MAX (frontsector->GetPlaneTexZ(sector_t::floor), backsector->GetPlaneTexZ(sector_t::floor)) + texheight; dc_texturemid = FLOAT2FIXED(MAX(frontsector->GetPlaneTexZF(sector_t::floor), backsector->GetPlaneTexZF(sector_t::floor)) + texheight);
} }
else else
{ {
dc_texturemid = MIN (frontsector->GetPlaneTexZ(sector_t::ceiling), backsector->GetPlaneTexZ(sector_t::ceiling)); dc_texturemid = FLOAT2FIXED(MIN(frontsector->GetPlaneTexZF(sector_t::ceiling), backsector->GetPlaneTexZF(sector_t::ceiling)));
} }
rowoffset = curline->sidedef->GetTextureYOffset(side_t::mid); rowoffset = curline->sidedef->GetTextureYOffset(side_t::mid);
@ -337,7 +337,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
if (!(curline->linedef->flags & ML_WRAP_MIDTEX) && if (!(curline->linedef->flags & ML_WRAP_MIDTEX) &&
!(curline->sidedef->Flags & WALLF_WRAP_MIDTEX)) !(curline->sidedef->Flags & WALLF_WRAP_MIDTEX))
{ // Texture does not wrap vertically. { // Texture does not wrap vertically.
fixed_t textop; double textop;
if (MaskedScaleY < 0) if (MaskedScaleY < 0)
{ {
@ -348,16 +348,16 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
{ {
// rowoffset is added before the MulScale3 so that the masked texture will // rowoffset is added before the MulScale3 so that the masked texture will
// still be positioned in world units rather than texels. // still be positioned in world units rather than texels.
dc_texturemid += rowoffset - viewz; dc_texturemid += rowoffset - FLOAT2FIXED(ViewPos.Z);
textop = dc_texturemid; textop = FIXED2FLOAT(dc_texturemid);
dc_texturemid = MulScale16 (dc_texturemid, MaskedScaleY); dc_texturemid = MulScale16 (dc_texturemid, MaskedScaleY);
} }
else else
{ {
// rowoffset is added outside the multiply so that it positions the texture // rowoffset is added outside the multiply so that it positions the texture
// by texels instead of world units. // by texels instead of world units.
textop = dc_texturemid - viewz + SafeDivScale16 (rowoffset, MaskedScaleY); textop = FIXED2FLOAT(dc_texturemid + SafeDivScale16 (rowoffset, MaskedScaleY)) - ViewPos.Z;
dc_texturemid = MulScale16 (dc_texturemid - viewz, MaskedScaleY) + rowoffset; dc_texturemid = MulScale16 (dc_texturemid - FLOAT2FIXED(ViewPos.Z), MaskedScaleY) + rowoffset;
} }
if (sprflipvert) if (sprflipvert)
{ {
@ -366,24 +366,22 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
} }
// [RH] Don't bother drawing segs that are completely offscreen // [RH] Don't bother drawing segs that are completely offscreen
if (MulScale12 (globaldclip, ds->sz1) < -textop && if (globaldclip * ds->sz1 < -textop && globaldclip * ds->sz2 < -textop)
MulScale12 (globaldclip, ds->sz2) < -textop)
{ // Texture top is below the bottom of the screen { // Texture top is below the bottom of the screen
goto clearfog; goto clearfog;
} }
if (MulScale12 (globaluclip, ds->sz1) > texheight - textop && if (globaluclip * ds->sz1 > texheight - textop && globaluclip * ds->sz2 > texheight - textop)
MulScale12 (globaluclip, ds->sz2) > texheight - textop)
{ // Texture bottom is above the top of the screen { // Texture bottom is above the top of the screen
goto clearfog; goto clearfog;
} }
if ((fake3D & FAKE3D_CLIPBOTTOM) && textop < sclipBottom - viewz) if ((fake3D & FAKE3D_CLIPBOTTOM) && textop < sclipBottom - ViewPos.Z)
{ {
notrelevant = true; notrelevant = true;
goto clearfog; goto clearfog;
} }
if ((fake3D & FAKE3D_CLIPTOP) && textop - texheight > sclipTop - viewz) if ((fake3D & FAKE3D_CLIPTOP) && textop - texheight > sclipTop - ViewPos.Z)
{ {
notrelevant = true; notrelevant = true;
goto clearfog; goto clearfog;
@ -396,7 +394,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
if (fake3D & FAKE3D_CLIPTOP) if (fake3D & FAKE3D_CLIPTOP)
{ {
OWallMost(wallupper, textop < sclipTop - viewz ? textop : sclipTop - viewz, &WallC); OWallMost(wallupper, textop < sclipTop - ViewPos.Z ? textop : sclipTop - ViewPos.Z, &WallC);
} }
else else
{ {
@ -404,7 +402,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
} }
if (fake3D & FAKE3D_CLIPBOTTOM) if (fake3D & FAKE3D_CLIPBOTTOM)
{ {
OWallMost(walllower, textop - texheight > sclipBottom - viewz ? textop - texheight : sclipBottom - viewz, &WallC); OWallMost(walllower, textop - texheight > sclipBottom - ViewPos.Z ? textop - texheight : sclipBottom - ViewPos.Z, &WallC);
} }
else else
{ {
@ -484,14 +482,14 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
{ {
// rowoffset is added before the MulScale3 so that the masked texture will // rowoffset is added before the MulScale3 so that the masked texture will
// still be positioned in world units rather than texels. // still be positioned in world units rather than texels.
dc_texturemid += rowoffset - viewz; dc_texturemid += rowoffset - FLOAT2FIXED(ViewPos.Z);
dc_texturemid = MulScale16 (dc_texturemid, MaskedScaleY); dc_texturemid = MulScale16 (dc_texturemid, MaskedScaleY);
} }
else else
{ {
// rowoffset is added outside the multiply so that it positions the texture // rowoffset is added outside the multiply so that it positions the texture
// by texels instead of world units. // by texels instead of world units.
dc_texturemid = MulScale16 (dc_texturemid - viewz, MaskedScaleY) + rowoffset; dc_texturemid = MulScale16 (dc_texturemid - FLOAT2FIXED(ViewPos.Z), MaskedScaleY) + rowoffset;
} }
WallC.sz1 = ds->sz1; WallC.sz1 = ds->sz1;
@ -512,7 +510,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
if (fake3D & FAKE3D_CLIPTOP) if (fake3D & FAKE3D_CLIPTOP)
{ {
OWallMost(wallupper, sclipTop - viewz, &WallC); OWallMost(wallupper, sclipTop - ViewPos.Z, &WallC);
for (i = x1; i < x2; i++) for (i = x1; i < x2; i++)
{ {
if (wallupper[i] < mceilingclip[i]) if (wallupper[i] < mceilingclip[i])
@ -522,7 +520,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
} }
if (fake3D & FAKE3D_CLIPBOTTOM) if (fake3D & FAKE3D_CLIPBOTTOM)
{ {
OWallMost(walllower, sclipBottom - viewz, &WallC); OWallMost(walllower, sclipBottom - ViewPos.Z, &WallC);
for (i = x1; i < x2; i++) for (i = x1; i < x2; i++)
{ {
if (walllower[i] > mfloorclip[i]) if (walllower[i] > mfloorclip[i])
@ -561,7 +559,8 @@ clearfog:
void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover) void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover)
{ {
int i; int i;
fixed_t xscale, yscale; fixed_t xscale;
double yscale;
fixed_t Alpha = Scale(rover->alpha, OPAQUE, 255); fixed_t Alpha = Scale(rover->alpha, OPAQUE, 255);
ESPSResult drawmode; ESPSResult drawmode;
@ -602,28 +601,29 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover)
scaledpart = side_t::mid; scaledpart = side_t::mid;
} }
xscale = fixed_t(rw_pic->Scale.X * scaledside->GetTextureXScale(scaledpart)); xscale = fixed_t(rw_pic->Scale.X * scaledside->GetTextureXScale(scaledpart));
yscale = fixed_t(rw_pic->Scale.Y * scaledside->GetTextureYScale(scaledpart)); yscale = rw_pic->Scale.Y * scaledside->GetTextureYScale(scaledpart);
fixed_t rowoffset = curline->sidedef->GetTextureYOffset(side_t::mid) + rover->master->sidedef[0]->GetTextureYOffset(side_t::mid); fixed_t rowoffset = curline->sidedef->GetTextureYOffset(side_t::mid) + rover->master->sidedef[0]->GetTextureYOffset(side_t::mid);
dc_texturemid = rover->model->GetPlaneTexZ(sector_t::ceiling); double planez = rover->model->GetPlaneTexZF(sector_t::ceiling);
rw_offset = curline->sidedef->GetTextureXOffset(side_t::mid) + rover->master->sidedef[0]->GetTextureXOffset(side_t::mid); rw_offset = curline->sidedef->GetTextureXOffset(side_t::mid) + rover->master->sidedef[0]->GetTextureXOffset(side_t::mid);
if (rowoffset < 0) if (rowoffset < 0)
{ {
rowoffset += rw_pic->GetHeight() << FRACBITS; rowoffset += rw_pic->GetHeight() << FRACBITS;
} }
dc_texturemid = FLOAT2FIXED((planez - ViewPos.Z) * yscale);
if (rw_pic->bWorldPanning) if (rw_pic->bWorldPanning)
{ {
// rowoffset is added before the MulScale3 so that the masked texture will // rowoffset is added before the MulScale3 so that the masked texture will
// still be positioned in world units rather than texels. // still be positioned in world units rather than texels.
dc_texturemid = MulScale16(dc_texturemid - viewz + rowoffset, yscale); dc_texturemid += xs_FloorToInt(rowoffset * yscale);
rw_offset = MulScale16 (rw_offset, xscale); rw_offset = MulScale16 (rw_offset, xscale); ///Is this really supposed to be xscale and not yscale?
} }
else else
{ {
// rowoffset is added outside the multiply so that it positions the texture // rowoffset is added outside the multiply so that it positions the texture
// by texels instead of world units. // by texels instead of world units.
dc_texturemid = MulScale16(dc_texturemid - viewz, yscale) + rowoffset; dc_texturemid += rowoffset;
} }
if (fixedlightlev >= 0) if (fixedlightlev >= 0)
@ -635,14 +635,14 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover)
WallC.sz2 = ds->sz2; WallC.sz2 = ds->sz2;
WallC.sx1 = ds->sx1; WallC.sx1 = ds->sx1;
WallC.sx2 = ds->sx2; WallC.sx2 = ds->sx2;
WallC.tx1 = ds->cx; WallC.tleft.X = ds->cx;
WallC.ty1 = ds->cy; WallC.tleft.Y = ds->cy;
WallC.tx2 = ds->cx + ds->cdx; WallC.tright.X = ds->cx + ds->cdx;
WallC.ty2 = ds->cy + ds->cdy; WallC.tright.Y = ds->cy + ds->cdy;
WallT = ds->tmapvals; WallT = ds->tmapvals;
OWallMost(wallupper, sclipTop - viewz, &WallC); OWallMost(wallupper, sclipTop - ViewPos.Z, &WallC);
OWallMost(walllower, sclipBottom - viewz, &WallC); OWallMost(walllower, sclipBottom - ViewPos.Z, &WallC);
for (i = x1; i < x2; i++) for (i = x1; i < x2; i++)
{ {
@ -656,7 +656,7 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover)
} }
PrepLWall (lwall, curline->sidedef->TexelLength*xscale, ds->sx1, ds->sx2); PrepLWall (lwall, curline->sidedef->TexelLength*xscale, ds->sx1, ds->sx2);
wallscan_np2_ds(ds, x1, x2, wallupper, walllower, MaskedSWall, lwall, yscale); wallscan_np2_ds(ds, x1, x2, wallupper, walllower, MaskedSWall, lwall, FLOAT2FIXED(yscale));
R_FinishSetPatchStyle(); R_FinishSetPatchStyle();
} }
@ -1104,6 +1104,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t
texturemid = dc_texturemid << (16 - shiftval); texturemid = dc_texturemid << (16 - shiftval);
xoffset = rw_offset; xoffset = rw_offset;
basecolormapdata = basecolormap->Maps; basecolormapdata = basecolormap->Maps;
fixed_t centeryfrac = FLOAT2FIXED(CenterY);
x = x1; x = x1;
//while ((umost[x] > dmost[x]) && (x < x2)) x++; //while ((umost[x] > dmost[x]) && (x < x2)) x++;
@ -1316,7 +1317,7 @@ static void call_wallscan(int x1, int x2, short *uwal, short *dwal, fixed_t *swa
// //
//============================================================================= //=============================================================================
void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat, fixed_t top, fixed_t bot, bool mask) void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat, fixed_t itop, fixed_t ibot, bool mask)
{ {
if (!r_np2) if (!r_np2)
{ {
@ -1327,18 +1328,24 @@ void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed
short most1[MAXWIDTH], most2[MAXWIDTH], most3[MAXWIDTH]; short most1[MAXWIDTH], most2[MAXWIDTH], most3[MAXWIDTH];
short *up, *down; short *up, *down;
fixed_t texheight = rw_pic->GetHeight() << FRACBITS; fixed_t texheight = rw_pic->GetHeight() << FRACBITS;
fixed_t scaledtexheight = FixedDiv(texheight, yrepeat); double scaledtexheight = FIXED2FLOAT(FixedDiv(texheight, yrepeat));
fixed_t partition; double partition;
double top = FIXED2FLOAT(itop);
double bot = FIXED2FLOAT(ibot);
if (yrepeat >= 0) if (yrepeat >= 0)
{ // normal orientation: draw strips from top to bottom { // normal orientation: draw strips from top to bottom
partition = top - (top - FixedDiv(dc_texturemid, yrepeat) - viewz) % scaledtexheight; partition = top - fmod(top - FIXED2FLOAT(FixedDiv(dc_texturemid, yrepeat)) - ViewPos.Z, scaledtexheight);
if (partition == top)
{
partition -= scaledtexheight;
}
up = uwal; up = uwal;
down = most1; down = most1;
dc_texturemid = FixedMul(partition - viewz, yrepeat) + texheight; dc_texturemid = xs_RoundToInt((partition - ViewPos.Z) * yrepeat + texheight);
while (partition > bot) while (partition > bot)
{ {
int j = OWallMost(most3, partition - viewz, &WallC); int j = OWallMost(most3, partition - ViewPos.Z, &WallC);
if (j != 3) if (j != 3)
{ {
for (int j = x1; j < x2; ++j) for (int j = x1; j < x2; ++j)
@ -1356,13 +1363,13 @@ void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed
} }
else else
{ // upside down: draw strips from bottom to top { // upside down: draw strips from bottom to top
partition = bot - (bot - FixedDiv(dc_texturemid, yrepeat) - viewz) % scaledtexheight; partition = bot - fmod(bot - FIXED2FLOAT(FixedDiv(dc_texturemid, yrepeat)) - ViewPos.Z, scaledtexheight);
up = most1; up = most1;
down = dwal; down = dwal;
dc_texturemid = FixedMul(partition - viewz, yrepeat) + texheight; dc_texturemid = xs_RoundToInt((partition - ViewPos.Z) * yrepeat + texheight);
while (partition < top) while (partition < top)
{ {
int j = OWallMost(most3, partition - viewz, &WallC); int j = OWallMost(most3, partition - ViewPos.Z, &WallC);
if (j != 12) if (j != 12)
{ {
for (int j = x1; j < x2; ++j) for (int j = x1; j < x2; ++j)
@ -1385,12 +1392,12 @@ static void wallscan_np2_ds(drawseg_t *ds, int x1, int x2, short *uwal, short *d
{ {
if (rw_pic->GetHeight() != 1 << rw_pic->HeightBits) if (rw_pic->GetHeight() != 1 << rw_pic->HeightBits)
{ {
fixed_t frontcz1 = ds->curline->frontsector->ceilingplane.ZatPointFixed(ds->curline->v1); double frontcz1 = ds->curline->frontsector->ceilingplane.ZatPoint(ds->curline->v1);
fixed_t frontfz1 = ds->curline->frontsector->floorplane.ZatPointFixed(ds->curline->v1); double frontfz1 = ds->curline->frontsector->floorplane.ZatPoint(ds->curline->v1);
fixed_t frontcz2 = ds->curline->frontsector->ceilingplane.ZatPointFixed(ds->curline->v2); double frontcz2 = ds->curline->frontsector->ceilingplane.ZatPoint(ds->curline->v2);
fixed_t frontfz2 = ds->curline->frontsector->floorplane.ZatPointFixed(ds->curline->v2); double frontfz2 = ds->curline->frontsector->floorplane.ZatPoint(ds->curline->v2);
fixed_t top = MAX(frontcz1, frontcz2); double top = MAX(frontcz1, frontcz2);
fixed_t bot = MIN(frontfz1, frontfz2); double bot = MIN(frontfz1, frontfz2);
if (fake3D & FAKE3D_CLIPTOP) if (fake3D & FAKE3D_CLIPTOP)
{ {
top = MIN(top, sclipTop); top = MIN(top, sclipTop);
@ -1399,7 +1406,7 @@ static void wallscan_np2_ds(drawseg_t *ds, int x1, int x2, short *uwal, short *d
{ {
bot = MAX(bot, sclipBottom); bot = MAX(bot, sclipBottom);
} }
wallscan_np2(x1, x2, uwal, dwal, swal, lwal, yrepeat, top, bot, true); wallscan_np2(x1, x2, uwal, dwal, swal, lwal, yrepeat, FLOAT2FIXED(top), FLOAT2FIXED(bot), true);
} }
else else
{ {
@ -1450,6 +1457,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe
texturemid = dc_texturemid << (16 - shiftval); texturemid = dc_texturemid << (16 - shiftval);
xoffset = rw_offset; xoffset = rw_offset;
basecolormapdata = basecolormap->Maps; basecolormapdata = basecolormap->Maps;
fixed_t centeryfrac = FLOAT2FIXED(CenterY);
x = startx = x1; x = startx = x1;
p = x + dc_destorg; p = x + dc_destorg;
@ -1623,6 +1631,7 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal,
texturemid = dc_texturemid << (16 - shiftval); texturemid = dc_texturemid << (16 - shiftval);
xoffset = rw_offset; xoffset = rw_offset;
basecolormapdata = basecolormap->Maps; basecolormapdata = basecolormap->Maps;
fixed_t centeryfrac = FLOAT2FIXED(CenterY);
x = startx = x1; x = startx = x1;
p = x + dc_destorg; p = x + dc_destorg;
@ -1769,7 +1778,8 @@ void R_RenderSegLoop ()
int x1 = rw_x; int x1 = rw_x;
int x2 = rw_stopx; int x2 = rw_stopx;
int x; int x;
fixed_t xscale, yscale; double xscale;
fixed_t yscale;
fixed_t xoffset = rw_offset; fixed_t xoffset = rw_offset;
if (fixedlightlev >= 0) if (fixedlightlev >= 0)
@ -1858,8 +1868,8 @@ void R_RenderSegLoop ()
{ {
dc_texturemid = rw_midtexturemid; dc_texturemid = rw_midtexturemid;
rw_pic = midtexture; rw_pic = midtexture;
xscale = fixed_t(rw_pic->Scale.X * rw_midtexturescalex); xscale = rw_pic->Scale.X * rw_midtexturescalex;
yscale = fixed_t(rw_pic->Scale.Y * rw_midtexturescaley); yscale = FLOAT2FIXED(rw_pic->Scale.Y * rw_midtexturescaley);
if (xscale != lwallscale) if (xscale != lwallscale)
{ {
PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2); PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2);
@ -1867,7 +1877,7 @@ void R_RenderSegLoop ()
} }
if (midtexture->bWorldPanning) if (midtexture->bWorldPanning)
{ {
rw_offset = MulScale16 (rw_offset_mid, xscale); rw_offset = xs_RoundToInt(rw_offset_mid * xscale);
} }
else else
{ {
@ -1901,8 +1911,8 @@ void R_RenderSegLoop ()
{ {
dc_texturemid = rw_toptexturemid; dc_texturemid = rw_toptexturemid;
rw_pic = toptexture; rw_pic = toptexture;
xscale = fixed_t(rw_pic->Scale.X * rw_toptexturescalex); xscale = rw_pic->Scale.X * rw_toptexturescalex;
yscale = fixed_t(rw_pic->Scale.Y * rw_toptexturescaley); yscale = FLOAT2FIXED(rw_pic->Scale.Y * rw_toptexturescaley);
if (xscale != lwallscale) if (xscale != lwallscale)
{ {
PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2); PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2);
@ -1910,7 +1920,7 @@ void R_RenderSegLoop ()
} }
if (toptexture->bWorldPanning) if (toptexture->bWorldPanning)
{ {
rw_offset = MulScale16 (rw_offset_top, xscale); rw_offset = xs_RoundToInt(rw_offset_top * xscale);
} }
else else
{ {
@ -1947,8 +1957,8 @@ void R_RenderSegLoop ()
{ {
dc_texturemid = rw_bottomtexturemid; dc_texturemid = rw_bottomtexturemid;
rw_pic = bottomtexture; rw_pic = bottomtexture;
xscale = fixed_t(rw_pic->Scale.X * rw_bottomtexturescalex); xscale = rw_pic->Scale.X * rw_bottomtexturescalex;
yscale = fixed_t(rw_pic->Scale.Y * rw_bottomtexturescaley); yscale = FLOAT2FIXED(rw_pic->Scale.Y * rw_bottomtexturescaley);
if (xscale != lwallscale) if (xscale != lwallscale)
{ {
PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2); PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2);
@ -1956,7 +1966,7 @@ void R_RenderSegLoop ()
} }
if (bottomtexture->bWorldPanning) if (bottomtexture->bWorldPanning)
{ {
rw_offset = MulScale16 (rw_offset_bottom, xscale); rw_offset = xs_RoundToInt(rw_offset_bottom * xscale);
} }
else else
{ {
@ -1987,7 +1997,8 @@ void R_RenderSegLoop ()
void R_NewWall (bool needlights) void R_NewWall (bool needlights)
{ {
fixed_t rowoffset, yrepeat; fixed_t rowoffset;
double yrepeat;
rw_markportal = false; rw_markportal = false;
@ -2016,18 +2027,18 @@ void R_NewWall (bool needlights)
midtexture = TexMan(sidedef->GetTexture(side_t::mid), true); midtexture = TexMan(sidedef->GetTexture(side_t::mid), true);
rw_offset_mid = sidedef->GetTextureXOffset(side_t::mid); rw_offset_mid = sidedef->GetTextureXOffset(side_t::mid);
rowoffset = sidedef->GetTextureYOffset(side_t::mid); rowoffset = sidedef->GetTextureYOffset(side_t::mid);
rw_midtexturescalex = sidedef->GetTextureXScale(side_t::mid); rw_midtexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::mid));
rw_midtexturescaley = sidedef->GetTextureYScale(side_t::mid); rw_midtexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::mid));
yrepeat = fixed_t(midtexture->Scale.Y * rw_midtexturescaley); yrepeat = midtexture->Scale.Y * rw_midtexturescaley;
if (yrepeat >= 0) if (yrepeat >= 0)
{ // normal orientation { // normal orientation
if (linedef->flags & ML_DONTPEGBOTTOM) if (linedef->flags & ML_DONTPEGBOTTOM)
{ // bottom of texture at bottom { // bottom of texture at bottom
rw_midtexturemid = MulScale16(frontsector->GetPlaneTexZ(sector_t::floor) - viewz, yrepeat) + (midtexture->GetHeight() << FRACBITS); rw_midtexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::floor) - ViewPos.Z) * yrepeat + midtexture->GetHeight());
} }
else else
{ // top of texture at top { // top of texture at top
rw_midtexturemid = MulScale16(frontsector->GetPlaneTexZ(sector_t::ceiling) - viewz, yrepeat); rw_midtexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat);
if (rowoffset < 0 && midtexture != NULL) if (rowoffset < 0 && midtexture != NULL)
{ {
rowoffset += midtexture->GetHeight() << FRACBITS; rowoffset += midtexture->GetHeight() << FRACBITS;
@ -2039,16 +2050,16 @@ void R_NewWall (bool needlights)
rowoffset = -rowoffset; rowoffset = -rowoffset;
if (linedef->flags & ML_DONTPEGBOTTOM) if (linedef->flags & ML_DONTPEGBOTTOM)
{ // top of texture at bottom { // top of texture at bottom
rw_midtexturemid = MulScale16(frontsector->GetPlaneTexZ(sector_t::floor) - viewz, yrepeat); rw_midtexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::floor) - ViewPos.Z) * yrepeat);
} }
else else
{ // bottom of texture at top { // bottom of texture at top
rw_midtexturemid = MulScale16(frontsector->GetPlaneTexZ(sector_t::ceiling) - viewz, yrepeat) + (midtexture->GetHeight() << FRACBITS); rw_midtexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZ(sector_t::ceiling) - ViewPos.Z) * yrepeat + midtexture->GetHeight());
} }
} }
if (midtexture->bWorldPanning) if (midtexture->bWorldPanning)
{ {
rw_midtexturemid += MulScale16(rowoffset, yrepeat); rw_midtexturemid += xs_FloorToInt(rowoffset * yrepeat);
} }
else else
{ {
@ -2062,7 +2073,7 @@ void R_NewWall (bool needlights)
{ // two-sided line { // two-sided line
// hack to allow height changes in outdoor areas // hack to allow height changes in outdoor areas
rw_frontlowertop = frontsector->GetPlaneTexZ(sector_t::ceiling); rw_frontlowertop = frontsector->GetPlaneTexZF(sector_t::ceiling);
if (frontsector->GetTexture(sector_t::ceiling) == skyflatnum && if (frontsector->GetTexture(sector_t::ceiling) == skyflatnum &&
backsector->GetTexture(sector_t::ceiling) == skyflatnum) backsector->GetTexture(sector_t::ceiling) == skyflatnum)
@ -2083,7 +2094,7 @@ void R_NewWall (bool needlights)
} }
// Putting sky ceilings on the front and back of a line alters the way unpegged // Putting sky ceilings on the front and back of a line alters the way unpegged
// positioning works. // positioning works.
rw_frontlowertop = backsector->GetPlaneTexZ(sector_t::ceiling); rw_frontlowertop = backsector->GetPlaneTexZF(sector_t::ceiling);
} }
if ((rw_backcz1 <= rw_frontfz1 && rw_backcz2 <= rw_frontfz2) || if ((rw_backcz1 <= rw_frontfz1 && rw_backcz2 <= rw_frontfz2) ||
@ -2171,14 +2182,14 @@ void R_NewWall (bool needlights)
rw_offset_top = sidedef->GetTextureXOffset(side_t::top); rw_offset_top = sidedef->GetTextureXOffset(side_t::top);
rowoffset = sidedef->GetTextureYOffset(side_t::top); rowoffset = sidedef->GetTextureYOffset(side_t::top);
rw_toptexturescalex = sidedef->GetTextureXScale(side_t::top); rw_toptexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::top));
rw_toptexturescaley = sidedef->GetTextureYScale(side_t::top); rw_toptexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::top));
yrepeat = fixed_t(toptexture->Scale.Y * rw_toptexturescaley); yrepeat = toptexture->Scale.Y * rw_toptexturescaley;
if (yrepeat >= 0) if (yrepeat >= 0)
{ // normal orientation { // normal orientation
if (linedef->flags & ML_DONTPEGTOP) if (linedef->flags & ML_DONTPEGTOP)
{ // top of texture at top { // top of texture at top
rw_toptexturemid = MulScale16(frontsector->GetPlaneTexZ(sector_t::ceiling) - viewz, yrepeat); rw_toptexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat);
if (rowoffset < 0 && toptexture != NULL) if (rowoffset < 0 && toptexture != NULL)
{ {
rowoffset += toptexture->GetHeight() << FRACBITS; rowoffset += toptexture->GetHeight() << FRACBITS;
@ -2186,7 +2197,7 @@ void R_NewWall (bool needlights)
} }
else else
{ // bottom of texture at bottom { // bottom of texture at bottom
rw_toptexturemid = MulScale16(backsector->GetPlaneTexZ(sector_t::ceiling) - viewz, yrepeat) + (toptexture->GetHeight() << FRACBITS); rw_toptexturemid = FLOAT2FIXED((backsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat + toptexture->GetHeight());
} }
} }
else else
@ -2194,16 +2205,16 @@ void R_NewWall (bool needlights)
rowoffset = -rowoffset; rowoffset = -rowoffset;
if (linedef->flags & ML_DONTPEGTOP) if (linedef->flags & ML_DONTPEGTOP)
{ // bottom of texture at top { // bottom of texture at top
rw_toptexturemid = MulScale16(frontsector->GetPlaneTexZ(sector_t::ceiling) - viewz, yrepeat) + (toptexture->GetHeight() << FRACBITS); rw_toptexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat + toptexture->GetHeight());
} }
else else
{ // top of texture at bottom { // top of texture at bottom
rw_toptexturemid = MulScale16(backsector->GetPlaneTexZ(sector_t::ceiling) - viewz, yrepeat); rw_toptexturemid = FLOAT2FIXED((backsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat);
} }
} }
if (toptexture->bWorldPanning) if (toptexture->bWorldPanning)
{ {
rw_toptexturemid += MulScale16(rowoffset, yrepeat); rw_toptexturemid += xs_FloorToInt(rowoffset * yrepeat);
} }
else else
{ {
@ -2216,18 +2227,18 @@ void R_NewWall (bool needlights)
rw_offset_bottom = sidedef->GetTextureXOffset(side_t::bottom); rw_offset_bottom = sidedef->GetTextureXOffset(side_t::bottom);
rowoffset = sidedef->GetTextureYOffset(side_t::bottom); rowoffset = sidedef->GetTextureYOffset(side_t::bottom);
rw_bottomtexturescalex = sidedef->GetTextureXScale(side_t::bottom); rw_bottomtexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::bottom));
rw_bottomtexturescaley = sidedef->GetTextureYScale(side_t::bottom); rw_bottomtexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::bottom));
yrepeat = fixed_t(bottomtexture->Scale.Y * rw_bottomtexturescaley); yrepeat = fixed_t(bottomtexture->Scale.Y * rw_bottomtexturescaley);
if (yrepeat >= 0) if (yrepeat >= 0)
{ // normal orientation { // normal orientation
if (linedef->flags & ML_DONTPEGBOTTOM) if (linedef->flags & ML_DONTPEGBOTTOM)
{ // bottom of texture at bottom { // bottom of texture at bottom
rw_bottomtexturemid = MulScale16(rw_frontlowertop - viewz, yrepeat); rw_bottomtexturemid = FLOAT2FIXED((rw_frontlowertop - ViewPos.Z) * yrepeat);
} }
else else
{ // top of texture at top { // top of texture at top
rw_bottomtexturemid = MulScale16(backsector->GetPlaneTexZ(sector_t::floor) - viewz, yrepeat); rw_bottomtexturemid = FLOAT2FIXED((backsector->GetPlaneTexZF(sector_t::floor) - ViewPos.Z) * yrepeat);
if (rowoffset < 0 && bottomtexture != NULL) if (rowoffset < 0 && bottomtexture != NULL)
{ {
rowoffset += bottomtexture->GetHeight() << FRACBITS; rowoffset += bottomtexture->GetHeight() << FRACBITS;
@ -2239,16 +2250,16 @@ void R_NewWall (bool needlights)
rowoffset = -rowoffset; rowoffset = -rowoffset;
if (linedef->flags & ML_DONTPEGBOTTOM) if (linedef->flags & ML_DONTPEGBOTTOM)
{ // top of texture at bottom { // top of texture at bottom
rw_bottomtexturemid = MulScale16(rw_frontlowertop - viewz, yrepeat); rw_bottomtexturemid = FLOAT2FIXED((rw_frontlowertop - ViewPos.Z) * yrepeat);
} }
else else
{ // bottom of texture at top { // bottom of texture at top
rw_bottomtexturemid = MulScale16(backsector->GetPlaneTexZ(sector_t::floor) - viewz, yrepeat) + (bottomtexture->GetHeight() << FRACBITS); rw_bottomtexturemid = FLOAT2FIXED((backsector->GetPlaneTexZ(sector_t::floor) - ViewPos.Z) * yrepeat + bottomtexture->GetHeight());
} }
} }
if (bottomtexture->bWorldPanning) if (bottomtexture->bWorldPanning)
{ {
rw_bottomtexturemid += MulScale16(rowoffset, yrepeat); rw_bottomtexturemid += xs_FloorToInt(rowoffset * yrepeat);
} }
else else
{ {
@ -2265,7 +2276,7 @@ void R_NewWall (bool needlights)
{ {
int planeside; int planeside;
planeside = frontsector->floorplane.PointOnSide(viewx, viewy, viewz); planeside = frontsector->floorplane.PointOnSide(ViewPos);
if (frontsector->floorplane.fC() < 0) // 3D floors have the floor backwards if (frontsector->floorplane.fC() < 0) // 3D floors have the floor backwards
planeside = -planeside; planeside = -planeside;
if (planeside <= 0) // above view plane if (planeside <= 0) // above view plane
@ -2273,7 +2284,7 @@ void R_NewWall (bool needlights)
if (frontsector->GetTexture(sector_t::ceiling) != skyflatnum) if (frontsector->GetTexture(sector_t::ceiling) != skyflatnum)
{ {
planeside = frontsector->ceilingplane.PointOnSide(viewx, viewy, viewz); planeside = frontsector->ceilingplane.PointOnSide(ViewPos);
if (frontsector->ceilingplane.fC() > 0) // 3D floors have the ceiling backwards if (frontsector->ceilingplane.fC() > 0) // 3D floors have the ceiling backwards
planeside = -planeside; planeside = -planeside;
if (planeside <= 0) // below view plane if (planeside <= 0) // below view plane
@ -2289,9 +2300,9 @@ void R_NewWall (bool needlights)
if (needlights && (segtextured || (backsector && IsFogBoundary(frontsector, backsector)))) if (needlights && (segtextured || (backsector && IsFogBoundary(frontsector, backsector))))
{ {
lwallscale = lwallscale =
midtex ? int(midtex->Scale.X * sidedef->GetTextureXScale(side_t::mid)) : midtex ? (midtex->Scale.X * sidedef->GetTextureXScale(side_t::mid) / 65536.0) :
toptexture ? int(toptexture->Scale.X * sidedef->GetTextureXScale(side_t::top)) : toptexture ? (toptexture->Scale.X * sidedef->GetTextureXScale(side_t::top) / 65536.0) :
bottomtexture ? int(bottomtexture->Scale.X * sidedef->GetTextureXScale(side_t::bottom)) : bottomtexture ? (bottomtexture->Scale.X * sidedef->GetTextureXScale(side_t::bottom) / 65536.0) :
FRACUNIT; FRACUNIT;
PrepWall (swall, lwall, sidedef->TexelLength * lwallscale, WallC.sx1, WallC.sx2); PrepWall (swall, lwall, sidedef->TexelLength * lwallscale, WallC.sx1, WallC.sx2);
@ -2301,8 +2312,8 @@ void R_NewWall (bool needlights)
wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, frontsector->lightlevel) wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, frontsector->lightlevel)
+ r_actualextralight); + r_actualextralight);
GlobVis = r_WallVisibility; GlobVis = r_WallVisibility;
rw_lightleft = SafeDivScale12 (GlobVis, WallC.sz1); rw_lightleft = FLOAT2FIXED(FIXED2DBL(GlobVis) / WallC.sz1);
rw_lightstep = (SafeDivScale12 (GlobVis, WallC.sz2) - rw_lightleft) / (WallC.sx2 - WallC.sx1); rw_lightstep = (FLOAT2FIXED(FIXED2DBL(GlobVis) / WallC.sz2) - rw_lightleft) / (WallC.sx2 - WallC.sx1);
} }
else else
{ {
@ -2383,13 +2394,13 @@ void R_StoreWallRange (int start, int stop)
ds_p->sx2 = WallC.sx2; ds_p->sx2 = WallC.sx2;
ds_p->sz1 = WallC.sz1; ds_p->sz1 = WallC.sz1;
ds_p->sz2 = WallC.sz2; ds_p->sz2 = WallC.sz2;
ds_p->cx = WallC.tx1; ds_p->cx = WallC.tleft.X;;
ds_p->cy = WallC.ty1; ds_p->cy = WallC.tleft.Y;
ds_p->cdx = WallC.tx2 - WallC.tx1; ds_p->cdx = WallC.tright.X - WallC.tleft.X;
ds_p->cdy = WallC.ty2 - WallC.ty1; ds_p->cdy = WallC.tright.Y - WallC.tleft.Y;
ds_p->tmapvals = WallT; ds_p->tmapvals = WallT;
ds_p->siz1 = (DWORD)DivScale32 (1, WallC.sz1) >> 1; ds_p->siz1 = 1 / WallC.sz1;
ds_p->siz2 = (DWORD)DivScale32 (1, WallC.sz2) >> 1; ds_p->siz2 = 1 / WallC.sz2;
ds_p->x1 = rw_x = start; ds_p->x1 = rw_x = start;
ds_p->x2 = stop; ds_p->x2 = stop;
ds_p->curline = curline; ds_p->curline = curline;
@ -2420,13 +2431,13 @@ void R_StoreWallRange (int start, int stop)
ds_p->silhouette = 0; ds_p->silhouette = 0;
if (rw_frontfz1 > rw_backfz1 || rw_frontfz2 > rw_backfz2 || if (rw_frontfz1 > rw_backfz1 || rw_frontfz2 > rw_backfz2 ||
backsector->floorplane.PointOnSide(viewx, viewy, viewz) < 0) backsector->floorplane.PointOnSide(ViewPos) < 0)
{ {
ds_p->silhouette = SIL_BOTTOM; ds_p->silhouette = SIL_BOTTOM;
} }
if (rw_frontcz1 < rw_backcz1 || rw_frontcz2 < rw_backcz2 || if (rw_frontcz1 < rw_backcz1 || rw_frontcz2 < rw_backcz2 ||
backsector->ceilingplane.PointOnSide(viewx, viewy, viewz) < 0) backsector->ceilingplane.PointOnSide(ViewPos) < 0)
{ {
ds_p->silhouette |= SIL_TOP; ds_p->silhouette |= SIL_TOP;
} }
@ -2509,7 +2520,7 @@ void R_StoreWallRange (int start, int stop)
if (pic->bWorldPanning) if (pic->bWorldPanning)
{ {
xoffset = MulScale16 (xoffset, lwallscale); xoffset = xs_RoundToInt(xoffset * lwallscale);
} }
for (i = start; i < stop; i++) for (i = start; i < stop; i++)
@ -2655,14 +2666,15 @@ void R_StoreWallRange (int start, int stop)
ds_p++; ds_p++;
} }
int OWallMost (short *mostbuf, fixed_t z, const FWallCoords *wallc) int OWallMost (short *mostbuf, double z, const FWallCoords *wallc)
{ {
int bad, y, ix1, ix2, iy1, iy2; int bad, ix1, ix2;
fixed_t s1, s2, s3, s4; double y, iy1, iy2;
double s1, s2, s3, s4;
z = -(z >> 4); z = -z;
s1 = MulScale16 (globaluclip, wallc->sz1); s2 = MulScale16 (globaluclip, wallc->sz2); s1 = globaluclip * wallc->sz1; s2 = globaluclip * wallc->sz2;
s3 = MulScale16 (globaldclip, wallc->sz1); s4 = MulScale16 (globaldclip, wallc->sz2); s3 = globaldclip * wallc->sz1; s4 = globaldclip * wallc->sz2;
bad = (z<s1)+((z<s2)<<1)+((z>s3)<<2)+((z>s4)<<3); bad = (z<s1)+((z<s2)<<1)+((z>s3)<<2)+((z>s4)<<3);
#if 1 #if 1
@ -2683,9 +2695,9 @@ int OWallMost (short *mostbuf, fixed_t z, const FWallCoords *wallc)
#if 1 #if 1
if (bad & 3) if (bad & 3)
{ {
int t = DivScale30 (z-s1, s2-s1); double t = (z-s1) / (s2-s1);
int inty = wallc->sz1 + MulScale30 (wallc->sz2 - wallc->sz1, t); double inty = wallc->sz1 + t * (wallc->sz2 - wallc->sz1);
int xcross = wallc->sx1 + Scale (MulScale30 (wallc->sz2, t), wallc->sx2 - wallc->sx1, inty); int xcross = xs_RoundToInt(wallc->sx1 + (t * wallc->sz2 * (wallc->sx2 - wallc->sx1)) / inty);
if ((bad & 3) == 2) if ((bad & 3) == 2)
{ {
@ -2701,9 +2713,9 @@ int OWallMost (short *mostbuf, fixed_t z, const FWallCoords *wallc)
if (bad & 12) if (bad & 12)
{ {
int t = DivScale30 (z-s3, s4-s3); double t = (z-s3) / (s4-s3);
int inty = wallc->sz1 + MulScale30 (wallc->sz2 - wallc->sz1, t); double inty = wallc->sz1 + t * (wallc->sz2 - wallc->sz1);
int xcross = wallc->sx1 + Scale (MulScale30 (wallc->sz2, t), wallc->sx2 - wallc->sx1, inty); int xcross = xs_RoundToInt(wallc->sx1 + (t * wallc->sz2 * (wallc->sx2 - wallc->sx1)) / inty);
if ((bad & 12) == 8) if ((bad & 12) == 8)
{ {
@ -2717,15 +2729,15 @@ int OWallMost (short *mostbuf, fixed_t z, const FWallCoords *wallc)
} }
} }
y = Scale (z, InvZtoScale, iy1); y = z * InvZtoScale / iy1;
if (ix2 == ix1) if (ix2 == ix1)
{ {
mostbuf[ix1] = (short)((y + centeryfrac) >> FRACBITS); mostbuf[ix1] = (short)xs_RoundToInt(y + CenterY);
} }
else else
{ {
fixed_t yinc = (Scale (z, InvZtoScale, iy2) - y) / (ix2 - ix1); fixed_t yinc = FLOAT2FIXED(((z * InvZtoScale / iy2) - y) / (ix2 - ix1));
qinterpolatedown16short (&mostbuf[ix1], ix2-ix1, y + centeryfrac, yinc); qinterpolatedown16short (&mostbuf[ix1], ix2-ix1, FLOAT2FIXED(y + CenterY), yinc);
} }
#else #else
double max = viewheight; double max = viewheight;
@ -2766,36 +2778,37 @@ int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc)
{ {
if (!plane.isSlope()) if (!plane.isSlope())
{ {
return OWallMost (mostbuf, plane.Zat0() - viewz, wallc); return OWallMost(mostbuf, plane.Zat0() - ViewPos.Z, wallc);
} }
fixed_t x, y, den, z1, z2, oz1, oz2; double x, y, den, z1, z2, oz1, oz2;
fixed_t s1, s2, s3, s4; double s1, s2, s3, s4;
int bad, ix1, ix2, iy1, iy2; int bad, ix1, ix2;
double iy1, iy2;
if (MirrorFlags & RF_XFLIP) if (MirrorFlags & RF_XFLIP)
{ {
x = curline->v2->fixX(); x = curline->v2->fX();
y = curline->v2->fixY(); y = curline->v2->fY();
if (wallc->sx1 == 0 && 0 != (den = wallc->tx1 - wallc->tx2 + wallc->ty1 - wallc->ty2)) if (wallc->sx1 == 0 && 0 != (den = wallc->tleft.X - wallc->tright.X + wallc->tleft.Y - wallc->tright.Y))
{ {
int frac = SafeDivScale30 (wallc->ty1 + wallc->tx1, den); double frac = (wallc->tleft.Y + wallc->tleft.X) / den;
x -= MulScale30 (frac, x - curline->v1->fixX()); x -= frac * (x - curline->v1->fX());
y -= MulScale30 (frac, y - curline->v1->fixY()); y -= frac * (y - curline->v1->fY());
} }
z1 = viewz - plane.ZatPointFixed(x, y); z1 = ViewPos.Z - plane.ZatPoint(x, y);
if (wallc->sx2 > wallc->sx1 + 1) if (wallc->sx2 > wallc->sx1 + 1)
{ {
x = curline->v1->fixX(); x = curline->v1->fX();
y = curline->v1->fixY(); y = curline->v1->fY();
if (wallc->sx2 == viewwidth && 0 != (den = wallc->tx1 - wallc->tx2 - wallc->ty1 + wallc->ty2)) if (wallc->sx2 == viewwidth && 0 != (den = wallc->tleft.X - wallc->tright.X - wallc->tleft.Y + wallc->tright.Y))
{ {
int frac = SafeDivScale30 (wallc->ty2 - wallc->tx2, den); double frac = (wallc->tright.Y - wallc->tright.X) / den;
x += MulScale30 (frac, curline->v2->fixX() - x); x += frac * (curline->v2->fX() - x);
y += MulScale30 (frac, curline->v2->fixY() - y); y += frac * (curline->v2->fY() - y);
} }
z2 = viewz - plane.ZatPointFixed(x, y); z2 = ViewPos.Z - plane.ZatPoint(x, y);
} }
else else
{ {
@ -2804,27 +2817,27 @@ int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc)
} }
else else
{ {
x = curline->v1->fixX(); x = curline->v1->fX();
y = curline->v1->fixY(); y = curline->v1->fY();
if (wallc->sx1 == 0 && 0 != (den = wallc->tx1 - wallc->tx2 + wallc->ty1 - wallc->ty2)) if (wallc->sx1 == 0 && 0 != (den = wallc->tleft.X - wallc->tright.X + wallc->tleft.Y - wallc->tright.Y))
{ {
int frac = SafeDivScale30 (wallc->ty1 + wallc->tx1, den); double frac = (wallc->tleft.Y + wallc->tleft.X) / den;
x += MulScale30 (frac, curline->v2->fixX() - x); x += frac * (curline->v2->fX() - x);
y += MulScale30 (frac, curline->v2->fixY() - y); y += frac * (curline->v2->fY() - y);
} }
z1 = viewz - plane.ZatPointFixed(x, y); z1 = ViewPos.Z - plane.ZatPoint(x, y);
if (wallc->sx2 > wallc->sx1 + 1) if (wallc->sx2 > wallc->sx1 + 1)
{ {
x = curline->v2->fixX(); x = curline->v2->fX();
y = curline->v2->fixY(); y = curline->v2->fY();
if (wallc->sx2 == viewwidth && 0 != (den = wallc->tx1 - wallc->tx2 - wallc->ty1 + wallc->ty2)) if (wallc->sx2 == viewwidth && 0 != (den = wallc->tleft.X - wallc->tright.X - wallc->tleft.Y + wallc->tright.Y))
{ {
int frac = SafeDivScale30 (wallc->ty2 - wallc->tx2, den); double frac = (wallc->tright.Y - wallc->tright.X) / den;
x -= MulScale30 (frac, x - curline->v1->fixX()); x -= frac * (x - curline->v1->fX());
y -= MulScale30 (frac, y - curline->v1->fixY()); y -= frac * (y - curline->v1->fY());
} }
z2 = viewz - plane.ZatPointFixed(x, y); z2 = ViewPos.Z - plane.ZatPoint(x, y);
} }
else else
{ {
@ -2832,8 +2845,8 @@ int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc)
} }
} }
s1 = MulScale12 (globaluclip, wallc->sz1); s2 = MulScale12 (globaluclip, wallc->sz2); s1 = globaluclip * wallc->sz1; s2 = globaluclip * wallc->sz2;
s3 = MulScale12 (globaldclip, wallc->sz1); s4 = MulScale12 (globaldclip, wallc->sz2); s3 = globaldclip * wallc->sz1; s4 = globaldclip * wallc->sz2;
bad = (z1<s1)+((z2<s2)<<1)+((z1>s3)<<2)+((z2>s4)<<3); bad = (z1<s1)+((z2<s2)<<1)+((z1>s3)<<2)+((z2>s4)<<3);
ix1 = wallc->sx1; ix2 = wallc->sx2; ix1 = wallc->sx1; ix2 = wallc->sx2;
@ -2856,10 +2869,10 @@ int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc)
if (bad&3) if (bad&3)
{ {
//inty = intz / (globaluclip>>16) //inty = intz / (globaluclip>>16)
int t = SafeDivScale30 (oz1-s1, s2-s1+oz1-oz2); double t = (oz1-s1) / (s2-s1+oz1-oz2);
int inty = wallc->sz1 + MulScale30 (wallc->sz2-wallc->sz1,t); double inty = wallc->sz1 + t * (wallc->sz2-wallc->sz1);
int intz = oz1 + MulScale30 (oz2-oz1,t); double intz = oz1 + t * (oz2-oz1);
int xcross = wallc->sx1 + Scale (MulScale30 (wallc->sz2, t), wallc->sx2-wallc->sx1, inty); int xcross = wallc->sx1 + xs_RoundToInt((t * wallc->sz2 * (wallc->sx2-wallc->sx1)) / inty);
//t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4)); //t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4));
//inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); //inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
@ -2880,10 +2893,10 @@ int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc)
if (bad&12) if (bad&12)
{ {
//inty = intz / (globaldclip>>16) //inty = intz / (globaldclip>>16)
int t = SafeDivScale30 (oz1-s3, s4-s3+oz1-oz2); double t = (oz1-s3) / (s4-s3+oz1-oz2);
int inty = wallc->sz1 + MulScale30 (wallc->sz2-wallc->sz1,t); double inty = wallc->sz1 + t * (wallc->sz2-wallc->sz1);
int intz = oz1 + MulScale30 (oz2-oz1,t); double intz = oz1 + t * (oz2-oz1);
int xcross = wallc->sx1 + Scale (MulScale30 (wallc->sz2, t), wallc->sx2-wallc->sx1,inty); int xcross = wallc->sx1 + xs_RoundToInt((t * wallc->sz2 * (wallc->sx2-wallc->sx1)) / inty);
//t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4)); //t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4));
//inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); //inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
@ -2901,15 +2914,15 @@ int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc)
} }
} }
y = Scale (z1>>4, InvZtoScale, iy1); y = z1 * InvZtoScale / iy1;
if (ix2 == ix1) if (ix2 == ix1)
{ {
mostbuf[ix1] = (short)((y + centeryfrac) >> FRACBITS); mostbuf[ix1] = (short)xs_RoundToInt(y/65536.0 + CenterY);
} }
else else
{ {
fixed_t yinc = (Scale (z2>>4, InvZtoScale, iy2) - y) / (ix2-ix1); fixed_t yinc = FLOAT2FIXED(((z2 * InvZtoScale / iy2) - y) / (ix2-ix1));
qinterpolatedown16short (&mostbuf[ix1], ix2-ix1, y + centeryfrac,yinc); qinterpolatedown16short (&mostbuf[ix1], ix2-ix1, FLOAT2FIXED(y/65536.0 + CenterY), yinc);
} }
return bad; return bad;
@ -2950,10 +2963,10 @@ static void PrepWallRoundFix(fixed_t *lwall, fixed_t walxrepeat, int x1, int x2)
} }
} }
void PrepWall (fixed_t *swall, fixed_t *lwall, fixed_t walxrepeat, int x1, int x2) void PrepWall (fixed_t *swall, fixed_t *lwall, double walxrepeat, int x1, int x2)
{ // swall = scale, lwall = texturecolumn { // swall = scale, lwall = texturecolumn
double top, bot, i; double top, bot, i;
double xrepeat = fabs((double)walxrepeat); double xrepeat = fabs(walxrepeat * 65536);
double depth_scale = WallT.InvZstep * WallTMapScale2; double depth_scale = WallT.InvZstep * WallTMapScale2;
double depth_org = -WallT.UoverZstep * WallTMapScale2; double depth_org = -WallT.UoverZstep * WallTMapScale2;
@ -2976,14 +2989,14 @@ void PrepWall (fixed_t *swall, fixed_t *lwall, fixed_t walxrepeat, int x1, int x
top += WallT.UoverZstep; top += WallT.UoverZstep;
bot += WallT.InvZstep; bot += WallT.InvZstep;
} }
PrepWallRoundFix(lwall, walxrepeat, x1, x2); PrepWallRoundFix(lwall, FLOAT2FIXED(walxrepeat), x1, x2);
} }
void PrepLWall (fixed_t *lwall, fixed_t walxrepeat, int x1, int x2) void PrepLWall (fixed_t *lwall, double walxrepeat, int x1, int x2)
{ // lwall = texturecolumn { // lwall = texturecolumn
double top, bot, i; double top, bot, i;
double xrepeat = fabs((double)walxrepeat); double xrepeat = fabs(walxrepeat * 65536);
double topstep; double topstep, botstep;
i = x1 - centerx; i = x1 - centerx;
top = WallT.UoverZorg + WallT.UoverZstep * i; top = WallT.UoverZorg + WallT.UoverZstep * i;
@ -2991,6 +3004,7 @@ void PrepLWall (fixed_t *lwall, fixed_t walxrepeat, int x1, int x2)
top *= xrepeat; top *= xrepeat;
topstep = WallT.UoverZstep * xrepeat; topstep = WallT.UoverZstep * xrepeat;
botstep = WallT.InvZstep;
for (int x = x1; x < x2; x++) for (int x = x1; x < x2; x++)
{ {
@ -3003,9 +3017,9 @@ void PrepLWall (fixed_t *lwall, fixed_t walxrepeat, int x1, int x2)
lwall[x] = xs_RoundToInt(top / bot); lwall[x] = xs_RoundToInt(top / bot);
} }
top += topstep; top += topstep;
bot += WallT.InvZstep; bot += botstep;
} }
PrepWallRoundFix(lwall, walxrepeat, x1, x2); PrepWallRoundFix(lwall, FLOAT2FIXED(walxrepeat), x1, x2);
} }
// pass = 0: when seg is first drawn // pass = 0: when seg is first drawn
@ -3014,7 +3028,7 @@ void PrepLWall (fixed_t *lwall, fixed_t walxrepeat, int x1, int x2)
static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, int pass) static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, int pass)
{ {
fixed_t lx, ly, lx2, ly2, decalx, decaly; DVector2 decal_left, decal_right, decal_pos;
int x1, x2; int x1, x2;
fixed_t xscale, yscale; fixed_t xscale, yscale;
fixed_t topoff; fixed_t topoff;
@ -3095,16 +3109,14 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper,
double dcx, dcy; double dcx, dcy;
decal->GetXY(wall, dcx, dcy); decal->GetXY(wall, dcx, dcy);
decalx = FLOAT2FIXED(dcx); decal_pos = { dcx, dcy };
decaly = FLOAT2FIXED(dcy);
angle_t ang = R_PointToAngle2 (curline->v1->fixX(), curline->v1->fixY(), curline->v2->fixX(), curline->v2->fixY()) >> ANGLETOFINESHIFT; DVector2 angvec = (curline->v2->fPos() - curline->v1->fPos()).Unit();
lx = decalx - FixedMul (x1, finecosine[ang]) - viewx;
lx2 = decalx + FixedMul (x2, finecosine[ang]) - viewx;
ly = decaly - FixedMul (x1, finesine[ang]) - viewy;
ly2 = decaly + FixedMul (x2, finesine[ang]) - viewy;
if (WallC.Init(lx, ly, lx2, ly2, TOO_CLOSE_Z)) decal_left = decal_pos - x1 * angvec - ViewPos;
decal_right = decal_pos + x2 * angvec - ViewPos;
if (WallC.Init(decal_left, decal_right, TOO_CLOSE_Z))
goto done; goto done;
x1 = WallC.sx1; x1 = WallC.sx1;
@ -3169,10 +3181,8 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper,
break; break;
} }
fixed_t fzpos;
fzpos = FLOAT2FIXED(zpos); // pacify GCC
topoff = WallSpriteTile->TopOffset << FRACBITS; topoff = WallSpriteTile->TopOffset << FRACBITS;
dc_texturemid = topoff + FixedDiv (fzpos - viewz, yscale); dc_texturemid = topoff + xs_ToInt((zpos - ViewPos.Z) * 65536 / yscale);
// Clip sprite to drawseg // Clip sprite to drawseg
x1 = MAX<int>(clipper->x1, x1); x1 = MAX<int>(clipper->x1, x1);

View file

@ -31,10 +31,10 @@ extern short *openings;
extern ptrdiff_t lastopening; extern ptrdiff_t lastopening;
extern size_t maxopenings; extern size_t maxopenings;
int OWallMost (short *mostbuf, fixed_t z, const FWallCoords *wallc); int OWallMost (short *mostbuf, double z, const FWallCoords *wallc);
int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc); int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc);
void PrepWall (fixed_t *swall, fixed_t *lwall, fixed_t walxrepeat, int x1, int x2); void PrepWall (fixed_t *swall, fixed_t *lwall, double walxrepeat, int x1, int x2);
void PrepLWall (fixed_t *lwall, fixed_t walxrepeat, int x1, int x2); void PrepLWall (fixed_t *lwall, double walxrepeat, int x1, int x2);
ptrdiff_t R_NewOpening (ptrdiff_t len); ptrdiff_t R_NewOpening (ptrdiff_t len);

View file

@ -88,10 +88,10 @@ struct FCoverageBuffer
unsigned int NumLists; unsigned int NumLists;
}; };
extern fixed_t globaluclip, globaldclip; extern double globaluclip, globaldclip;
#define MINZ (2048*4) #define MINZ double((2048*4) / double(1 << 20))
#define BASEYCENTER (100) #define BASEYCENTER (100)
EXTERN_CVAR (Bool, st_scale) EXTERN_CVAR (Bool, st_scale)
@ -151,7 +151,7 @@ static vissprite_t **spritesorter;
static int spritesortersize = 0; static int spritesortersize = 0;
static int vsprcount; static int vsprcount;
static void R_ProjectWallSprite(AActor *thing, fixed_t fx, fixed_t fy, fixed_t fz, FTextureID picnum, fixed_t xscale, fixed_t yscale, INTBOOL flip); static void R_ProjectWallSprite(AActor *thing, const DVector3 &pos, FTextureID picnum, const DVector2 &scale, INTBOOL flip);
@ -244,6 +244,7 @@ bool sprflipvert;
void R_DrawMaskedColumn (const BYTE *column, const FTexture::Span *span) void R_DrawMaskedColumn (const BYTE *column, const FTexture::Span *span)
{ {
fixed_t centeryfrac = FLOAT2FIXED(CenterY);
while (span->Length != 0) while (span->Length != 0)
{ {
const int length = span->Length; const int length = span->Length;
@ -357,7 +358,7 @@ static inline void R_CollectPortals()
} }
} }
static inline bool R_ClipSpriteColumnWithPortals(fixed_t x, fixed_t y, vissprite_t* spr) static inline bool R_ClipSpriteColumnWithPortals(vissprite_t* spr)
{ {
// [ZZ] 10.01.2016: don't clip sprites from the root of a skybox. // [ZZ] 10.01.2016: don't clip sprites from the root of a skybox.
if (CurrentPortalInSkybox) if (CurrentPortalInSkybox)
@ -371,10 +372,8 @@ static inline bool R_ClipSpriteColumnWithPortals(fixed_t x, fixed_t y, vissprite
// (all checks that are already done in R_CollectPortals have been removed for performance reasons.) // (all checks that are already done in R_CollectPortals have been removed for performance reasons.)
line_t* line = seg->curline->linedef;
// don't clip if the sprite is in front of the portal // don't clip if the sprite is in front of the portal
if (!P_PointOnLineSidePrecise(FIXED2DBL(x), FIXED2DBL(y), line)) if (!P_PointOnLineSidePrecise(spr->gpos.X, spr->gpos.Y, seg->curline->linedef))
continue; continue;
// now if current column is covered by this drawseg, we clip it away // now if current column is covered by this drawseg, we clip it away
@ -399,13 +398,14 @@ void R_DrawVisSprite (vissprite_t *vis)
int x2, stop4; int x2, stop4;
fixed_t xiscale; fixed_t xiscale;
ESPSResult mode; ESPSResult mode;
bool ispsprite = (!vis->sector && !vis->gx && !vis->gy && !vis->gz); bool ispsprite = (!vis->sector && vis->gpos != FVector3(0, 0, 0));
if (vis->xscale == 0 || vis->yscale == 0) if (vis->xscale == 0 || vis->yscale == 0)
{ // scaled to 0; can't see { // scaled to 0; can't see
return; return;
} }
fixed_t centeryfrac = FLOAT2FIXED(CenterY);
dc_colormap = vis->Style.colormap; dc_colormap = vis->Style.colormap;
mode = R_SetPatchStyle (vis->Style.RenderStyle, vis->Style.Alpha, vis->Translation, vis->FillColor); mode = R_SetPatchStyle (vis->Style.RenderStyle, vis->Style.Alpha, vis->Translation, vis->FillColor);
@ -461,7 +461,7 @@ void R_DrawVisSprite (vissprite_t *vis)
while ((dc_x < stop4) && (dc_x & 3)) while ((dc_x < stop4) && (dc_x & 3))
{ {
pixels = tex->GetColumn (frac >> FRACBITS, &spans); pixels = tex->GetColumn (frac >> FRACBITS, &spans);
if (ispsprite || !R_ClipSpriteColumnWithPortals(vis->gx, vis->gy, vis)) if (ispsprite || !R_ClipSpriteColumnWithPortals(vis))
R_DrawMaskedColumn (pixels, spans); R_DrawMaskedColumn (pixels, spans);
dc_x++; dc_x++;
frac += xiscale; frac += xiscale;
@ -473,7 +473,7 @@ void R_DrawVisSprite (vissprite_t *vis)
for (int zz = 4; zz; --zz) for (int zz = 4; zz; --zz)
{ {
pixels = tex->GetColumn (frac >> FRACBITS, &spans); pixels = tex->GetColumn (frac >> FRACBITS, &spans);
if (ispsprite || !R_ClipSpriteColumnWithPortals(vis->gx, vis->gy, vis)) if (ispsprite || !R_ClipSpriteColumnWithPortals(vis))
R_DrawMaskedColumnHoriz (pixels, spans); R_DrawMaskedColumnHoriz (pixels, spans);
dc_x++; dc_x++;
frac += xiscale; frac += xiscale;
@ -484,7 +484,7 @@ void R_DrawVisSprite (vissprite_t *vis)
while (dc_x < x2) while (dc_x < x2)
{ {
pixels = tex->GetColumn (frac >> FRACBITS, &spans); pixels = tex->GetColumn (frac >> FRACBITS, &spans);
if (ispsprite || !R_ClipSpriteColumnWithPortals(vis->gx, vis->gy, vis)) if (ispsprite || !R_ClipSpriteColumnWithPortals(vis))
R_DrawMaskedColumn (pixels, spans); R_DrawMaskedColumn (pixels, spans);
dc_x++; dc_x++;
frac += xiscale; frac += xiscale;
@ -509,7 +509,7 @@ void R_DrawWallSprite(vissprite_t *spr)
WallT.InitFromWallCoords(&spr->wallc); WallT.InitFromWallCoords(&spr->wallc);
PrepWall(swall, lwall, spr->pic->GetWidth() << FRACBITS, x1, x2); PrepWall(swall, lwall, spr->pic->GetWidth() << FRACBITS, x1, x2);
yscale = spr->yscale; yscale = spr->yscale;
dc_texturemid = FixedDiv(spr->gzt - viewz, yscale); dc_texturemid = FixedDiv(FLOAT2FIXED(spr->gzt - ViewPos.Z), yscale);
if (spr->renderflags & RF_XFLIP) if (spr->renderflags & RF_XFLIP)
{ {
int right = (spr->pic->GetWidth() << FRACBITS) - 1; int right = (spr->pic->GetWidth() << FRACBITS) - 1;
@ -533,8 +533,8 @@ void R_DrawWallSprite(vissprite_t *spr)
int shade = LIGHT2SHADE(spr->sector->lightlevel + r_actualextralight); int shade = LIGHT2SHADE(spr->sector->lightlevel + r_actualextralight);
GlobVis = r_WallVisibility; GlobVis = r_WallVisibility;
rw_lightleft = SafeDivScale12(GlobVis, spr->wallc.sz1); rw_lightleft = SafeDivScale12(GlobVis, xs_Fix<12>::ToFix(spr->wallc.sz1));
rw_lightstep = (SafeDivScale12(GlobVis, spr->wallc.sz2) - rw_lightleft) / (spr->wallc.sx2 - spr->wallc.sx1); rw_lightstep = (SafeDivScale12(GlobVis, xs_Fix<12>::ToFix(spr->wallc.sz2)) - rw_lightleft) / (spr->wallc.sx2 - spr->wallc.sx1);
rw_light = rw_lightleft + (x1 - spr->wallc.sx1) * rw_lightstep; rw_light = rw_lightleft + (x1 - spr->wallc.sx1) * rw_lightstep;
if (fixedlightlev >= 0) if (fixedlightlev >= 0)
dc_colormap = usecolormap->Maps + fixedlightlev; dc_colormap = usecolormap->Maps + fixedlightlev;
@ -595,7 +595,7 @@ void R_DrawWallSprite(vissprite_t *spr)
{ // calculate lighting { // calculate lighting
dc_colormap = usecolormap->Maps + (GETPALOOKUP (rw_light, shade) << COLORMAPSHIFT); dc_colormap = usecolormap->Maps + (GETPALOOKUP (rw_light, shade) << COLORMAPSHIFT);
} }
if (!R_ClipSpriteColumnWithPortals(spr->gx, spr->gy, spr)) if (!R_ClipSpriteColumnWithPortals(spr))
R_WallSpriteColumn(R_DrawMaskedColumn); R_WallSpriteColumn(R_DrawMaskedColumn);
dc_x++; dc_x++;
} }
@ -609,7 +609,7 @@ void R_DrawWallSprite(vissprite_t *spr)
rt_initcols(); rt_initcols();
for (int zz = 4; zz; --zz) for (int zz = 4; zz; --zz)
{ {
if (!R_ClipSpriteColumnWithPortals(spr->gx, spr->gy, spr)) if (!R_ClipSpriteColumnWithPortals(spr))
R_WallSpriteColumn(R_DrawMaskedColumnHoriz); R_WallSpriteColumn(R_DrawMaskedColumnHoriz);
dc_x++; dc_x++;
} }
@ -622,7 +622,7 @@ void R_DrawWallSprite(vissprite_t *spr)
{ // calculate lighting { // calculate lighting
dc_colormap = usecolormap->Maps + (GETPALOOKUP (rw_light, shade) << COLORMAPSHIFT); dc_colormap = usecolormap->Maps + (GETPALOOKUP (rw_light, shade) << COLORMAPSHIFT);
} }
if (!R_ClipSpriteColumnWithPortals(spr->gx, spr->gy, spr)) if (!R_ClipSpriteColumnWithPortals(spr))
R_WallSpriteColumn(R_DrawMaskedColumn); R_WallSpriteColumn(R_DrawMaskedColumn);
dc_x++; dc_x++;
} }
@ -636,9 +636,9 @@ void R_WallSpriteColumn (void (*drawfunc)(const BYTE *column, const FTexture::Sp
dc_iscale = MulScale16 (swall[dc_x], rw_offset); dc_iscale = MulScale16 (swall[dc_x], rw_offset);
spryscale = SafeDivScale32 (1, dc_iscale); spryscale = SafeDivScale32 (1, dc_iscale);
if (sprflipvert) if (sprflipvert)
sprtopscreen = centeryfrac + FixedMul (dc_texturemid, spryscale); sprtopscreen = FLOAT2FIXED(CenterY) + FixedMul (dc_texturemid, spryscale);
else else
sprtopscreen = centeryfrac - FixedMul (dc_texturemid, spryscale); sprtopscreen = FLOAT2FIXED(CenterY) - FixedMul (dc_texturemid, spryscale);
const BYTE *column; const BYTE *column;
const FTexture::Span *spans; const FTexture::Span *spans;
@ -679,7 +679,7 @@ void R_DrawVisVoxel(vissprite_t *spr, int minslabz, int maxslabz, short *cliptop
} }
// Render the voxel, either directly to the screen or offscreen. // Render the voxel, either directly to the screen or offscreen.
R_DrawVoxel(spr->vx, spr->vy, spr->vz, spr->vang, spr->gx, spr->gy, spr->gz, spr->angle, R_DrawVoxel(spr->vpos, spr->vang, spr->gpos, spr->angle,
spr->xscale, spr->yscale, spr->voxel, spr->Style.colormap, cliptop, clipbot, spr->xscale, spr->yscale, spr->voxel, spr->Style.colormap, cliptop, clipbot,
minslabz, maxslabz, flags); minslabz, maxslabz, flags);
@ -728,15 +728,15 @@ void R_DrawVisVoxel(vissprite_t *spr, int minslabz, int maxslabz, short *cliptop
// //
void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling) void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling)
{ {
fixed_t tr_x; double tr_x;
fixed_t tr_y; double tr_y;
fixed_t gzt; // killough 3/27/98 double gzt; // killough 3/27/98
fixed_t gzb; // [RH] use bottom of sprite, not actor double gzb; // [RH] use bottom of sprite, not actor
fixed_t tx, tx2; double tx;// , tx2;
fixed_t tz; double tz;
fixed_t xscale = FRACUNIT, yscale = FRACUNIT; double xscale = 1, yscale = 1;
int x1; int x1;
int x2; int x2;
@ -767,9 +767,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
// [RH] Interpolate the sprite's position to make it look smooth // [RH] Interpolate the sprite's position to make it look smooth
DVector3 pos = thing->InterpolatedPosition(r_TicFracF); DVector3 pos = thing->InterpolatedPosition(r_TicFracF);
const fixed_t fx = FLOAT2FIXED(pos.X); pos.Z += thing->GetBobOffset(r_TicFracF);
const fixed_t fy = FLOAT2FIXED(pos.Y);
fixed_t fz = FLOAT2FIXED(pos.Z + thing->GetBobOffset(r_TicFracF));
tex = NULL; tex = NULL;
voxel = NULL; voxel = NULL;
@ -801,15 +799,15 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
{ {
// choose a different rotation based on player view // choose a different rotation based on player view
spriteframe_t *sprframe = &SpriteFrames[tex->Rotations]; spriteframe_t *sprframe = &SpriteFrames[tex->Rotations];
angle_t ang = R_PointToAngle2 (viewx, viewy, fx, fy); DAngle ang = (pos - ViewPos).Angle();
angle_t rot; angle_t rot;
if (sprframe->Texture[0] == sprframe->Texture[1]) if (sprframe->Texture[0] == sprframe->Texture[1])
{ {
rot = (ang - thing->Angles.Yaw.BAMs() + (angle_t)(ANGLE_45/2)*9) >> 28; rot = (ang - thing->Angles.Yaw + 45.0/2*9).BAMs() >> 28;
} }
else else
{ {
rot = (ang - thing->Angles.Yaw.BAMs() + (angle_t)(ANGLE_45/2)*9-(angle_t)(ANGLE_180/16)) >> 28; rot = (ang - thing->Angles.Yaw + (45.0/2*9-180.0/16)).BAMs() >> 28;
} }
picnum = sprframe->Texture[rot]; picnum = sprframe->Texture[rot];
if (sprframe->Flip & (1 << rot)) if (sprframe->Flip & (1 << rot))
@ -840,15 +838,15 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
//picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0]; //picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0];
// choose a different rotation based on player view // choose a different rotation based on player view
spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame]; spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame];
angle_t ang = R_PointToAngle2 (viewx, viewy, fx, fy); DAngle ang = (pos - ViewPos).Angle();
angle_t rot; angle_t rot;
if (sprframe->Texture[0] == sprframe->Texture[1]) if (sprframe->Texture[0] == sprframe->Texture[1])
{ {
rot = (ang - thing->Angles.Yaw.BAMs() + (angle_t)(ANGLE_45/2)*9) >> 28; rot = (ang - thing->Angles.Yaw + 45.0 / 2 * 9).BAMs() >> 28;
} }
else else
{ {
rot = (ang - thing->Angles.Yaw.BAMs() + (angle_t)(ANGLE_45/2)*9-(angle_t)(ANGLE_180/16)) >> 28; rot = (ang - thing->Angles.Yaw + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28;
} }
picnum = sprframe->Texture[rot]; picnum = sprframe->Texture[rot];
if (sprframe->Flip & (1 << rot)) if (sprframe->Flip & (1 << rot))
@ -872,37 +870,35 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
return; return;
} }
fixed_t spritescaleX = FLOAT2FIXED(spriteScale.X);
fixed_t spritescaleY = FLOAT2FIXED(spriteScale.Y);
if ((renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE) if ((renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE)
{ {
R_ProjectWallSprite(thing, fx, fy, fz, picnum, spritescaleX, spritescaleY, renderflags); R_ProjectWallSprite(thing, pos, picnum, spriteScale, renderflags);
return; return;
} }
// transform the origin point // transform the origin point
tr_x = fx - viewx; tr_x = pos.X - ViewPos.X;
tr_y = fy - viewy; tr_y = pos.Y - ViewPos.Y;
tz = DMulScale20 (tr_x, viewtancos, tr_y, viewtansin); tz = tr_x * ViewTanCos + tr_y * ViewTanSin;
// thing is behind view plane? // thing is behind view plane?
if (voxel == NULL && tz < MINZ) if (voxel == NULL && tz < MINZ)
return; return;
tx = DMulScale16 (tr_x, viewsin, -tr_y, viewcos); tx = tr_x * ViewSin - tr_y * ViewCos;
// [RH] Flip for mirrors // [RH] Flip for mirrors
if (MirrorFlags & RF_XFLIP) if (MirrorFlags & RF_XFLIP)
{ {
tx = -tx; tx = -tx;
} }
tx2 = tx >> 4; //tx2 = tx >> 4;
// too far off the side? // too far off the side?
// if it's a voxel, it can be further off the side // if it's a voxel, it can be further off the side
if ((voxel == NULL && (abs(tx) >> 6) > abs(tz)) || if ((voxel == NULL && (fabs(tx / 64) > fabs(tz))) ||
(voxel != NULL && (abs(tx) >> 7) > abs(tz))) (voxel != NULL && (fabs(tx / 128) > abs(tz))))
{ {
return; return;
} }
@ -912,16 +908,16 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
// [RH] Added scaling // [RH] Added scaling
int scaled_to = tex->GetScaledTopOffset(); int scaled_to = tex->GetScaledTopOffset();
int scaled_bo = scaled_to - tex->GetScaledHeight(); int scaled_bo = scaled_to - tex->GetScaledHeight();
gzt = fz + spritescaleY * scaled_to; gzt = pos.Z + spriteScale.Y * scaled_to;
gzb = fz + spritescaleY * scaled_bo; gzb = pos.Z + spriteScale.Y * scaled_bo;
} }
else else
{ {
xscale = fixed_t(spritescaleX * voxel->Scale); xscale = spriteScale.X * voxel->Scale;
yscale = fixed_t(spritescaleY * voxel->Scale); yscale = spriteScale.Y * voxel->Scale;
fixed_t piv = fixed_t(voxel->Voxel->Mips[0].Pivot.Z*256.); double piv = voxel->Voxel->Mips[0].Pivot.Z;
gzt = fz + MulScale8(yscale, piv) - FLOAT2FIXED(thing->Floorclip); gzt = pos.Z + yscale * piv - thing->Floorclip;
gzb = fz + MulScale8(yscale, piv - (voxel->Voxel->Mips[0].SizeZ << 8)); gzb = pos.Z + yscale * (piv - voxel->Voxel->Mips[0].SizeZ);
if (gzt <= gzb) if (gzt <= gzb)
return; return;
} }
@ -955,11 +951,10 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
if (voxel == NULL) if (voxel == NULL)
{ {
xscale = DivScale12 (centerxfrac, tz); xscale = CenterX / tz;
// [RH] Reject sprites that are off the top or bottom of the screen // [RH] Reject sprites that are off the top or bottom of the screen
if (MulScale12 (globaluclip, tz) > viewz - gzb || if (globaluclip * tz > ViewPos.Z - gzb || globaldclip * tz < ViewPos.Z - gzt)
MulScale12 (globaldclip, tz) < viewz - gzt)
{ {
return; return;
} }
@ -968,36 +963,36 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
renderflags ^= MirrorFlags & RF_XFLIP; renderflags ^= MirrorFlags & RF_XFLIP;
// calculate edges of the shape // calculate edges of the shape
const fixed_t thingxscalemul = fixed_t(spritescaleX / tex->Scale.X); const double thingxscalemul = spriteScale.X / tex->Scale.X;
tx -= ((renderflags & RF_XFLIP) ? (tex->GetWidth() - tex->LeftOffset - 1) : tex->LeftOffset) * thingxscalemul; tx -= ((renderflags & RF_XFLIP) ? (tex->GetWidth() - tex->LeftOffset - 1) : tex->LeftOffset) * thingxscalemul;
x1 = centerx + MulScale32 (tx, xscale); x1 = centerx + xs_RoundToInt(tx * xscale);
// off the right side? // off the right side?
if (x1 >= WindowRight) if (x1 >= WindowRight)
return; return;
tx += tex->GetWidth() * thingxscalemul; tx += tex->GetWidth() * thingxscalemul;
x2 = centerx + MulScale32 (tx, xscale); x2 = centerx + xs_RoundToInt(tx * xscale);
// off the left side or too small? // off the left side or too small?
if ((x2 < WindowLeft || x2 <= x1)) if ((x2 < WindowLeft || x2 <= x1))
return; return;
xscale = fixed_t(FixedMul(spritescaleX, xscale) / tex->Scale.X); xscale = spriteScale.X * xscale / tex->Scale.X;
iscale = (tex->GetWidth() << FRACBITS) / (x2 - x1); iscale = (tex->GetWidth() << FRACBITS) / (x2 - x1);
fixed_t yscale = fixed_t(spritescaleY / tex->Scale.Y); fixed_t yscale = FLOAT2FIXED(spriteScale.Y / tex->Scale.Y);
// store information in a vissprite // store information in a vissprite
vis = R_NewVisSprite(); vis = R_NewVisSprite();
vis->CurrentPortalUniq = CurrentPortalUniq; vis->CurrentPortalUniq = CurrentPortalUniq;
vis->xscale = xscale; vis->xscale = FLOAT2FIXED(xscale);
vis->yscale = Scale(InvZtoScale, yscale, tz << 4); vis->yscale = fixed_t(InvZtoScale * yscale / tz);
vis->idepth = (unsigned)DivScale32(1, tz) >> 1; // tz is 20.12, so idepth ought to be 12.20, but signed math makes it 13.19 vis->idepth = float(1 / tz);
vis->floorclip = FixedDiv (FLOAT2FIXED(thing->Floorclip), yscale); vis->floorclip = FixedDiv (FLOAT2FIXED(thing->Floorclip), yscale);
vis->texturemid = (tex->TopOffset << FRACBITS) - FixedDiv (viewz - fz + FLOAT2FIXED(thing->Floorclip), yscale); vis->texturemid = (tex->TopOffset << FRACBITS) - FixedDiv(FLOAT2FIXED(ViewPos.Z - pos.Z + thing->Floorclip), yscale);
vis->x1 = x1 < WindowLeft ? WindowLeft : x1; vis->x1 = x1 < WindowLeft ? WindowLeft : x1;
vis->x2 = x2 > WindowRight ? WindowRight : x2; vis->x2 = x2 > WindowRight ? WindowRight : x2;
vis->angle = thing->Angles.Yaw.BAMs(); vis->angle = thing->Angles.Yaw.BAMs();
@ -1021,14 +1016,14 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
vis = R_NewVisSprite(); vis = R_NewVisSprite();
vis->CurrentPortalUniq = CurrentPortalUniq; vis->CurrentPortalUniq = CurrentPortalUniq;
vis->xscale = xscale; vis->xscale = FLOAT2FIXED(xscale);
vis->yscale = yscale; vis->yscale = FLOAT2FIXED(yscale);
vis->x1 = WindowLeft; vis->x1 = WindowLeft;
vis->x2 = WindowRight; vis->x2 = WindowRight;
vis->idepth = (unsigned)DivScale32(1, MAX(tz, MINZ)) >> 1; vis->idepth = 1 / MINZ;
vis->floorclip = FLOAT2FIXED(thing->Floorclip); vis->floorclip = FLOAT2FIXED(thing->Floorclip);
fz -= FLOAT2FIXED(thing->Floorclip); pos.Z -= thing->Floorclip;
vis->angle = thing->Angles.Yaw.BAMs() + voxel->AngleOffset.BAMs(); vis->angle = thing->Angles.Yaw.BAMs() + voxel->AngleOffset.BAMs();
@ -1039,24 +1034,20 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
vis->angle -= ang.BAMs(); vis->angle -= ang.BAMs();
} }
vis->vx = viewx; vis->vpos = { (float)ViewPos.X, (float)ViewPos.Y, (float)ViewPos.Z };
vis->vy = viewy; vis->vang = FAngle((float)ViewAngle.Degrees);
vis->vz = viewz;
vis->vang = viewangle;
} }
// killough 3/27/98: save sector for special clipping later // killough 3/27/98: save sector for special clipping later
vis->heightsec = heightsec; vis->heightsec = heightsec;
vis->sector = thing->Sector; vis->sector = thing->Sector;
vis->depth = tz; vis->depth = (float)tz;
vis->gx = fx; vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z };
vis->gy = fy; vis->gzb = (float)gzb; // [RH] use gzb, not thing->z
vis->gz = fz; vis->gzt = (float)gzt; // killough 3/27/98
vis->gzb = gzb; // [RH] use gzb, not thing->z vis->deltax = float(pos.X - ViewPos.X);
vis->gzt = gzt; // killough 3/27/98 vis->deltay = float(pos.Y - ViewPos.Y);
vis->deltax = fx - viewx;
vis->deltay = fy - viewy;
vis->renderflags = renderflags; vis->renderflags = renderflags;
if(thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D if(thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D
vis->Style.RenderStyle = thing->RenderStyle; vis->Style.RenderStyle = thing->RenderStyle;
@ -1137,20 +1128,22 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
else else
{ // diminished light { // diminished light
vis->ColormapNum = GETPALOOKUP( vis->ColormapNum = GETPALOOKUP(
(fixed_t)DivScale12 (r_SpriteVisibility, MAX(tz, MINZ)), spriteshade); (fixed_t)(r_SpriteVisibility / MAX(tz, MINZ)), spriteshade);
vis->Style.colormap = mybasecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT); vis->Style.colormap = mybasecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT);
} }
} }
} }
static void R_ProjectWallSprite(AActor *thing, fixed_t fx, fixed_t fy, fixed_t fz, FTextureID picnum, fixed_t xscale, fixed_t yscale, int renderflags) static void R_ProjectWallSprite(AActor *thing, const DVector3 &pos, FTextureID picnum, const DVector2 &scale, int renderflags)
{ {
FWallCoords wallc; FWallCoords wallc;
int x1, x2; double x1, x2;
fixed_t lx1, lx2, ly1, ly2; DVector2 left, right;
fixed_t gzb, gzt, tz; double gzb, gzt, tz;
FTexture *pic = TexMan(picnum, true); FTexture *pic = TexMan(picnum, true);
angle_t ang = (thing->Angles.Yaw.BAMs() + ANGLE_90) >> ANGLETOFINESHIFT; DAngle ang = thing->Angles.Yaw + 90;
double angcos = ang.Cos();
double angsin = ang.Sin();
vissprite_t *vis; vissprite_t *vis;
// Determine left and right edges of sprite. The sprite's angle is its normal, // Determine left and right edges of sprite. The sprite's angle is its normal,
@ -1158,16 +1151,16 @@ static void R_ProjectWallSprite(AActor *thing, fixed_t fx, fixed_t fy, fixed_t f
x2 = pic->GetScaledWidth(); x2 = pic->GetScaledWidth();
x1 = pic->GetScaledLeftOffset(); x1 = pic->GetScaledLeftOffset();
x1 *= xscale; x1 *= scale.X;
x2 *= xscale; x2 *= scale.X;
lx1 = fx - FixedMul(x1, finecosine[ang]) - viewx; left.X = pos.X - x1 * angcos - ViewPos.X;
ly1 = fy - FixedMul(x1, finesine[ang]) - viewy; left.Y = pos.Y - x1 * angsin - ViewPos.Y;
lx2 = lx1 + FixedMul(x2, finecosine[ang]); right.X = left.X + x2 * angcos;
ly2 = ly1 + FixedMul(x2, finesine[ang]); right.Y = right.Y + x2 * angsin;
// Is it off-screen? // Is it off-screen?
if (wallc.Init(lx1, ly1, lx2, ly2, TOO_CLOSE_Z)) if (wallc.Init(left, right, TOO_CLOSE_Z))
return; return;
if (wallc.sx1 >= WindowRight || wallc.sx2 <= WindowLeft) if (wallc.sx1 >= WindowRight || wallc.sx2 <= WindowLeft)
@ -1175,29 +1168,27 @@ static void R_ProjectWallSprite(AActor *thing, fixed_t fx, fixed_t fy, fixed_t f
// Sprite sorting should probably treat these as walls, not sprites, // Sprite sorting should probably treat these as walls, not sprites,
// but right now, I just want to get them drawing. // but right now, I just want to get them drawing.
tz = DMulScale20(fx - viewx, viewtancos, fy - viewy, viewtansin); tz = (pos.X - ViewPos.X) * ViewTanCos + (pos.Y - ViewPos.Y) * ViewTanSin;
int scaled_to = pic->GetScaledTopOffset(); int scaled_to = pic->GetScaledTopOffset();
int scaled_bo = scaled_to - pic->GetScaledHeight(); int scaled_bo = scaled_to - pic->GetScaledHeight();
gzt = fz + yscale * scaled_to; gzt = pos.Z + scale.Y * scaled_to;
gzb = fz + yscale * scaled_bo; gzb = pos.Z + scale.Y * scaled_bo;
vis = R_NewVisSprite(); vis = R_NewVisSprite();
vis->CurrentPortalUniq = CurrentPortalUniq; vis->CurrentPortalUniq = CurrentPortalUniq;
vis->x1 = wallc.sx1 < WindowLeft ? WindowLeft : wallc.sx1; vis->x1 = wallc.sx1 < WindowLeft ? WindowLeft : wallc.sx1;
vis->x2 = wallc.sx2 >= WindowRight ? WindowRight : wallc.sx2; vis->x2 = wallc.sx2 >= WindowRight ? WindowRight : wallc.sx2;
vis->yscale = yscale; vis->yscale = FLOAT2FIXED(scale.Y);
vis->idepth = (unsigned)DivScale32(1, tz) >> 1; vis->idepth = float(1 / tz);
vis->depth = tz; vis->depth = (float)tz;
vis->sector = thing->Sector; vis->sector = thing->Sector;
vis->heightsec = NULL; vis->heightsec = NULL;
vis->gx = fx; vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z };
vis->gy = fy; vis->gzb = (float)gzb;
vis->gz = fz; vis->gzt = (float)gzt;
vis->gzb = gzb; vis->deltax = float(pos.X - ViewPos.X);
vis->gzt = gzt; vis->deltay = float(pos.Y - ViewPos.Y);
vis->deltax = fx - viewx;
vis->deltay = fy - viewy;
vis->renderflags = renderflags; vis->renderflags = renderflags;
if(thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D if(thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D
vis->Style.RenderStyle = thing->RenderStyle; vis->Style.RenderStyle = thing->RenderStyle;
@ -1213,7 +1204,7 @@ static void R_ProjectWallSprite(AActor *thing, fixed_t fx, fixed_t fy, fixed_t f
vis->bIsVoxel = false; vis->bIsVoxel = false;
vis->bWallSprite = true; vis->bWallSprite = true;
vis->ColormapNum = GETPALOOKUP( vis->ColormapNum = GETPALOOKUP(
(fixed_t)DivScale12 (r_SpriteVisibility, MAX(tz, MINZ)), spriteshade); (fixed_t)DivScale12 (r_SpriteVisibility, xs_Fix<20>::ToFix(MAX(tz, MINZ))), spriteshade);
vis->Style.colormap = basecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT); vis->Style.colormap = basecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT);
vis->wallc = wallc; vis->wallc = wallc;
} }
@ -1325,14 +1316,14 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_
tx = sx-((320/2)<<FRACBITS); tx = sx-((320/2)<<FRACBITS);
tx -= tex->GetScaledLeftOffset() << FRACBITS; tx -= tex->GetScaledLeftOffset() << FRACBITS;
x1 = (centerxfrac + FixedMul (tx, pspritexscale)) >>FRACBITS; x1 = centerx + (FixedMul(tx, pspritexscale) >> FRACBITS);
// off the right side // off the right side
if (x1 > viewwidth) if (x1 > viewwidth)
return; return;
tx += tex->GetScaledWidth() << FRACBITS; tx += tex->GetScaledWidth() << FRACBITS;
x2 = ((centerxfrac + FixedMul (tx, pspritexscale)) >>FRACBITS); x2 = centerx + (FixedMul(tx, pspritexscale) >> FRACBITS);
// off the left side // off the left side
if (x2 <= 0) if (x2 <= 0)
@ -1544,10 +1535,10 @@ void R_DrawPlayerSprites ()
if(fixedlightlev < 0 && viewsector->e && viewsector->e->XFloor.lightlist.Size()) { if(fixedlightlev < 0 && viewsector->e && viewsector->e->XFloor.lightlist.Size()) {
for(i = viewsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) for(i = viewsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--)
if(viewz <= viewsector->e->XFloor.lightlist[i].plane.Zat0()) { if(ViewPos.Z <= viewsector->e->XFloor.lightlist[i].plane.Zat0()) {
rover = viewsector->e->XFloor.lightlist[i].caster; rover = viewsector->e->XFloor.lightlist[i].caster;
if(rover) { if(rover) {
if(rover->flags & FF_DOUBLESHADOW && viewz <= rover->bottom.plane->Zat0()) if(rover->flags & FF_DOUBLESHADOW && ViewPos.Z <= rover->bottom.plane->Zat0())
break; break;
sec = rover->model; sec = rover->model;
if(rover->flags & FF_FADEWALLS) if(rover->flags & FF_FADEWALLS)
@ -1586,11 +1577,10 @@ void R_DrawPlayerSprites ()
if (camera->player != NULL) if (camera->player != NULL)
{ {
fixed_t centerhack = centeryfrac; double centerhack = CenterY;
float ofsx, ofsy; float ofsx, ofsy;
centery = viewheight >> 1; CenterY = viewheight / 2;
centeryfrac = centery << FRACBITS;
P_BobWeapon (camera->player, &camera->player->psprites[ps_weapon], &ofsx, &ofsy, r_TicFracF); P_BobWeapon (camera->player, &camera->player->psprites[ps_weapon], &ofsx, &ofsy, r_TicFracF);
@ -1611,8 +1601,7 @@ void R_DrawPlayerSprites ()
} }
} }
centeryfrac = centerhack; CenterY = centerhack;
centery = centerhack >> FRACBITS;
} }
} }
@ -1914,8 +1903,8 @@ void R_DrawSprite (vissprite_t *spr)
if (!spr->bIsVoxel && spr->pic == NULL) if (!spr->bIsVoxel && spr->pic == NULL)
{ {
// kg3D - reject invisible parts // kg3D - reject invisible parts
if ((fake3D & FAKE3D_CLIPBOTTOM) && spr->gz <= sclipBottom) return; if ((fake3D & FAKE3D_CLIPBOTTOM) && spr->gpos.Z <= sclipBottom) return;
if ((fake3D & FAKE3D_CLIPTOP) && spr->gz >= sclipTop) return; if ((fake3D & FAKE3D_CLIPTOP) && spr->gpos.Z >= sclipTop) return;
R_DrawParticle (spr); R_DrawParticle (spr);
return; return;
} }
@ -1940,7 +1929,7 @@ void R_DrawSprite (vissprite_t *spr)
{ {
if (!(fake3D & FAKE3D_CLIPTOP)) if (!(fake3D & FAKE3D_CLIPTOP))
{ {
sclipTop = spr->sector->ceilingplane.ZatPointFixed(viewx, viewy); sclipTop = spr->sector->ceilingplane.ZatPointFixed(ViewPos);
} }
sector_t *sec = NULL; sector_t *sec = NULL;
for (i = spr->sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) for (i = spr->sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--)
@ -2013,7 +2002,7 @@ void R_DrawSprite (vissprite_t *spr)
{ // diminished light { // diminished light
spriteshade = LIGHT2SHADE(sec->lightlevel + r_actualextralight); spriteshade = LIGHT2SHADE(sec->lightlevel + r_actualextralight);
spr->Style.colormap = mybasecolormap->Maps + (GETPALOOKUP ( spr->Style.colormap = mybasecolormap->Maps + (GETPALOOKUP (
(fixed_t)DivScale12 (r_SpriteVisibility, MAX(MINZ, spr->depth)), spriteshade) << COLORMAPSHIFT); (fixed_t)DivScale12 (r_SpriteVisibility, xs_Fix<20>::ToFix(MAX(MINZ, (double)spr->depth))), spriteshade) << COLORMAPSHIFT);
} }
} }
} }
@ -2028,8 +2017,8 @@ void R_DrawSprite (vissprite_t *spr)
// Clip the sprite against deep water and/or fake ceilings. // Clip the sprite against deep water and/or fake ceilings.
// [RH] rewrote this to be based on which part of the sector is really visible // [RH] rewrote this to be based on which part of the sector is really visible
fixed_t scale = MulScale19 (InvZtoScale, spr->idepth); double scale = InvZtoScale * spr->idepth;
fixed_t hzb = FIXED_MIN, hzt = FIXED_MAX; double hzb = DBL_MIN, hzt = DBL_MAX;
if (spr->bIsVoxel && spr->floorclip != 0) if (spr->bIsVoxel && spr->floorclip != 0)
{ {
@ -2040,8 +2029,8 @@ void R_DrawSprite (vissprite_t *spr)
{ // only things in specially marked sectors { // only things in specially marked sectors
if (spr->FakeFlatStat != FAKED_AboveCeiling) if (spr->FakeFlatStat != FAKED_AboveCeiling)
{ {
fixed_t hz = spr->heightsec->floorplane.ZatPointFixed(spr->gx, spr->gy); double hz = spr->heightsec->floorplane.ZatPoint(spr->gpos);
fixed_t h = (centeryfrac - FixedMul (hz-viewz, scale)) >> FRACBITS; int h = xs_RoundToInt(CenterY - (hz - ViewPos.Z) * scale);
if (spr->FakeFlatStat == FAKED_BelowFloor) if (spr->FakeFlatStat == FAKED_BelowFloor)
{ // seen below floor: clip top { // seen below floor: clip top
@ -2062,8 +2051,8 @@ void R_DrawSprite (vissprite_t *spr)
} }
if (spr->FakeFlatStat != FAKED_BelowFloor && !(spr->heightsec->MoreFlags & SECF_FAKEFLOORONLY)) if (spr->FakeFlatStat != FAKED_BelowFloor && !(spr->heightsec->MoreFlags & SECF_FAKEFLOORONLY))
{ {
fixed_t hz = spr->heightsec->ceilingplane.ZatPointFixed(spr->gx, spr->gy); double hz = spr->heightsec->ceilingplane.ZatPoint(spr->gpos);
fixed_t h = (centeryfrac - FixedMul (hz-viewz, scale)) >> FRACBITS; int h = xs_RoundToInt(CenterY - (hz - ViewPos.Z) * scale);
if (spr->FakeFlatStat == FAKED_AboveCeiling) if (spr->FakeFlatStat == FAKED_AboveCeiling)
{ // seen above ceiling: clip bottom { // seen above ceiling: clip bottom
@ -2086,7 +2075,7 @@ void R_DrawSprite (vissprite_t *spr)
// killough 3/27/98: end special clipping for deep water / fake ceilings // killough 3/27/98: end special clipping for deep water / fake ceilings
else if (!spr->bIsVoxel && spr->floorclip) else if (!spr->bIsVoxel && spr->floorclip)
{ // [RH] Move floorclip stuff from R_DrawVisSprite to here { // [RH] Move floorclip stuff from R_DrawVisSprite to here
int clip = ((centeryfrac - FixedMul (spr->texturemid - int clip = ((FLOAT2FIXED(CenterY) - FixedMul (spr->texturemid -
(spr->pic->GetHeight() << FRACBITS) + (spr->pic->GetHeight() << FRACBITS) +
spr->floorclip, spr->yscale)) >> FRACBITS); spr->floorclip, spr->yscale)) >> FRACBITS);
if (clip < botclip) if (clip < botclip)
@ -2099,16 +2088,16 @@ void R_DrawSprite (vissprite_t *spr)
{ {
if (!spr->bIsVoxel) if (!spr->bIsVoxel)
{ {
fixed_t h = sclipBottom; double hz = sclipBottom;
if (spr->fakefloor) if (spr->fakefloor)
{ {
fixed_t floorz = spr->fakefloor->top.plane->Zat0(); double floorz = spr->fakefloor->top.plane->Zat0();
if (viewz > floorz && floorz == sclipBottom ) if (ViewPos.Z > floorz && floorz == sclipBottom )
{ {
h = spr->fakefloor->bottom.plane->Zat0(); hz = spr->fakefloor->bottom.plane->Zat0();
} }
} }
h = (centeryfrac - FixedMul(h-viewz, scale)) >> FRACBITS; int h = xs_RoundToInt(CenterY - (hz - ViewPos.Z) * scale);
if (h < botclip) if (h < botclip)
{ {
botclip = MAX<short>(0, h); botclip = MAX<short>(0, h);
@ -2120,17 +2109,16 @@ void R_DrawSprite (vissprite_t *spr)
{ {
if (!spr->bIsVoxel) if (!spr->bIsVoxel)
{ {
fixed_t h = sclipTop; double hz = sclipTop;
if (spr->fakeceiling != NULL) if (spr->fakeceiling != NULL)
{ {
fixed_t ceilingZ = spr->fakeceiling->bottom.plane->Zat0(); double ceilingZ = spr->fakeceiling->bottom.plane->Zat0();
if (viewz < ceilingZ && ceilingZ == sclipTop) if (ViewPos.Z < ceilingZ && ceilingZ == sclipTop)
{ {
h = spr->fakeceiling->top.plane->Zat0(); hz = spr->fakeceiling->top.plane->Zat0();
} }
} }
h = (centeryfrac - FixedMul (h-viewz, scale)) >> FRACBITS; int h = xs_RoundToInt(CenterY - (hz - ViewPos.Z) * scale);
if (h > topclip) if (h > topclip)
{ {
topclip = MIN<short>(h, viewheight); topclip = MIN<short>(h, viewheight);
@ -2206,7 +2194,7 @@ void R_DrawSprite (vissprite_t *spr)
r1 = MAX<int> (ds->x1, x1); r1 = MAX<int> (ds->x1, x1);
r2 = MIN<int> (ds->x2, x2); r2 = MIN<int> (ds->x2, x2);
fixed_t neardepth, fardepth; float neardepth, fardepth;
if (!spr->bWallSprite) if (!spr->bWallSprite)
{ {
if (ds->sz1 < ds->sz2) if (ds->sz1 < ds->sz2)
@ -2220,8 +2208,8 @@ void R_DrawSprite (vissprite_t *spr)
} }
// Check if sprite is in front of draw seg: // Check if sprite is in front of draw seg:
if ((!spr->bWallSprite && neardepth > spr->depth) || ((spr->bWallSprite || fardepth > spr->depth) && if ((!spr->bWallSprite && neardepth > spr->depth) || ((spr->bWallSprite || fardepth > spr->depth) &&
DMulScale32(spr->gy - ds->curline->v1->fixY(), ds->curline->v2->fixX() - ds->curline->v1->fixX(), (spr->gpos.Y - ds->curline->v1->fY()) * (ds->curline->v2->fX() - ds->curline->v1->fX()) -
ds->curline->v1->fixX() - spr->gx, ds->curline->v2->fixY() - ds->curline->v1->fixY()) <= 0)) (spr->gpos.X - ds->curline->v1->fX()) * (ds->curline->v2->fY() - ds->curline->v1->fY()) <= 0))
{ {
// seg is behind sprite, so draw the mid texture if it has one // seg is behind sprite, so draw the mid texture if it has one
if (ds->CurrentPortalUniq == CurrentPortalUniq && // [ZZ] instead, portal uniq check is made here if (ds->CurrentPortalUniq == CurrentPortalUniq && // [ZZ] instead, portal uniq check is made here
@ -2307,8 +2295,8 @@ void R_DrawSprite (vissprite_t *spr)
{ {
clearbufshort(cliptop + x2, viewwidth - x2, viewheight); clearbufshort(cliptop + x2, viewwidth - x2, viewheight);
} }
int minvoxely = spr->gzt <= hzt ? 0 : (spr->gzt - hzt) / spr->yscale; int minvoxely = spr->gzt <= hzt ? 0 : FLOAT2FIXED(spr->gzt - hzt) / spr->yscale;
int maxvoxely = spr->gzb > hzb ? INT_MAX : (spr->gzt - hzb) / spr->yscale; int maxvoxely = spr->gzb > hzb ? INT_MAX : FLOAT2FIXED(spr->gzt - hzb) / spr->yscale;
R_DrawVisVoxel(spr, minvoxely, maxvoxely, cliptop, clipbot); R_DrawVisVoxel(spr, minvoxely, maxvoxely, cliptop, clipbot);
} }
spr->Style.colormap = colormap; spr->Style.colormap = colormap;
@ -2360,7 +2348,7 @@ void R_DrawMaskedSingle (bool renew)
} }
} }
void R_DrawHeightPlanes(fixed_t height); // kg3D - fake planes void R_DrawHeightPlanes(double height); // kg3D - fake planes
void R_DrawMasked (void) void R_DrawMasked (void)
{ {
@ -2376,7 +2364,7 @@ void R_DrawMasked (void)
HeightLevel *hl; HeightLevel *hl;
// ceilings // ceilings
for (hl = height_cur; hl != NULL && hl->height >= viewz; hl = hl->prev) for (hl = height_cur; hl != NULL && hl->height >= ViewPos.Z; hl = hl->prev)
{ {
if (hl->next) if (hl->next)
{ {
@ -2397,7 +2385,7 @@ void R_DrawMasked (void)
sclipTop = height_top->height; sclipTop = height_top->height;
R_DrawMaskedSingle(true); R_DrawMaskedSingle(true);
hl = height_top; hl = height_top;
for (hl = height_top; hl != NULL && hl->height < viewz; hl = hl->next) for (hl = height_top; hl != NULL && hl->height < ViewPos.Z; hl = hl->next)
{ {
R_DrawHeightPlanes(hl->height); R_DrawHeightPlanes(hl->height);
if (hl->next) if (hl->next)
@ -2421,11 +2409,10 @@ void R_DrawMasked (void)
void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade, int fakeside) void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade, int fakeside)
{ {
fixed_t tr_x; double tr_x, tr_y;
fixed_t tr_y; double tx, ty;
fixed_t tx, ty; double tz, tiz;
fixed_t tz, tiz; double xscale, yscale;
fixed_t xscale, yscale;
int x1, x2, y1, y2; int x1, x2, y1, y2;
vissprite_t* vis; vissprite_t* vis;
sector_t* heightsec = NULL; sector_t* heightsec = NULL;
@ -2436,16 +2423,16 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
return; return;
// transform the origin point // transform the origin point
tr_x = FLOAT2FIXED(particle->Pos.X - ViewPos.X); tr_x = particle->Pos.X - ViewPos.X;
tr_y = FLOAT2FIXED(particle->Pos.Y - ViewPos.Y); tr_y = particle->Pos.Y - ViewPos.Y;
tz = DMulScale20 (tr_x, viewtancos, tr_y, viewtansin); tz = tr_x * ViewTanCos + tr_y * ViewTanSin;
// particle is behind view plane? // particle is behind view plane?
if (tz < MINZ) if (tz < MINZ)
return; return;
tx = DMulScale20 (tr_x, viewsin, -tr_y, viewcos); tx = tr_x * ViewSin - tr_y * ViewCos;
// Flip for mirrors // Flip for mirrors
if (MirrorFlags & RF_XFLIP) if (MirrorFlags & RF_XFLIP)
@ -2454,26 +2441,25 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
} }
// too far off the side? // too far off the side?
if (tz <= abs (tx)) if (tz <= fabs(tx))
return; return;
tiz = 268435456 / tz; tiz = 1 / tz;
xscale = centerx * tiz; xscale = centerx * tiz;
// calculate edges of the shape // calculate edges of the shape
int psize = particle->size << (12-3); double psize = particle->size / 8.0;
x1 = MAX<int> (WindowLeft, (centerxfrac + MulScale12 (tx-psize, xscale)) >> FRACBITS); x1 = MAX<int>(WindowLeft, centerx + xs_RoundToInt((tx - psize) * xscale));
x2 = MIN<int> (WindowRight, (centerxfrac + MulScale12 (tx+psize, xscale)) >> FRACBITS); x2 = MIN<int>(WindowRight, centerx + xs_RoundToInt((tx + psize) * xscale));
if (x1 >= x2) if (x1 >= x2)
return; return;
yscale = MulScale16(yaspectmul, xscale); yscale = xs_RoundToInt(YaspectMul * xscale);
ty = FLOAT2FIXED(particle->Pos.Z - ViewPos.Z); ty = FLOAT2FIXED(particle->Pos.Z - ViewPos.Z);
psize <<= 4; y1 = xs_RoundToInt(CenterY - (ty + psize) * yscale);
y1 = (centeryfrac - FixedMul (ty+psize, yscale)) >> FRACBITS; y2 = xs_RoundToInt(CenterY - (ty - psize) * yscale);
y2 = (centeryfrac - FixedMul (ty-psize, yscale)) >> FRACBITS;
// Clip the particle now. Because it's a point and projected as its subsector is // Clip the particle now. Because it's a point and projected as its subsector is
// entered, we don't need to clip it to drawsegs like a normal sprite. // entered, we don't need to clip it to drawsegs like a normal sprite.
@ -2540,16 +2526,13 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
vis = R_NewVisSprite (); vis = R_NewVisSprite ();
vis->CurrentPortalUniq = CurrentPortalUniq; vis->CurrentPortalUniq = CurrentPortalUniq;
vis->heightsec = heightsec; vis->heightsec = heightsec;
vis->xscale = xscale; vis->yscale = vis->xscale = FLOAT2FIXED(xscale);
// vis->yscale = FixedMul (xscale, InvZtoScale); // vis->yscale = FixedMul (xscale, InvZtoScale);
vis->yscale = xscale; vis->depth = (float)tz;
vis->depth = tz; vis->idepth = float(1 / tz);
vis->idepth = (DWORD)DivScale32 (1, tz) >> 1; vis->gpos = { (float)particle->Pos.X, (float)particle->Pos.Y, (float)particle->Pos.Z };
vis->gx = FLOAT2FIXED(particle->Pos.X); vis->y1 = y1;
vis->gy = FLOAT2FIXED(particle->Pos.Y); vis->y2 = y2;
vis->gz = FLOAT2FIXED(particle->Pos.Z);
vis->gzb = y1;
vis->gzt = y2;
vis->x1 = x1; vis->x1 = x1;
vis->x2 = x2; vis->x2 = x2;
vis->Translation = 0; vis->Translation = 0;
@ -2569,14 +2552,15 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
{ {
vis->Style.colormap = fixedcolormap; vis->Style.colormap = fixedcolormap;
} }
else if(particle->bright) { else if (particle->bright)
{
vis->Style.colormap = map; vis->Style.colormap = map;
} }
else else
{ {
// Using MulScale15 instead of 16 makes particles slightly more visible // Using MulScale15 instead of 16 makes particles slightly more visible
// than regular sprites. // than regular sprites.
vis->ColormapNum = GETPALOOKUP(MulScale15 (tiz, r_SpriteVisibility), shade); vis->ColormapNum = GETPALOOKUP(MulScale15 (FLOAT2FIXED(tiz), r_SpriteVisibility), shade);
vis->Style.colormap = map + (vis->ColormapNum << COLORMAPSHIFT); vis->Style.colormap = map + (vis->ColormapNum << COLORMAPSHIFT);
} }
} }
@ -2597,7 +2581,7 @@ static void R_DrawMaskedSegsBehindParticle (const vissprite_t *vis)
{ {
continue; continue;
} }
if (Scale (ds->siz2 - ds->siz1, (x2 + x1)/2 - ds->sx1, ds->sx2 - ds->sx1) + ds->siz1 < vis->idepth) if ((ds->siz2 - ds->siz1) * ((x2 + x1)/2 - ds->sx1) / (ds->sx2 - ds->sx1) + ds->siz1 < vis->idepth)
{ {
// [ZZ] only draw stuff that's inside the same portal as the particle, other portals will care for themselves // [ZZ] only draw stuff that's inside the same portal as the particle, other portals will care for themselves
if (ds->CurrentPortalUniq == vis->CurrentPortalUniq) if (ds->CurrentPortalUniq == vis->CurrentPortalUniq)
@ -2613,8 +2597,8 @@ void R_DrawParticle (vissprite_t *vis)
BYTE *dest; BYTE *dest;
DWORD fg; DWORD fg;
BYTE color = vis->Style.colormap[vis->startfrac]; BYTE color = vis->Style.colormap[vis->startfrac];
int yl = vis->gzb; int yl = vis->y1;
int ycount = vis->gzt - yl + 1; int ycount = vis->y2 - yl + 1;
int x1 = vis->x1; int x1 = vis->x1;
int countbase = vis->x2 - x1; int countbase = vis->x2 - x1;
@ -2658,7 +2642,7 @@ void R_DrawParticle (vissprite_t *vis)
for (int x = x1; x < (x1+countbase); x++) for (int x = x1; x < (x1+countbase); x++)
{ {
dc_x = x; dc_x = x;
if (R_ClipSpriteColumnWithPortals(vis->gx, vis->gy, vis)) if (R_ClipSpriteColumnWithPortals(vis))
continue; continue;
dest = ylookup[yl] + x + dc_destorg; dest = ylookup[yl] + x + dc_destorg;
for (int y = 0; y < ycount; y++) for (int y = 0; y < ycount; y++)
@ -2671,10 +2655,10 @@ void R_DrawParticle (vissprite_t *vis)
} }
} }
extern fixed_t baseyaspectmul; extern double BaseYaspectMul;;
void R_DrawVoxel(fixed_t globalposx, fixed_t globalposy, fixed_t globalposz, angle_t viewang, void R_DrawVoxel(const FVector3 &globalpos, FAngle viewangle,
fixed_t dasprx, fixed_t daspry, fixed_t dasprz, angle_t dasprang, const FVector3 &dasprpos, angle_t dasprang,
fixed_t daxscale, fixed_t dayscale, FVoxel *voxobj, fixed_t daxscale, fixed_t dayscale, FVoxel *voxobj,
lighttable_t *colormap, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags) lighttable_t *colormap, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags)
{ {
@ -2689,24 +2673,25 @@ void R_DrawVoxel(fixed_t globalposx, fixed_t globalposy, fixed_t globalposz, ang
int z1a[64], z2a[64], yplc[64]; int z1a[64], z2a[64], yplc[64];
const int nytooclose = centerxwide * 2100, nytoofar = 32768*32768 - 1048576; const int nytooclose = centerxwide * 2100, nytoofar = 32768*32768 - 1048576;
const int xdimenscale = Scale(centerxwide, yaspectmul, 160); const int xdimenscale = FLOAT2FIXED(centerxwide * YaspectMul / 160);
const double centerxwide_f = centerxwide; const double centerxwide_f = centerxwide;
const double centerxwidebig_f = centerxwide_f * 65536*65536*8; const double centerxwidebig_f = centerxwide_f * 65536*65536*8;
// Convert to Build's coordinate system. // Convert to Build's coordinate system.
globalposx = globalposx >> 12; fixed_t globalposx = xs_Fix<4>::ToFix(globalpos.X);
globalposy = -globalposy >> 12; fixed_t globalposy = xs_Fix<4>::ToFix(-globalpos.Y);
globalposz = -globalposz >> 8; fixed_t globalposz = xs_Fix<8>::ToFix(-globalpos.Z);
dasprx = dasprx >> 12; fixed_t dasprx = xs_Fix<4>::ToFix(dasprpos.X);
daspry = -daspry >> 12; fixed_t daspry = xs_Fix<4>::ToFix(-dasprpos.Y);
dasprz = -dasprz >> 8; fixed_t dasprz = xs_Fix<8>::ToFix(-dasprpos.Z);
// Shift the scales from 16 bits of fractional precision to 6. // Shift the scales from 16 bits of fractional precision to 6.
// Also do some magic voodoo scaling to make them the right size. // Also do some magic voodoo scaling to make them the right size.
daxscale = daxscale / (0xC000 >> 6); daxscale = daxscale / (0xC000 >> 6);
dayscale = dayscale / (0xC000 >> 6); dayscale = dayscale / (0xC000 >> 6);
angle_t viewang = viewangle.BAMs();
cosang = finecosine[viewang >> ANGLETOFINESHIFT] >> 2; cosang = finecosine[viewang >> ANGLETOFINESHIFT] >> 2;
sinang = -finesine[viewang >> ANGLETOFINESHIFT] >> 2; sinang = -finesine[viewang >> ANGLETOFINESHIFT] >> 2;
sprcosang = finecosine[dasprang >> ANGLETOFINESHIFT] >> 2; sprcosang = finecosine[dasprang >> ANGLETOFINESHIFT] >> 2;
@ -2717,7 +2702,7 @@ void R_DrawVoxel(fixed_t globalposx, fixed_t globalposy, fixed_t globalposz, ang
// Select mip level // Select mip level
i = abs(DMulScale6(dasprx - globalposx, cosang, daspry - globalposy, sinang)); i = abs(DMulScale6(dasprx - globalposx, cosang, daspry - globalposy, sinang));
i = DivScale6(i, MIN(daxscale, dayscale)); i = DivScale6(i, MIN(daxscale, dayscale));
j = FocalLengthX >> 3; j = xs_Fix<13>::ToFix(FocalLengthX);
for (k = 0; i >= j && k < voxobj->NumMips; ++k) for (k = 0; i >= j && k < voxobj->NumMips; ++k)
{ {
i >>= 1; i >>= 1;
@ -2730,8 +2715,8 @@ void R_DrawVoxel(fixed_t globalposx, fixed_t globalposy, fixed_t globalposz, ang
maxslabz >>= k; maxslabz >>= k;
daxscale <<= (k+8); dayscale <<= (k+8); daxscale <<= (k+8); dayscale <<= (k+8);
dazscale = FixedDiv(dayscale, baseyaspectmul); dazscale = FixedDiv(dayscale, FLOAT2FIXED(BaseYaspectMul));
daxscale = FixedDiv(daxscale, yaspectmul); daxscale = fixed_t(daxscale / YaspectMul);
daxscale = Scale(daxscale, xdimenscale, centerxwide << 9); daxscale = Scale(daxscale, xdimenscale, centerxwide << 9);
dayscale = Scale(dayscale, FixedMul(xdimenscale, viewingrangerecip), centerxwide << 9); dayscale = Scale(dayscale, FixedMul(xdimenscale, viewingrangerecip), centerxwide << 9);

View file

@ -32,13 +32,17 @@
struct vissprite_t struct vissprite_t
{ {
short x1, x2; short x1, x2;
fixed_t gx, gy, gz; // origin in world coordinates FVector3 gpos; // origin in world coordinates
union
{
float gzb, gzt; // global bottom / top for silhouette clipping
int y1, y2; // top / bottom of particle on screen
};
angle_t angle; angle_t angle;
fixed_t gzb, gzt; // global bottom / top for silhouette clipping
fixed_t xscale, yscale; fixed_t xscale, yscale;
fixed_t depth; float depth;
fixed_t idepth; // 1/z float idepth; // 1/z
fixed_t deltax, deltay; float deltax, deltay;
DWORD FillColor; DWORD FillColor;
fixed_t floorclip; fixed_t floorclip;
union union
@ -63,8 +67,8 @@ struct vissprite_t
// Used by voxels // Used by voxels
struct struct
{ {
fixed_t vx, vy, vz; // view origin FVector3 vpos; // view origin
angle_t vang; // view angle FAngle vang; // view angle
}; };
}; };
sector_t *heightsec; // killough 3/27/98: height sector for underwater/fake ceiling sector_t *heightsec; // killough 3/27/98: height sector for underwater/fake ceiling
@ -81,6 +85,9 @@ struct vissprite_t
DWORD Translation; // [RH] for color translation DWORD Translation; // [RH] for color translation
visstyle_t Style; visstyle_t Style;
int CurrentPortalUniq; // [ZZ] to identify the portal that this thing is in. used for clipping. int CurrentPortalUniq; // [ZZ] to identify the portal that this thing is in. used for clipping.
vissprite_t() {}
vissprite_t &vissprite_t::operator= (const vissprite_t &o) { memcpy(this, &o, sizeof *this); return *this; }
}; };
struct particle_t; struct particle_t;
@ -128,9 +135,9 @@ void R_CheckOffscreenBuffer(int width, int height, bool spansonly);
enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 }; enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 };
void R_DrawVoxel(fixed_t viewx, fixed_t viewy, fixed_t viewz, angle_t viewangle, void R_DrawVoxel(const FVector3 &viewpos, FAngle viewangle,
fixed_t dasprx, fixed_t daspry, fixed_t dasprz, angle_t dasprang, const FVector3 &sprpos, angle_t dasprang,
fixed_t daxscale, fixed_t dayscale, FVoxel *voxobj, fixed_t daxscale, fixed_t dayscale, struct FVoxel *voxobj,
lighttable_t *colormap, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags); lighttable_t *colormap, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags);
void R_ClipVisSprite (vissprite_t *vis, int xl, int xh); void R_ClipVisSprite (vissprite_t *vis, int xl, int xh);

View file

@ -123,8 +123,8 @@ int otic;
sector_t *viewsector; sector_t *viewsector;
fixed_t viewcos, viewtancos; double ViewCos, ViewTanCos;
fixed_t viewsin, viewtansin; double ViewSin, ViewTanSin;
AActor *camera; // [RH] camera to draw from. doesn't have to be a player AActor *camera; // [RH] camera to draw from. doesn't have to be a player
@ -142,7 +142,7 @@ int WidescreenRatio;
int setblocks; int setblocks;
int extralight; int extralight;
bool setsizeneeded; bool setsizeneeded;
fixed_t FocalTangent; double FocalTangent;
unsigned int R_OldBlend = ~0; unsigned int R_OldBlend = ~0;
int validcount = 1; // increment every time a check is made int validcount = 1; // increment every time a check is made
@ -150,9 +150,8 @@ int FieldOfView = 2048; // Fineangles in the SCREENWIDTH wide window
FCanvasTextureInfo *FCanvasTextureInfo::List; FCanvasTextureInfo *FCanvasTextureInfo::List;
fixed_t viewx, viewy, viewz; DVector3a view;
angle_t viewangle; DAngle viewpitch;
int viewpitch;
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
@ -463,7 +462,7 @@ void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight)
fov = 170*FINEANGLES/360; fov = 170*FINEANGLES/360;
} }
FocalTangent = finetangent[FINEANGLES/4+fov/2]; FocalTangent = FIXED2FLOAT(finetangent[FINEANGLES/4+fov/2]);
Renderer->SetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio); Renderer->SetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio);
} }
@ -737,11 +736,11 @@ void R_ResetViewInterpolation ()
void R_SetViewAngle () void R_SetViewAngle ()
{ {
viewsin = FLOAT2FIXED(ViewAngle.Sin()); ViewSin = ViewAngle.Sin();
viewcos = FLOAT2FIXED(ViewAngle.Cos()); ViewCos = ViewAngle.Cos();
viewtansin = FixedMul (FocalTangent, viewsin); ViewTanSin = FocalTangent * ViewSin;
viewtancos = FixedMul (FocalTangent, viewcos); ViewTanCos = FocalTangent * ViewCos;
} }
//========================================================================== //==========================================================================
@ -1108,12 +1107,6 @@ void R_SetupFrame (AActor *actor)
} }
} }
viewx = FLOAT2FIXED(ViewPos.X);
viewy = FLOAT2FIXED(ViewPos.Y);
viewz = FLOAT2FIXED(ViewPos.Z);
viewangle = ViewAngle.BAMs();
viewpitch = ViewPitch.BAMs();
Renderer->CopyStackedViewParameters(); Renderer->CopyStackedViewParameters();
Renderer->SetupFrame(player); Renderer->SetupFrame(player);

View file

@ -17,18 +17,14 @@ extern DAngle ViewAngle;
extern DAngle ViewPitch; extern DAngle ViewPitch;
extern DVector3 ViewPath[2]; extern DVector3 ViewPath[2];
extern fixed_t viewx, viewy, viewz;
extern angle_t viewangle;
extern int viewpitch;
extern "C" int centerx, centerxwide; extern "C" int centerx, centerxwide;
extern "C" int centery; extern "C" int centery;
extern int setblocks; extern int setblocks;
extern fixed_t viewtancos; extern double ViewTanCos;
extern fixed_t viewtansin; extern double ViewTanSin;
extern fixed_t FocalTangent; extern double FocalTangent;
extern bool r_NoInterpolate; extern bool r_NoInterpolate;
extern int validcount; extern int validcount;

View file

@ -199,8 +199,8 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms)
unmaskedSpan[1].Length = 0; unmaskedSpan[1].Length = 0;
} }
fixed_t centeryback = centeryfrac; double centeryback = CenterY;
centeryfrac = 0; CenterY = 0;
sprtopscreen = FLOAT2FIXED(y0); sprtopscreen = FLOAT2FIXED(y0);
// There is not enough precision in the drawing routines to keep the full // There is not enough precision in the drawing routines to keep the full
@ -225,7 +225,7 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms)
//dc_texturemid = FLOAT2FIXED((-y0) * iyscale); //dc_texturemid = FLOAT2FIXED((-y0) * iyscale);
//dc_iscale = 0xffffffffu / (unsigned)spryscale; //dc_iscale = 0xffffffffu / (unsigned)spryscale;
dc_iscale = DivScale32(1, spryscale); dc_iscale = DivScale32(1, spryscale);
dc_texturemid = FixedMul(-sprtopscreen, dc_iscale) + FixedMul(centeryfrac-FRACUNIT, dc_iscale); dc_texturemid = FixedMul(-sprtopscreen, dc_iscale) + xs_ToInt((CenterY - 1) * dc_iscale);
fixed_t frac = 0; fixed_t frac = 0;
double xiscale = img->GetWidth() / parms.destwidth; double xiscale = img->GetWidth() / parms.destwidth;
double x2 = x0 + parms.destwidth; double x2 = x0 + parms.destwidth;
@ -325,7 +325,7 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms)
frac += xiscale_i; frac += xiscale_i;
} }
} }
centeryfrac = centeryback; CenterY = centeryback;
} }
R_FinishSetPatchStyle (); R_FinishSetPatchStyle ();