From 3c7d0c971fea4a00747893ed2183bf4c47a146fa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 22 Apr 2016 17:48:25 +0200 Subject: [PATCH 01/12] - fixed: It seems it is not allowed to serialize any thinker before the actual thinker chain is serialized. This means that sector_t::floordata, ceilingdata and lightdata's handling had to be moved to P_SerializeWorldActors. --- src/p_saveg.cpp | 8 ++++---- src/version.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index efcbb2406..54215568a 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -347,9 +347,6 @@ void P_SerializeWorld (FArchive &arc) << sec->seqType << sec->friction << sec->movefactor - << sec->floordata - << sec->ceilingdata - << sec->lightingdata << sec->stairlock << sec->prevsec << sec->nextsec @@ -459,7 +456,10 @@ void P_SerializeWorldActors(FArchive &arc) for (i = 0, sec = sectors; i < numsectors; i++, sec++) { arc << sec->SoundTarget - << sec->SecActTarget; + << sec->SecActTarget + << sec->floordata + << sec->ceilingdata + << sec->lightingdata; } for (auto &s : sectorPortals) { diff --git a/src/version.h b/src/version.h index 46c8abf66..5405dba98 100644 --- a/src/version.h +++ b/src/version.h @@ -72,11 +72,11 @@ const char *GetVersionString(); // SAVESIG should match SAVEVER. // MINSAVEVER is the minimum level snapshot version that can be loaded. -#define MINSAVEVER 4540 +#define MINSAVEVER 4541 // Use 4500 as the base git save version, since it's higher than the // SVN revision ever got. -#define SAVEVER 4540 +#define SAVEVER 4541 #define SAVEVERSTRINGIFY2(x) #x #define SAVEVERSTRINGIFY(x) SAVEVERSTRINGIFY2(x) From bab0ed451a1f7c881fce0286703184ad925cbdbc Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 6 Apr 2016 22:49:10 -0500 Subject: [PATCH 02/12] No more warnings when building re2c with VC++ --- tools/re2c/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/re2c/CMakeLists.txt b/tools/re2c/CMakeLists.txt index fb3198ba7..b362a3b84 100644 --- a/tools/re2c/CMakeLists.txt +++ b/tools/re2c/CMakeLists.txt @@ -6,8 +6,8 @@ include( CheckFunctionExists ) include( CheckTypeSize ) if( MSVC ) - # Runtime type information is required - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR" ) + # Runtime type information is required and don't complain about uint32_t to bool conversions + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR /wd4800" ) endif() set( PACKAGE_NAME re2c ) From ded3f9245234481634cba582c9985e42a2d421cc Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 14 Apr 2016 12:40:14 -0500 Subject: [PATCH 03/12] Commence renderer floatification --- src/r_3dfloors.cpp | 4 +- src/r_3dfloors.h | 6 +- src/r_bsp.cpp | 167 +++++++++---------- src/r_bsp.h | 18 +- src/r_defs.h | 8 +- src/r_drawt.cpp | 4 +- src/r_main.cpp | 165 +++++++++--------- src/r_main.h | 23 ++- src/r_plane.cpp | 147 +++++++--------- src/r_plane.h | 4 +- src/r_segs.cpp | 408 +++++++++++++++++++++++---------------------- src/r_segs.h | 6 +- src/r_things.cpp | 373 ++++++++++++++++++++--------------------- src/r_things.h | 27 +-- src/r_utility.cpp | 27 ++- src/r_utility.h | 10 +- src/v_draw.cpp | 8 +- 17 files changed, 672 insertions(+), 733 deletions(-) diff --git a/src/r_3dfloors.cpp b/src/r_3dfloors.cpp index 590d65515..ee7dc4c81 100644 --- a/src/r_3dfloors.cpp +++ b/src/r_3dfloors.cpp @@ -21,8 +21,8 @@ F3DFloor *fakeFloor; fixed_t fakeHeight; fixed_t fakeAlpha; int fakeActive = 0; -fixed_t sclipBottom; -fixed_t sclipTop; +double sclipBottom; +double sclipTop; HeightLevel *height_top = NULL; HeightLevel *height_cur = NULL; int CurrentMirror = 0; diff --git a/src/r_3dfloors.h b/src/r_3dfloors.h index e95d35045..cacb97444 100644 --- a/src/r_3dfloors.h +++ b/src/r_3dfloors.h @@ -7,7 +7,7 @@ struct HeightLevel { - fixed_t height; + double height; struct HeightLevel *prev; struct HeightLevel *next; }; @@ -51,8 +51,8 @@ extern int fake3D; extern F3DFloor *fakeFloor; extern fixed_t fakeAlpha; extern int fakeActive; -extern fixed_t sclipBottom; -extern fixed_t sclipTop; +extern double sclipBottom; +extern double sclipTop; extern HeightLevel *height_top; extern HeightLevel *height_cur; extern int CurrentMirror; diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 39dd22766..1cc2fa918 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -336,7 +336,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, { sector_t *heightsec = viewsector->heightsec; bool underwater = r_fakingunderwater || - (heightsec && heightsec->floorplane.PointOnSide(viewx, viewy, viewz) <= 0); + (heightsec && heightsec->floorplane.PointOnSide(ViewPos) <= 0); bool doorunderwater = false; 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); - fixed_t orgceilz = sec->ceilingplane.ZatPointFixed(viewx, viewy); + double refceilz = s->ceilingplane.ZatPoint(ViewPos); + double orgceilz = sec->ceilingplane.ZatPoint(ViewPos); #if 1 // [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. if (back && !r_fakingunderwater && curline->frontsector->heightsec == NULL) { - if (rw_frontcz1 <= s->floorplane.ZatPointFixed (curline->v1) && - rw_frontcz2 <= s->floorplane.ZatPointFixed(curline->v2)) + if (rw_frontcz1 <= s->floorplane.ZatPoint(curline->v1) && + rw_frontcz2 <= s->floorplane.ZatPoint(curline->v2)) { // Check that the window is actually visible 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; } - else if (heightsec && heightsec->ceilingplane.PointOnSide(viewx, viewy, viewz) <= 0 && + else if (heightsec && heightsec->ceilingplane.PointOnSide(ViewPos) <= 0 && orgceilz > refceilz && !(s->MoreFlags & SECF_FAKEFLOORONLY)) { // Above-ceiling hack 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 bool solid; - fixed_t tx1, tx2, ty1, ty2; + DVector2 pt1, pt2; curline = line; // [RH] Color if not texturing line dc_color = (((int)(line - segs) * 8) + 4) & 255; - tx1 = line->v1->fixX() - viewx; - tx2 = line->v2->fixX() - viewx; - ty1 = line->v1->fixY() - viewy; - ty2 = line->v2->fixY() - viewy; + pt1 = line->v1->fPos() - ViewPos; + pt2 = line->v2->fPos() - ViewPos; // 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; - if (WallC.Init(tx1, ty1, tx2, ty2, 32)) + if (WallC.Init(pt1, pt2, 32.0 / (1 << 12))) return; if (WallC.sx1 >= WindowRight || WallC.sx2 <= WindowLeft) @@ -591,7 +589,7 @@ void R_AddLine (seg_t *line) { 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)) @@ -773,57 +771,57 @@ void R_AddLine (seg_t *line) // // 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); - tx2 = DMulScale20(x2, viewsin, -y2, viewcos); + tleft.X = float(pt1.X * ViewSin - pt1.Y * ViewCos); + tright.X = float(pt2.X * ViewSin - pt2.Y * ViewCos); - ty1 = DMulScale20(x1, viewtancos, y1, viewtansin); - ty2 = DMulScale20(x2, viewtancos, y2, viewtansin); + tleft.Y = float(pt1.X * ViewTanCos + pt1.Y * ViewTanSin); + tright.Y = float(pt2.X * ViewTanCos + pt2.Y * ViewTanSin); if (MirrorFlags & RF_XFLIP) { - int t = 256 - tx1; - tx1 = 256 - tx2; - tx2 = t; - swapvalues(ty1, ty2); + float t = -tleft.X; + tleft.X = -tright.X; + tright.X = t; + 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 (ty1 == 0) return true; - sx1 = (centerxfrac + Scale(tx1, centerxfrac, ty1)) >> FRACBITS; - if (tx1 >= 0) sx1 = MIN(viewwidth, sx1+1); // fix for signed divide - sz1 = ty1; + if (tleft.X > tleft.Y) return true; // left edge is off the right side + if (tleft.Y == 0) return true; + sx1 = xs_ToInt(CenterX + tleft.X * CenterX / tleft.Y); + if (tleft.X >= 0) sx1 = MIN(viewwidth, sx1+1); // fix for signed divide + sz1 = tleft.Y; } else { - if (tx2 < -ty2) return true; // wall is off the left side - fixed_t den = tx1 - tx2 - ty2 + ty1; + if (tright.X < -tright.Y) return true; // wall is off the left side + float den = tleft.X - tright.X - tright.Y + tleft.Y; if (den == 0) return true; 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) return true; - if (tx2 <= ty2) + if (tright.X <= tright.Y) { - if (tx2 < -ty2) return true; // right edge is off the left side - if (ty2 == 0) return true; - sx2 = (centerxfrac + Scale(tx2, centerxfrac, ty2)) >> FRACBITS; - if (tx2 >= 0) sx2 = MIN(viewwidth, sx2+1); // fix for signed divide - sz2 = ty2; + if (tright.X < -tright.Y) return true; // right edge is off the left side + if (tright.Y == 0) return true; + sx2 = xs_ToInt(CenterX + tright.X * CenterX / tright.Y); + if (tright.X >= 0) sx2 = MIN(viewwidth, sx2+1); // fix for signed divide + sz2 = tright.Y; } else { - if (tx1 > ty1) return true; // wall is off the right side - fixed_t den = ty2 - ty1 - tx2 + tx1; + if (tleft.X > tleft.Y) return true; // wall is off the right side + float den = tright.Y - tleft.Y - tright.X + tleft.X; if (den == 0) return true; 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) @@ -834,28 +832,25 @@ bool FWallCoords::Init(int x1, int y1, int x2, int y2, int too_close) void FWallTmapVals::InitFromWallCoords(const FWallCoords *wallc) { + const FVector2 *left = &wallc->tleft; + const FVector2 *right = &wallc->tright; + if (MirrorFlags & RF_XFLIP) { - UoverZorg = (float)wallc->tx2 * centerx; - 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); + swapvalues(left, right); } + 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 - fixed_t fullx1 = DMulScale20 (tx1, viewsin, -ty1, viewcos); - fixed_t fullx2 = DMulScale20 (tx2, viewsin, -ty2, viewcos); - fixed_t fully1 = DMulScale20 (tx1, viewtancos, ty1, viewtansin); - fixed_t fully2 = DMulScale20 (tx2, viewtancos, ty2, viewtansin); + double fullx1 = left.X * ViewSin - left.Y * ViewCos; + double fullx2 = right.X * ViewSin - right.Y * ViewCos; + double fully1 = left.X * ViewTanCos + left.Y * ViewTanSin; + double fully2 = right.X * ViewTanCos + right.Y * ViewTanSin; if (MirrorFlags & RF_XFLIP) { @@ -863,10 +858,10 @@ void FWallTmapVals::InitFromLine(int tx1, int ty1, int tx2, int ty2) fullx2 = -fullx2; } - UoverZorg = (float)fullx1 * centerx; - UoverZstep = (float)(-fully1); - InvZorg = (float)(fullx1 - fullx2) * centerx; - InvZstep = (float)(fully2 - fully1); + UoverZorg = float(fullx1 * centerx); + UoverZstep = float(-fully1); + InvZorg = float((fullx1 - fullx2) * centerx); + InvZstep = float(fully2 - fully1); } // @@ -896,24 +891,24 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static int boxy; int boxpos; - fixed_t x1, y1, x2, y2; - fixed_t rx1, ry1, rx2, ry2; + double x1, y1, x2, y2; + double rx1, ry1, rx2, ry2; int sx1, sx2; cliprange_t* start; // Find the corners of the box // that define the edges from current viewpoint. - if (viewx <= bspcoord[BOXLEFT]) + if (ViewPos.X <= FIXED2DBL(bspcoord[BOXLEFT])) boxx = 0; - else if (viewx < bspcoord[BOXRIGHT]) + else if (ViewPos.X < FIXED2DBL(bspcoord[BOXRIGHT])) boxx = 1; else boxx = 2; - if (viewy >= bspcoord[BOXTOP]) + if (ViewPos.Y >= FIXED2DBL(bspcoord[BOXTOP])) boxy = 0; - else if (viewy > bspcoord[BOXBOTTOM]) + else if (ViewPos.Y > FIXED2DBL(bspcoord[BOXBOTTOM])) boxy = 1; else boxy = 2; @@ -922,36 +917,36 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static if (boxpos == 5) return true; - x1 = bspcoord[checkcoord[boxpos][0]] - viewx; - y1 = bspcoord[checkcoord[boxpos][1]] - viewy; - x2 = bspcoord[checkcoord[boxpos][2]] - viewx; - y2 = bspcoord[checkcoord[boxpos][3]] - viewy; + x1 = FIXED2DBL(bspcoord[checkcoord[boxpos][0]]) - ViewPos.X; + y1 = FIXED2DBL(bspcoord[checkcoord[boxpos][1]]) - ViewPos.Y; + x2 = FIXED2DBL(bspcoord[checkcoord[boxpos][2]]) - ViewPos.X; + y2 = FIXED2DBL(bspcoord[checkcoord[boxpos][3]]) - ViewPos.Y; // check clip list for an open space // Sitting on a line? - if (DMulScale32 (y1, x1-x2, x1, y2-y1) >= 0) + if (y1 * (x1 - x2) + x1 * (y2 - y1) >= -EQUAL_EPSILON) return true; - rx1 = DMulScale20 (x1, viewsin, -y1, viewcos); - rx2 = DMulScale20 (x2, viewsin, -y2, viewcos); - ry1 = DMulScale20 (x1, viewtancos, y1, viewtansin); - ry2 = DMulScale20 (x2, viewtancos, y2, viewtansin); + rx1 = x1 * ViewSin - y1 * ViewCos; + rx2 = x2 * ViewSin - y2 * ViewCos; + ry1 = x1 * ViewTanCos + y1 * ViewTanSin; + ry2 = x2 * ViewTanCos + y2 * ViewTanSin; if (MirrorFlags & RF_XFLIP) { - int t = 256-rx1; - rx1 = 256-rx2; + double t = -rx1; + rx1 = -rx2; rx2 = t; - swapvalues (ry1, ry2); + swapvalues(ry1, ry2); } if (rx1 >= -ry1) { if (rx1 > ry1) return false; // left edge is off the right side if (ry1 == 0) return false; - sx1 = (centerxfrac + Scale (rx1, centerxfrac, ry1)) >> FRACBITS; - if (rx1 >= 0) sx1 = MIN (viewwidth, sx1+1); // fix for signed divide + sx1 = xs_ToInt(CenterX + rx1 * CenterX / ry1); + if (rx1 >= 0) sx1 = MIN(viewwidth, sx1+1); // fix for signed divide } else { @@ -964,8 +959,8 @@ 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 (ry2 == 0) return false; - sx2 = (centerxfrac + Scale (rx2, centerxfrac, ry2)) >> FRACBITS; - if (rx2 >= 0) sx2 = MIN (viewwidth, sx2+1); // fix for signed divide + sx2 = xs_ToInt(CenterX + rx2 * CenterX / ry2); + if (rx2 >= 0) sx2 = MIN(viewwidth, sx2+1); // fix for signed divide } else { @@ -1116,7 +1111,7 @@ void R_Subsector (subsector_t *sub) 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 || portal != NULL || (frontsector->heightsec && @@ -1157,7 +1152,7 @@ void R_Subsector (subsector_t *sub) // killough 10/98: add support for skies transferred from sidedefs 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 || portal != NULL || (frontsector->heightsec && @@ -1408,7 +1403,7 @@ void R_RenderBSPNode (void *node) node_t *bsp = (node_t *)node; // 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). R_RenderBSPNode (bsp->children[side]); diff --git a/src/r_bsp.h b/src/r_bsp.h index 061583ce7..3fa1788d4 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -30,17 +30,17 @@ // The 3072 below is just an arbitrary value picked to avoid // drawing lines the player is too close to that would overflow // the texture calculations. -#define TOO_CLOSE_Z 3072 +#define TOO_CLOSE_Z (3072.0 / (1<<12)) struct FWallCoords { - fixed_t tx1, tx2; // x coords at left, right of wall in view space rx1,rx2 - fixed_t ty1, ty2; // y coords at left, right of wall in view space ry1,ry2 + FVector2 tleft; // coords at left of wall in view space rx1,ry1 + 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 - 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 @@ -49,7 +49,7 @@ struct FWallTmapVals float InvZorg, InvZstep; 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; @@ -69,9 +69,9 @@ struct drawseg_t fixed_t iscale, iscalestep; short x1, x2; // Same as sx1 and sx2, but clipped to the drawseg short sx1, sx2; // left, right of parent seg on screen - fixed_t 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 - fixed_t cx, cy, cdx, cdy; + float sz1, sz2; // z for left, right of parent seg on screen + float siz1, siz2; // 1/z for left, right of parent seg on screen + float cx, cy, cdx, cdy; fixed_t yrepeat; BYTE silhouette; // 0=none, 1=bottom, 2=top, 3=both BYTE bFogBoundary; diff --git a/src/r_defs.h b/src/r_defs.h index ad043a404..4c3406ce0 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -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 - fixed_t Zat0 () const + double Zat0() const { - return FLOAT2FIXED(negiC*D); + return negiC*D; } // Returns the value of z at (x,y) @@ -362,6 +362,10 @@ public: 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 { diff --git a/src/r_drawt.cpp b/src/r_drawt.cpp index b6dd12f32..d4b9d5f1e 100644 --- a/src/r_drawt.cpp +++ b/src/r_drawt.cpp @@ -1136,7 +1136,7 @@ void R_DrawMaskedColumnHoriz (const BYTE *column, const FTexture::Span *span) if (sprflipvert) { 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; while (dc_texturefrac >= maxfrac) { @@ -1155,7 +1155,7 @@ void R_DrawMaskedColumnHoriz (const BYTE *column, const FTexture::Span *span) else { 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) { if (++dc_yl > dc_yh) diff --git a/src/r_main.cpp b/src/r_main.cpp index f6a341f4e..ed9593390 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -113,24 +113,22 @@ fixed_t r_SkyVisibility; fixed_t GlobVis; fixed_t viewingrangerecip; -fixed_t FocalLengthX; -fixed_t FocalLengthY; -float FocalLengthXfloat; +double FocalLengthX; +double FocalLengthY; FDynamicColormap*basecolormap; // [RH] colormap currently drawing with int fixedlightlev; lighttable_t *fixedcolormap; FSpecialColormap *realfixedcolormap; -float WallTMapScale2; +double WallTMapScale2; bool bRenderingToCanvas; // [RH] True if rendering to a special canvas -fixed_t globaluclip, globaldclip; -fixed_t centerxfrac; -fixed_t centeryfrac; -fixed_t yaspectmul; -fixed_t baseyaspectmul; // yaspectmul without a forced aspect ratio -float iyaspectmulfloat; -fixed_t InvZtoScale; +double globaluclip, globaldclip; +double CenterX, CenterY; +double YaspectMul; +double BaseYaspectMul; // yaspectmul without a forced aspect ratio +double IYaspectMul; +double InvZtoScale; // just for profiling purposes int linecount; @@ -188,9 +186,8 @@ static inline int viewangletox(int i) } else { - int t = FixedMul(finetangent[i], FocalLengthX); - t = (centerxfrac - t + FRACUNIT-1) >> FRACBITS; - return clamp(t, -1, viewwidth+1); + double t = FIXED2DBL(finetangent[i]) * FocalLengthX; + return clamp(xs_CeilToInt(CenterX - t), -1, viewwidth+1); } } @@ -205,9 +202,8 @@ void R_InitTextureMapping () int i, x; // Calc focallength so FieldOfView fineangles covers viewwidth. - FocalLengthX = FixedDiv (centerxfrac, FocalTangent); - FocalLengthY = Scale (centerxfrac, yaspectmul, FocalTangent); - FocalLengthXfloat = (float)FocalLengthX / 65536.f; + FocalLengthX = CenterX / FocalTangent; + FocalLengthY = FocalLengthX * YaspectMul; // This is 1/FocalTangent before the widescreen extension of FOV. viewingrangerecip = DivScale32(1, finetangent[FINEANGLES/4+(FieldOfView/2)]); @@ -224,13 +220,13 @@ void R_InitTextureMapping () // the drawn sky texture. // The remaining arcs are done with tantoangle instead. - const int t1 = MAX(centerx - (FocalLengthX >> FRACBITS), 0); - const int t2 = MIN(centerx + (FocalLengthX >> FRACBITS), viewwidth); - const fixed_t dfocus = FocalLengthX >> DBITS; + const int t1 = MAX(int(CenterX - FocalLengthX), 0); + const int t2 = MIN(int(CenterX + FocalLengthX), viewwidth); + const fixed_t dfocus = FLOAT2FIXED(FocalLengthX) >> DBITS; for (i = 0, x = t2; x >= t1; --x) { - while(viewangletox(i) > x) + while (viewangletox(i) > x) { ++i; } @@ -278,8 +274,8 @@ void R_SetVisibility (float vis) else r_WallVisibility = r_BaseVisibility; - r_WallVisibility = FixedMul (Scale (InvZtoScale, SCREENWIDTH*BaseRatioSizes[WidescreenRatio][1], - viewwidth*SCREENHEIGHT*3), FixedMul (r_WallVisibility, FocalTangent)); + r_WallVisibility = FixedMul (FLOAT2FIXED(InvZtoScale * SCREENWIDTH*BaseRatioSizes[WidescreenRatio][1] / + (viewwidth*SCREENHEIGHT*3)), xs_ToInt(r_WallVisibility * FocalTangent)); // Prevent overflow on floors/ceilings. Note that the calculation of // MaxVisForFloor means that planes less than two units from the player's @@ -292,7 +288,7 @@ void R_SetVisibility (float vis) else r_FloorVisibility = r_BaseVisibility; - r_FloorVisibility = Scale (160*FRACUNIT, r_FloorVisibility, FocalLengthY); + r_FloorVisibility = xs_ToInt(160.0 * r_FloorVisibility / FocalLengthY); r_TiltVisibility = vis * (float)FocalTangent * (16.f * 320.f) / (float)viewwidth; r_SpriteVisibility = r_WallVisibility; @@ -359,8 +355,8 @@ void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, halfviewwidth = (viewwidth >> 1) - 1; lastcenteryfrac = 1<<30; - centerxfrac = centerx<>ANGLETOFINESHIFT]); + dy = FocalLengthY * (-ViewPitch).Tan(); } else { dy = 0; } - centeryfrac = (viewheight << (FRACBITS-1)) + dy; - centery = centeryfrac >> FRACBITS; - globaluclip = FixedDiv (-centeryfrac, InvZtoScale); - globaldclip = FixedDiv ((viewheight<renderflags & RF_INVISIBLE : ActorRenderFlags::FromInt(0); @@ -707,44 +700,40 @@ void R_EnterPortal (PortalDrawseg* pds, int depth) // Reflect the current view behind the mirror. if (pds->src->Delta().X == 0) { // vertical mirror - viewx = v1->fixX() - startx + v1->fixX(); + ViewPos.X = v1->fX() - startpos.X + v1->fX(); } else if (pds->src->Delta().Y == 0) { // horizontal mirror - viewy = v1->fixY() - starty + v1->fixY(); + ViewPos.Y = v1->fY() - startpos.Y + v1->fY(); } else - { // any mirror--use floats to avoid integer overflow + { // any mirror vertex_t *v2 = pds->src->v2; double dx = v2->fX() - v1->fX(); double dy = v2->fY() - v1->fY(); double x1 = v1->fX(); double y1 = v1->fY(); - double x = FIXED2DBL(startx); - double y = FIXED2DBL(starty); + double x = startpos.X; + double y = startpos.Y; // the above two cases catch len == 0 double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy); - viewx = FLOAT2FIXED((x1 + r * dx)*2 - x); - viewy = FLOAT2FIXED((y1 + r * dy)*2 - y); + ViewPos.X = (x1 + r * dx)*2 - x; + ViewPos.Y = (y1 + r * dy)*2 - y; } - viewangle = pds->src->Delta().Angle().BAMs() - startang; + ViewAngle = pds->src->Delta().Angle() - startang; } else { - DVector3 view(FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz)); - DAngle va = ANGLE2DBL(viewangle); + DVector3 view(ViewPos); + DAngle va = ViewAngle; P_TranslatePortalXY(pds->src, view.X, view.Y); P_TranslatePortalZ(pds->src, view.Z); P_TranslatePortalAngle(pds->src, va); P_TranslatePortalXY(pds->src, ViewPath[0].X, ViewPath[0].Y); P_TranslatePortalXY(pds->src, ViewPath[1].X, ViewPath[1].Y); - viewx = FLOAT2FIXED(view.X); - viewy = FLOAT2FIXED(view.Y); - viewz = FLOAT2FIXED(view.Z); - viewangle = va.BAMs(); if (!r_showviewer && camera) { @@ -760,15 +749,15 @@ void R_EnterPortal (PortalDrawseg* pds, int depth) } } } + ViewPos = view; + ViewAngle = va; } - ViewAngle = AngleToFloat(viewangle); - ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) }; - viewsin = finesine[viewangle>>ANGLETOFINESHIFT]; - viewcos = finecosine[viewangle>>ANGLETOFINESHIFT]; + ViewSin = ViewAngle.Sin(); + ViewCos = ViewAngle.Cos(); - viewtansin = FixedMul (FocalTangent, viewsin); - viewtancos = FixedMul (FocalTangent, viewcos); + ViewTanSin = FocalTangent * ViewSin; + ViewTanCos = FocalTangent * ViewCos; R_CopyStackedViewParameters(); @@ -809,7 +798,7 @@ void R_EnterPortal (PortalDrawseg* pds, int depth) R_DrawPortals (); PlaneCycles.Unclock(); - fixed_t vzp = viewz; + double vzp = ViewPos.Z; int prevuniq = CurrentPortalUniq; // depth check is in another place right now @@ -838,14 +827,10 @@ void R_EnterPortal (PortalDrawseg* pds, int depth) CurrentPortal = prevpds; MirrorFlags = prevmf; - viewangle = startang; - viewx = startx; - viewy = starty; - viewz = startz; + ViewAngle = startang; + ViewPos = startpos; ViewPath[0] = savedpath[0]; ViewPath[1] = savedpath[1]; - ViewAngle = AngleToFloat(viewangle); - ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) }; } //========================================================================== diff --git a/src/r_main.h b/src/r_main.h index 5602439c7..ede0c5b3b 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -35,22 +35,21 @@ typedef BYTE lighttable_t; // This could be wider for >8 bit display. // POV related. // extern bool bRenderingToCanvas; -extern fixed_t viewcos; -extern fixed_t viewsin; +extern double ViewCos; +extern double ViewSin; extern fixed_t viewingrangerecip; -extern fixed_t FocalLengthX, FocalLengthY; -extern float FocalLengthXfloat; -extern fixed_t InvZtoScale; +extern double FocalLengthX, FocalLengthY; +extern double InvZtoScale; -extern float WallTMapScale2; +extern double WallTMapScale2; extern int viewwindowx; extern int viewwindowy; -extern fixed_t centerxfrac; -extern fixed_t centeryfrac; -extern fixed_t yaspectmul; -extern float iyaspectmulfloat; +extern double CenterX; +extern double CenterY; +extern double YaspectMul; +extern double IYaspectMul; extern FDynamicColormap*basecolormap; // [RH] Colormap for sector currently being drawn @@ -139,8 +138,8 @@ void R_MultiresInit (void); extern int stacked_extralight; extern float stacked_visibility; -extern fixed_t stacked_viewx, stacked_viewy, stacked_viewz; -extern angle_t stacked_angle; +extern DVector3 stacked_viewpos; +extern DAngle stacked_angle; extern void R_CopyStackedViewParameters(); diff --git a/src/r_plane.cpp b/src/r_plane.cpp index a1c429fea..61c204f94 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -99,8 +99,8 @@ visplane_t *ceilingplane; // won't draw in skyboxes properly. int stacked_extralight; float stacked_visibility; -fixed_t stacked_viewx, stacked_viewy, stacked_viewz; -angle_t stacked_angle; +DVector3 stacked_viewpos; +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. ds_colormap = basecolormap->Maps + (GETPALOOKUP ( - FixedMul (GlobVis, abs (centeryfrac - (y << FRACBITS))), planeshade) << COLORMAPSHIFT); + xs_ToInt(GlobVis * fabs(CenterY - y)), planeshade) << COLORMAPSHIFT); } #ifdef X86_ASM @@ -640,9 +640,7 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl // check even more. if (check->extralight == stacked_extralight && check->visibility == stacked_visibility && - check->viewx == stacked_viewx && - check->viewy == stacked_viewy && - check->viewz == stacked_viewz && + check->viewpos == stacked_viewpos && ( // headache inducing logic... :( (portal->mType != PORTS_STACKEDSECTORTHING) || @@ -689,9 +687,7 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl CurrentPortalUniq == check->CurrentPortalUniq && MirrorFlags == check->MirrorFlags && CurrentSkybox == check->CurrentSkybox && - viewx == check->viewx && - viewy == check->viewy && - viewz == check->viewz + ViewPos == check->viewpos ) { return check; @@ -715,9 +711,7 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl check->right = 0; check->extralight = stacked_extralight; check->visibility = stacked_visibility; - check->viewx = stacked_viewx; - check->viewy = stacked_viewy; - check->viewz = stacked_viewz; + check->viewpos = stacked_viewpos; check->viewangle = stacked_angle; check->Alpha = alpha; 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->extralight = pl->extralight; new_pl->visibility = pl->visibility; - new_pl->viewx = pl->viewx; - new_pl->viewy = pl->viewy; - new_pl->viewz = pl->viewz; + new_pl->viewpos = pl->viewpos; new_pl->viewangle = pl->viewangle; new_pl->sky = pl->sky; new_pl->Alpha = pl->Alpha; @@ -985,7 +977,7 @@ static void R_DrawSky (visplane_t *pl) static void R_DrawSkyStriped (visplane_t *pl) { - fixed_t centerysave = centeryfrac; + double centerysave = CenterY; short drawheight = (short)MulScale16 (frontskytex->GetHeight(), frontyScale); fixed_t topfrac; 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 // fractional part of centeryfrac. - centeryfrac = centery << FRACBITS; + CenterY = centery; topfrac = (skymid + iscale * (1-centery)) % (frontskytex->GetHeight() << FRACBITS); if (topfrac < 0) topfrac += frontskytex->GetHeight() << FRACBITS; yl = 0; @@ -1020,7 +1012,7 @@ static void R_DrawSkyStriped (visplane_t *pl) yh += drawheight; dc_texturemid = iscale * (centery-yl-1); } - centeryfrac = centerysave; + CenterY = centerysave; } //========================================================================== @@ -1060,15 +1052,15 @@ int R_DrawPlanes () } // kg3D - draw all visplanes with "height" -void R_DrawHeightPlanes(fixed_t height) +void R_DrawHeightPlanes(double height) { visplane_t *pl; int i; ds_color = 3; - fixed_t oViewX = viewx, oViewY = viewy, oViewZ = viewz; - angle_t oViewAngle = viewangle; + DVector3 oViewPos = ViewPos; + DAngle oViewAngle = ViewAngle; for (i = 0; i < MAXVISPLANES; i++) { @@ -1078,24 +1070,15 @@ void R_DrawHeightPlanes(fixed_t height) if(pl->CurrentSkybox != CurrentSkybox || pl->CurrentPortalUniq != CurrentPortalUniq) continue; if(pl->sky < 0 && pl->height.Zat0() == height) { - viewx = pl->viewx; - viewy = pl->viewy; - viewz = pl->viewz; - viewangle = pl->viewangle; - ViewAngle = AngleToFloat(viewangle); - ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) }; + ViewPos = pl->viewpos; + ViewAngle = pl->viewangle; MirrorFlags = pl->MirrorFlags; R_DrawSinglePlane (pl, pl->sky & 0x7FFFFFFF, pl->Additive, true); } } } - - viewx = oViewX; - viewy = oViewY; - viewz = oViewZ; - viewangle = oViewAngle; - ViewAngle = AngleToFloat(viewangle); - ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) }; + ViewPos = oViewPos; + ViewAngle = oViewAngle; } @@ -1186,7 +1169,7 @@ void R_DrawPortals () static TArray interestingStack; static TArray drawsegStack; static TArray visspriteStack; - static TArray viewxStack, viewyStack, viewzStack; + static TArray viewposStack; static TArray visplaneStack; numskyboxes = 0; @@ -1198,10 +1181,8 @@ void R_DrawPortals () CurrentPortalInSkybox = true; int savedextralight = extralight; - fixed_t savedx = viewx; - fixed_t savedy = viewy; - fixed_t savedz = viewz; - angle_t savedangle = viewangle; + DVector3 savedpos = ViewPos; + DAngle savedangle = ViewAngle; ptrdiff_t savedvissprite_p = vissprite_p - vissprites; ptrdiff_t savedds_p = ds_p - drawsegs; ptrdiff_t savedlastopening = lastopening; @@ -1241,11 +1222,8 @@ void R_DrawPortals () extralight = 0; R_SetVisibility(sky->args[0] * 0.25f); - DVector3 viewpos = sky->InterpolatedPosition(r_TicFracF); - viewx = FLOAT2FIXED(viewpos.X); - viewy = FLOAT2FIXED(viewpos.Y); - viewz = FLOAT2FIXED(viewpos.Z); - viewangle = savedangle + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_TicFracF).BAMs(); + ViewPos = sky->InterpolatedPosition(r_TicFracF); + ViewAngle = savedangle + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * r_TicFracF); R_CopyStackedViewParameters(); break; @@ -1256,10 +1234,10 @@ void R_DrawPortals () case PORTS_LINKEDPORTAL: extralight = pl->extralight; R_SetVisibility (pl->visibility); - viewx = pl->viewx + FLOAT2FIXED(port->mDisplacement.X); - viewy = pl->viewy + FLOAT2FIXED(port->mDisplacement.Y); - viewz = pl->viewz; - viewangle = pl->viewangle; + ViewPos.X = pl->viewpos.X + port->mDisplacement.X; + ViewPos.Y = pl->viewpos.Y + port->mDisplacement.Y; + ViewPos.Z = pl->viewpos.Z; + ViewAngle = pl->viewangle; break; case PORTS_HORIZON: @@ -1274,9 +1252,6 @@ void R_DrawPortals () continue; } - ViewAngle = AngleToFloat(viewangle); - ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) }; - port->mFlags |= PORTSF_INSKYBOX; if (port->mPartner > 0) sectorPortals[port->mPartner].mFlags |= PORTSF_INSKYBOX; camera = NULL; @@ -1332,9 +1307,7 @@ void R_DrawPortals () drawsegStack.Push (diffnum); diffnum = firstvissprite - vissprites; visspriteStack.Push (diffnum); - viewxStack.Push (viewx); - viewyStack.Push (viewy); - viewzStack.Push (viewz); + viewposStack.Push(ViewPos); visplaneStack.Push (pl); InSubsector = NULL; @@ -1357,9 +1330,9 @@ void R_DrawPortals () firstdrawseg = drawsegs + pd; visspriteStack.Pop (pd); firstvissprite = vissprites + pd; - viewxStack.Pop (viewx); // Masked textures and planes need the view - viewyStack.Pop (viewy); // coordinates restored for proper positioning. - viewzStack.Pop (viewz); + + // Masked textures and planes need the view coordinates restored for proper positioning. + viewposStack.Pop(ViewPos); R_DrawMasked (); @@ -1385,14 +1358,10 @@ void R_DrawPortals () camera = savedcamera; viewsector = savedsector; - viewx = savedx; - viewy = savedy; - viewz = savedz; + ViewPos = savedpos; R_SetVisibility (savedvisibility); extralight = savedextralight; - viewangle = savedangle; - ViewAngle = AngleToFloat(viewangle); - ViewPos = { FIXED2DBL(viewx), FIXED2DBL(viewy), FIXED2DBL(viewz) }; + ViewAngle = savedangle; R_SetViewAngle (); CurrentPortalInSkybox = false; @@ -1432,7 +1401,7 @@ void R_DrawSkyPlane (visplane_t *pl) } sky2tex = sky2texture; skymid = skytexturemid; - skyangle = viewangle; + skyangle = ViewAngle.BAMs(); 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 cosine = cos(rad), sine = sin(rad); - pviewx = xs_RoundToInt(pl->xoffs + viewx * cosine - viewy * sine); - pviewy = xs_RoundToInt(pl->yoffs - viewx * sine - viewy * cosine); + pviewx = xs_RoundToInt(pl->xoffs + FLOAT2FIXED(ViewPos.X * cosine - ViewPos.Y * sine)); + pviewy = xs_RoundToInt(pl->yoffs - FLOAT2FIXED(ViewPos.X * sine - ViewPos.Y * cosine)); } else { - pviewx = pl->xoffs + viewx; - pviewy = pl->yoffs - viewy; + pviewx = pl->xoffs + FLOAT2FIXED(ViewPos.X); + pviewy = pl->yoffs - FLOAT2FIXED(ViewPos.Y); } pviewx = FixedMul (xscale, pviewx); pviewy = FixedMul (yscale, pviewy); // 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 - xstepscale = Scale (xscale, finecosine[planeang], FocalLengthX); - ystepscale = Scale (yscale, -finesine[planeang], FocalLengthX); + xstepscale = fixed_t(FixedMul(xscale, finecosine[planeang]) / FocalLengthX); + ystepscale = fixed_t(FixedMul(yscale, -finesine[planeang]) / FocalLengthX); // [RH] flip for mirrors 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; 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); if (fixedlightlev >= 0) @@ -1678,15 +1647,11 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske return; } - double vx = FIXED2DBL(viewx); - double vy = FIXED2DBL(viewy); - double vz = FIXED2DBL(viewz); - lxscale = FIXED2DBL(pl->xscale) * ifloatpow2[ds_xbits]; lyscale = FIXED2DBL(pl->yscale) * ifloatpow2[ds_ybits]; xscale = 64.f / lxscale; yscale = 64.f / lyscale; - zeroheight = pl->height.ZatPoint(vx, vy); + zeroheight = pl->height.ZatPoint(ViewPos); pviewx = MulScale (pl->xoffs, pl->xscale, ds_xbits); 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 // Don't add in the offsets at this stage, because doing so can result in // errors if the flat is rotated. - ang = (ANG270 - viewangle) * (M_PI / ANGLE_180); - p[0] = vx * cos(ang) - vy * sin(ang); - p[2] = vx * sin(ang) + vy * cos(ang); - p[1] = pl->height.ZatPoint(0.0, 0.0) - vz; + ang = (DAngle(270.) - ViewAngle).Radians(); + p[0] = ViewPos.X * cos(ang) - ViewPos.Y * sin(ang); + p[2] = ViewPos.X * sin(ang) + ViewPos.Y * cos(ang); + p[1] = pl->height.ZatPoint(0.0, 0.0) - ViewPos.Z; // 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[2] = yscale * sin(ang); // 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 // the textures a constant size across the surface's plane instead. 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; - 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_sv = p ^ n; plane_sz = m ^ n; - plane_su.Z *= FocalLengthXfloat; - plane_sv.Z *= FocalLengthXfloat; - plane_sz.Z *= FocalLengthXfloat; + plane_su.Z *= FocalLengthX; + plane_sv.Z *= FocalLengthX; + plane_sz.Z *= FocalLengthX; - plane_su.Y *= iyaspectmulfloat; - plane_sv.Y *= iyaspectmulfloat; - plane_sz.Y *= iyaspectmulfloat; + plane_su.Y *= IYaspectMul; + plane_sv.Y *= IYaspectMul; + plane_sz.Y *= IYaspectMul; // Premultiply the texture vectors with the scale factors 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]; } - 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) planelightfloat = -planelightfloat; diff --git a/src/r_plane.h b/src/r_plane.h index e1030f66d..d0cb0304b 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -51,8 +51,8 @@ struct visplane_s // stack, then they are unused. int extralight; float visibility; - fixed_t viewx, viewy, viewz; - angle_t viewangle; + DVector3 viewpos; + DAngle viewangle; fixed_t Alpha; bool Additive; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 3acc90993..3ad6d6316 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -64,7 +64,7 @@ CVAR(Bool, r_np2, true, 0) #define HEIGHTBITS 12 #define HEIGHTSHIFT (FRACBITS-HEIGHTBITS) -extern fixed_t globaluclip, globaldclip; +extern double globaluclip, globaldclip; PortalDrawseg* CurrentPortal = NULL; int CurrentPortalUniq = 0; @@ -93,7 +93,7 @@ short wallupper[MAXWIDTH]; short walllower[MAXWIDTH]; fixed_t swall[MAXWIDTH]; fixed_t lwall[MAXWIDTH]; -fixed_t lwallscale; +double lwallscale; // // regular wall @@ -114,7 +114,7 @@ fixed_t rw_light; // [RH] Scale lights with viewsize adjustments fixed_t rw_lightstep; fixed_t rw_lightleft; -static fixed_t rw_frontlowertop; +static double rw_frontlowertop; static int rw_x; static int rw_stopx; @@ -123,12 +123,12 @@ static fixed_t rw_scalestep; static fixed_t rw_midtexturemid; static fixed_t rw_toptexturemid; static fixed_t rw_bottomtexturemid; -static fixed_t rw_midtexturescalex; -static fixed_t rw_midtexturescaley; -static fixed_t rw_toptexturescalex; -static fixed_t rw_toptexturescaley; -static fixed_t rw_bottomtexturescalex; -static fixed_t rw_bottomtexturescaley; +static double rw_midtexturescalex; +static double rw_midtexturescaley; +static double rw_toptexturescalex; +static double rw_toptexturescaley; +static double rw_bottomtexturescalex; +static double rw_bottomtexturescaley; FTexture *rw_pic; @@ -182,9 +182,9 @@ static void BlastMaskedColumn (void (*blastfunc)(const BYTE *pixels, const FText dc_iscale = MulScale18 (MaskedSWall[dc_x], MaskedScaleY); if (sprflipvert) - sprtopscreen = centeryfrac + FixedMul(dc_texturemid, spryscale); + sprtopscreen = FLOAT2FIXED(CenterY) + FixedMul(dc_texturemid, spryscale); 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 // 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; int i; sector_t tempsec; // killough 4/13/98 - fixed_t texheight, texheightscale; + double texheight, texheightscale; bool notrelevant = false; fixed_t rowoffset; @@ -274,7 +274,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) { 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--) { @@ -317,19 +317,19 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) dc_colormap = fixedcolormap; // find positioning - texheight = tex->GetScaledHeight() << FRACBITS; - texheightscale = abs(curline->sidedef->GetTextureYScale(side_t::mid)); - if (texheightscale != FRACUNIT) + texheight = tex->GetScaledHeightDouble(); + texheightscale = fabs(curline->sidedef->GetTextureYScaleF(side_t::mid)); + if (texheightscale != 1) { - texheight = FixedDiv(texheight, texheightscale); + texheight = texheight / texheightscale; } 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 { - 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); @@ -337,7 +337,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) if (!(curline->linedef->flags & ML_WRAP_MIDTEX) && !(curline->sidedef->Flags & WALLF_WRAP_MIDTEX)) { // Texture does not wrap vertically. - fixed_t textop; + double textop; 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 // still be positioned in world units rather than texels. - dc_texturemid += rowoffset - viewz; - textop = dc_texturemid; + dc_texturemid += rowoffset - FLOAT2FIXED(ViewPos.Z); + textop = FIXED2FLOAT(dc_texturemid); dc_texturemid = MulScale16 (dc_texturemid, MaskedScaleY); } else { // rowoffset is added outside the multiply so that it positions the texture // by texels instead of world units. - textop = dc_texturemid - viewz + SafeDivScale16 (rowoffset, MaskedScaleY); - dc_texturemid = MulScale16 (dc_texturemid - viewz, MaskedScaleY) + rowoffset; + textop = FIXED2FLOAT(dc_texturemid + SafeDivScale16 (rowoffset, MaskedScaleY)) - ViewPos.Z; + dc_texturemid = MulScale16 (dc_texturemid - FLOAT2FIXED(ViewPos.Z), MaskedScaleY) + rowoffset; } 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 - if (MulScale12 (globaldclip, ds->sz1) < -textop && - MulScale12 (globaldclip, ds->sz2) < -textop) + if (globaldclip * ds->sz1 < -textop && globaldclip * ds->sz2 < -textop) { // Texture top is below the bottom of the screen goto clearfog; } - if (MulScale12 (globaluclip, ds->sz1) > texheight - textop && - MulScale12 (globaluclip, ds->sz2) > texheight - textop) + if (globaluclip * ds->sz1 > texheight - textop && globaluclip * ds->sz2 > texheight - textop) { // Texture bottom is above the top of the screen goto clearfog; } - if ((fake3D & FAKE3D_CLIPBOTTOM) && textop < sclipBottom - viewz) + if ((fake3D & FAKE3D_CLIPBOTTOM) && textop < sclipBottom - ViewPos.Z) { notrelevant = true; goto clearfog; } - if ((fake3D & FAKE3D_CLIPTOP) && textop - texheight > sclipTop - viewz) + if ((fake3D & FAKE3D_CLIPTOP) && textop - texheight > sclipTop - ViewPos.Z) { notrelevant = true; goto clearfog; @@ -396,7 +394,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) 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 { @@ -404,7 +402,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) } 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 { @@ -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 // 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); } else { // rowoffset is added outside the multiply so that it positions the texture // 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; @@ -512,7 +510,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) if (fake3D & FAKE3D_CLIPTOP) { - OWallMost(wallupper, sclipTop - viewz, &WallC); + OWallMost(wallupper, sclipTop - ViewPos.Z, &WallC); for (i = x1; i < x2; i++) { if (wallupper[i] < mceilingclip[i]) @@ -522,7 +520,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) } if (fake3D & FAKE3D_CLIPBOTTOM) { - OWallMost(walllower, sclipBottom - viewz, &WallC); + OWallMost(walllower, sclipBottom - ViewPos.Z, &WallC); for (i = x1; i < x2; i++) { if (walllower[i] > mfloorclip[i]) @@ -561,7 +559,8 @@ clearfog: void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover) { int i; - fixed_t xscale, yscale; + fixed_t xscale; + double yscale; fixed_t Alpha = Scale(rover->alpha, OPAQUE, 255); ESPSResult drawmode; @@ -602,28 +601,29 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover) scaledpart = side_t::mid; } 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); - 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); if (rowoffset < 0) { rowoffset += rw_pic->GetHeight() << FRACBITS; } + dc_texturemid = FLOAT2FIXED((planez - ViewPos.Z) * yscale); if (rw_pic->bWorldPanning) { // rowoffset is added before the MulScale3 so that the masked texture will // still be positioned in world units rather than texels. - dc_texturemid = MulScale16(dc_texturemid - viewz + rowoffset, yscale); - rw_offset = MulScale16 (rw_offset, xscale); + dc_texturemid += xs_FloorToInt(rowoffset * yscale); + rw_offset = MulScale16 (rw_offset, xscale); ///Is this really supposed to be xscale and not yscale? } else { // rowoffset is added outside the multiply so that it positions the texture // by texels instead of world units. - dc_texturemid = MulScale16(dc_texturemid - viewz, yscale) + rowoffset; + dc_texturemid += rowoffset; } if (fixedlightlev >= 0) @@ -635,14 +635,14 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover) WallC.sz2 = ds->sz2; WallC.sx1 = ds->sx1; WallC.sx2 = ds->sx2; - WallC.tx1 = ds->cx; - WallC.ty1 = ds->cy; - WallC.tx2 = ds->cx + ds->cdx; - WallC.ty2 = ds->cy + ds->cdy; + WallC.tleft.X = ds->cx; + WallC.tleft.Y = ds->cy; + WallC.tright.X = ds->cx + ds->cdx; + WallC.tright.Y = ds->cy + ds->cdy; WallT = ds->tmapvals; - OWallMost(wallupper, sclipTop - viewz, &WallC); - OWallMost(walllower, sclipBottom - viewz, &WallC); + OWallMost(wallupper, sclipTop - ViewPos.Z, &WallC); + OWallMost(walllower, sclipBottom - ViewPos.Z, &WallC); 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); - 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(); } @@ -1104,6 +1104,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t texturemid = dc_texturemid << (16 - shiftval); xoffset = rw_offset; basecolormapdata = basecolormap->Maps; + fixed_t centeryfrac = FLOAT2FIXED(CenterY); x = x1; //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) { @@ -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 *up, *down; fixed_t texheight = rw_pic->GetHeight() << FRACBITS; - fixed_t scaledtexheight = FixedDiv(texheight, yrepeat); - fixed_t partition; + double scaledtexheight = FIXED2FLOAT(FixedDiv(texheight, yrepeat)); + double partition; + double top = FIXED2FLOAT(itop); + double bot = FIXED2FLOAT(ibot); if (yrepeat >= 0) { // 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; down = most1; - dc_texturemid = FixedMul(partition - viewz, yrepeat) + texheight; + dc_texturemid = xs_RoundToInt((partition - ViewPos.Z) * yrepeat + texheight); while (partition > bot) { - int j = OWallMost(most3, partition - viewz, &WallC); + int j = OWallMost(most3, partition - ViewPos.Z, &WallC); if (j != 3) { 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 { // 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; down = dwal; - dc_texturemid = FixedMul(partition - viewz, yrepeat) + texheight; + dc_texturemid = xs_RoundToInt((partition - ViewPos.Z) * yrepeat + texheight); while (partition < top) { - int j = OWallMost(most3, partition - viewz, &WallC); + int j = OWallMost(most3, partition - ViewPos.Z, &WallC); if (j != 12) { 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) { - fixed_t frontcz1 = ds->curline->frontsector->ceilingplane.ZatPointFixed(ds->curline->v1); - fixed_t frontfz1 = ds->curline->frontsector->floorplane.ZatPointFixed(ds->curline->v1); - fixed_t frontcz2 = ds->curline->frontsector->ceilingplane.ZatPointFixed(ds->curline->v2); - fixed_t frontfz2 = ds->curline->frontsector->floorplane.ZatPointFixed(ds->curline->v2); - fixed_t top = MAX(frontcz1, frontcz2); - fixed_t bot = MIN(frontfz1, frontfz2); + double frontcz1 = ds->curline->frontsector->ceilingplane.ZatPoint(ds->curline->v1); + double frontfz1 = ds->curline->frontsector->floorplane.ZatPoint(ds->curline->v1); + double frontcz2 = ds->curline->frontsector->ceilingplane.ZatPoint(ds->curline->v2); + double frontfz2 = ds->curline->frontsector->floorplane.ZatPoint(ds->curline->v2); + double top = MAX(frontcz1, frontcz2); + double bot = MIN(frontfz1, frontfz2); if (fake3D & FAKE3D_CLIPTOP) { 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); } - 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 { @@ -1450,6 +1457,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe texturemid = dc_texturemid << (16 - shiftval); xoffset = rw_offset; basecolormapdata = basecolormap->Maps; + fixed_t centeryfrac = FLOAT2FIXED(CenterY); x = startx = x1; 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); xoffset = rw_offset; basecolormapdata = basecolormap->Maps; + fixed_t centeryfrac = FLOAT2FIXED(CenterY); x = startx = x1; p = x + dc_destorg; @@ -1769,7 +1778,8 @@ void R_RenderSegLoop () int x1 = rw_x; int x2 = rw_stopx; int x; - fixed_t xscale, yscale; + double xscale; + fixed_t yscale; fixed_t xoffset = rw_offset; if (fixedlightlev >= 0) @@ -1858,8 +1868,8 @@ void R_RenderSegLoop () { dc_texturemid = rw_midtexturemid; rw_pic = midtexture; - xscale = fixed_t(rw_pic->Scale.X * rw_midtexturescalex); - yscale = fixed_t(rw_pic->Scale.Y * rw_midtexturescaley); + xscale = rw_pic->Scale.X * rw_midtexturescalex; + yscale = FLOAT2FIXED(rw_pic->Scale.Y * rw_midtexturescaley); if (xscale != lwallscale) { PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2); @@ -1867,7 +1877,7 @@ void R_RenderSegLoop () } if (midtexture->bWorldPanning) { - rw_offset = MulScale16 (rw_offset_mid, xscale); + rw_offset = xs_RoundToInt(rw_offset_mid * xscale); } else { @@ -1901,8 +1911,8 @@ void R_RenderSegLoop () { dc_texturemid = rw_toptexturemid; rw_pic = toptexture; - xscale = fixed_t(rw_pic->Scale.X * rw_toptexturescalex); - yscale = fixed_t(rw_pic->Scale.Y * rw_toptexturescaley); + xscale = rw_pic->Scale.X * rw_toptexturescalex; + yscale = FLOAT2FIXED(rw_pic->Scale.Y * rw_toptexturescaley); if (xscale != lwallscale) { PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2); @@ -1910,7 +1920,7 @@ void R_RenderSegLoop () } if (toptexture->bWorldPanning) { - rw_offset = MulScale16 (rw_offset_top, xscale); + rw_offset = xs_RoundToInt(rw_offset_top * xscale); } else { @@ -1947,8 +1957,8 @@ void R_RenderSegLoop () { dc_texturemid = rw_bottomtexturemid; rw_pic = bottomtexture; - xscale = fixed_t(rw_pic->Scale.X * rw_bottomtexturescalex); - yscale = fixed_t(rw_pic->Scale.Y * rw_bottomtexturescaley); + xscale = rw_pic->Scale.X * rw_bottomtexturescalex; + yscale = FLOAT2FIXED(rw_pic->Scale.Y * rw_bottomtexturescaley); if (xscale != lwallscale) { PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2); @@ -1956,7 +1966,7 @@ void R_RenderSegLoop () } if (bottomtexture->bWorldPanning) { - rw_offset = MulScale16 (rw_offset_bottom, xscale); + rw_offset = xs_RoundToInt(rw_offset_bottom * xscale); } else { @@ -1987,7 +1997,8 @@ void R_RenderSegLoop () void R_NewWall (bool needlights) { - fixed_t rowoffset, yrepeat; + fixed_t rowoffset; + double yrepeat; rw_markportal = false; @@ -2016,18 +2027,18 @@ void R_NewWall (bool needlights) midtexture = TexMan(sidedef->GetTexture(side_t::mid), true); rw_offset_mid = sidedef->GetTextureXOffset(side_t::mid); rowoffset = sidedef->GetTextureYOffset(side_t::mid); - rw_midtexturescalex = sidedef->GetTextureXScale(side_t::mid); - rw_midtexturescaley = sidedef->GetTextureYScale(side_t::mid); - yrepeat = fixed_t(midtexture->Scale.Y * rw_midtexturescaley); + rw_midtexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::mid)); + rw_midtexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::mid)); + yrepeat = midtexture->Scale.Y * rw_midtexturescaley; if (yrepeat >= 0) { // normal orientation if (linedef->flags & ML_DONTPEGBOTTOM) { // 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 { // 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) { rowoffset += midtexture->GetHeight() << FRACBITS; @@ -2039,16 +2050,16 @@ void R_NewWall (bool needlights) rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGBOTTOM) { // 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 { // 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) { - rw_midtexturemid += MulScale16(rowoffset, yrepeat); + rw_midtexturemid += xs_FloorToInt(rowoffset * yrepeat); } else { @@ -2062,7 +2073,7 @@ void R_NewWall (bool needlights) { // two-sided line // 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 && 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 // 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) || @@ -2171,14 +2182,14 @@ void R_NewWall (bool needlights) rw_offset_top = sidedef->GetTextureXOffset(side_t::top); rowoffset = sidedef->GetTextureYOffset(side_t::top); - rw_toptexturescalex = sidedef->GetTextureXScale(side_t::top); - rw_toptexturescaley = sidedef->GetTextureYScale(side_t::top); - yrepeat = fixed_t(toptexture->Scale.Y * rw_toptexturescaley); + rw_toptexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::top)); + rw_toptexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::top)); + yrepeat = toptexture->Scale.Y * rw_toptexturescaley; if (yrepeat >= 0) { // normal orientation if (linedef->flags & ML_DONTPEGTOP) { // 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) { rowoffset += toptexture->GetHeight() << FRACBITS; @@ -2186,7 +2197,7 @@ void R_NewWall (bool needlights) } else { // 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 @@ -2194,16 +2205,16 @@ void R_NewWall (bool needlights) rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGTOP) { // 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 { // 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) { - rw_toptexturemid += MulScale16(rowoffset, yrepeat); + rw_toptexturemid += xs_FloorToInt(rowoffset * yrepeat); } else { @@ -2216,18 +2227,18 @@ void R_NewWall (bool needlights) rw_offset_bottom = sidedef->GetTextureXOffset(side_t::bottom); rowoffset = sidedef->GetTextureYOffset(side_t::bottom); - rw_bottomtexturescalex = sidedef->GetTextureXScale(side_t::bottom); - rw_bottomtexturescaley = sidedef->GetTextureYScale(side_t::bottom); + rw_bottomtexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::bottom)); + rw_bottomtexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::bottom)); yrepeat = fixed_t(bottomtexture->Scale.Y * rw_bottomtexturescaley); if (yrepeat >= 0) { // normal orientation if (linedef->flags & ML_DONTPEGBOTTOM) { // bottom of texture at bottom - rw_bottomtexturemid = MulScale16(rw_frontlowertop - viewz, yrepeat); + rw_bottomtexturemid = FLOAT2FIXED((rw_frontlowertop - ViewPos.Z) * yrepeat); } else { // 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) { rowoffset += bottomtexture->GetHeight() << FRACBITS; @@ -2239,16 +2250,16 @@ void R_NewWall (bool needlights) rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGBOTTOM) { // top of texture at bottom - rw_bottomtexturemid = MulScale16(rw_frontlowertop - viewz, yrepeat); + rw_bottomtexturemid = FLOAT2FIXED((rw_frontlowertop - ViewPos.Z) * yrepeat); } else { // 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) { - rw_bottomtexturemid += MulScale16(rowoffset, yrepeat); + rw_bottomtexturemid += xs_FloorToInt(rowoffset * yrepeat); } else { @@ -2265,7 +2276,7 @@ void R_NewWall (bool needlights) { 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 planeside = -planeside; if (planeside <= 0) // above view plane @@ -2273,7 +2284,7 @@ void R_NewWall (bool needlights) 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 planeside = -planeside; if (planeside <= 0) // below view plane @@ -2289,9 +2300,9 @@ void R_NewWall (bool needlights) if (needlights && (segtextured || (backsector && IsFogBoundary(frontsector, backsector)))) { lwallscale = - midtex ? int(midtex->Scale.X * sidedef->GetTextureXScale(side_t::mid)) : - toptexture ? int(toptexture->Scale.X * sidedef->GetTextureXScale(side_t::top)) : - bottomtexture ? int(bottomtexture->Scale.X * sidedef->GetTextureXScale(side_t::bottom)) : + midtex ? (midtex->Scale.X * sidedef->GetTextureXScale(side_t::mid) / 65536.0) : + toptexture ? (toptexture->Scale.X * sidedef->GetTextureXScale(side_t::top) / 65536.0) : + bottomtexture ? (bottomtexture->Scale.X * sidedef->GetTextureXScale(side_t::bottom) / 65536.0) : FRACUNIT; 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) + r_actualextralight); GlobVis = r_WallVisibility; - rw_lightleft = SafeDivScale12 (GlobVis, WallC.sz1); - rw_lightstep = (SafeDivScale12 (GlobVis, WallC.sz2) - rw_lightleft) / (WallC.sx2 - WallC.sx1); + rw_lightleft = FLOAT2FIXED(FIXED2DBL(GlobVis) / WallC.sz1); + rw_lightstep = (FLOAT2FIXED(FIXED2DBL(GlobVis) / WallC.sz2) - rw_lightleft) / (WallC.sx2 - WallC.sx1); } else { @@ -2383,13 +2394,13 @@ void R_StoreWallRange (int start, int stop) ds_p->sx2 = WallC.sx2; ds_p->sz1 = WallC.sz1; ds_p->sz2 = WallC.sz2; - ds_p->cx = WallC.tx1; - ds_p->cy = WallC.ty1; - ds_p->cdx = WallC.tx2 - WallC.tx1; - ds_p->cdy = WallC.ty2 - WallC.ty1; + ds_p->cx = WallC.tleft.X;; + ds_p->cy = WallC.tleft.Y; + ds_p->cdx = WallC.tright.X - WallC.tleft.X; + ds_p->cdy = WallC.tright.Y - WallC.tleft.Y; ds_p->tmapvals = WallT; - ds_p->siz1 = (DWORD)DivScale32 (1, WallC.sz1) >> 1; - ds_p->siz2 = (DWORD)DivScale32 (1, WallC.sz2) >> 1; + ds_p->siz1 = 1 / WallC.sz1; + ds_p->siz2 = 1 / WallC.sz2; ds_p->x1 = rw_x = start; ds_p->x2 = stop; ds_p->curline = curline; @@ -2420,13 +2431,13 @@ void R_StoreWallRange (int start, int stop) ds_p->silhouette = 0; 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; } 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; } @@ -2509,7 +2520,7 @@ void R_StoreWallRange (int start, int stop) if (pic->bWorldPanning) { - xoffset = MulScale16 (xoffset, lwallscale); + xoffset = xs_RoundToInt(xoffset * lwallscale); } for (i = start; i < stop; i++) @@ -2655,14 +2666,15 @@ void R_StoreWallRange (int start, int stop) 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; - fixed_t s1, s2, s3, s4; + int bad, ix1, ix2; + double y, iy1, iy2; + double s1, s2, s3, s4; - z = -(z >> 4); - s1 = MulScale16 (globaluclip, wallc->sz1); s2 = MulScale16 (globaluclip, wallc->sz2); - s3 = MulScale16 (globaldclip, wallc->sz1); s4 = MulScale16 (globaldclip, wallc->sz2); + z = -z; + s1 = globaluclip * wallc->sz1; s2 = globaluclip * wallc->sz2; + s3 = globaldclip * wallc->sz1; s4 = globaldclip * wallc->sz2; bad = (zs3)<<2)+((z>s4)<<3); #if 1 @@ -2683,9 +2695,9 @@ int OWallMost (short *mostbuf, fixed_t z, const FWallCoords *wallc) #if 1 if (bad & 3) { - int t = DivScale30 (z-s1, s2-s1); - int inty = wallc->sz1 + MulScale30 (wallc->sz2 - wallc->sz1, t); - int xcross = wallc->sx1 + Scale (MulScale30 (wallc->sz2, t), wallc->sx2 - wallc->sx1, inty); + double t = (z-s1) / (s2-s1); + double inty = wallc->sz1 + t * (wallc->sz2 - wallc->sz1); + int xcross = xs_RoundToInt(wallc->sx1 + (t * wallc->sz2 * (wallc->sx2 - wallc->sx1)) / inty); if ((bad & 3) == 2) { @@ -2701,9 +2713,9 @@ int OWallMost (short *mostbuf, fixed_t z, const FWallCoords *wallc) if (bad & 12) { - int t = DivScale30 (z-s3, s4-s3); - int inty = wallc->sz1 + MulScale30 (wallc->sz2 - wallc->sz1, t); - int xcross = wallc->sx1 + Scale (MulScale30 (wallc->sz2, t), wallc->sx2 - wallc->sx1, inty); + double t = (z-s3) / (s4-s3); + double inty = wallc->sz1 + t * (wallc->sz2 - wallc->sz1); + int xcross = xs_RoundToInt(wallc->sx1 + (t * wallc->sz2 * (wallc->sx2 - wallc->sx1)) / inty); 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) { - mostbuf[ix1] = (short)((y + centeryfrac) >> FRACBITS); + mostbuf[ix1] = (short)xs_RoundToInt(y + CenterY); } else { - fixed_t yinc = (Scale (z, InvZtoScale, iy2) - y) / (ix2 - ix1); - qinterpolatedown16short (&mostbuf[ix1], ix2-ix1, y + centeryfrac, yinc); + fixed_t yinc = FLOAT2FIXED(((z * InvZtoScale / iy2) - y) / (ix2 - ix1)); + qinterpolatedown16short (&mostbuf[ix1], ix2-ix1, FLOAT2FIXED(y + CenterY), yinc); } #else double max = viewheight; @@ -2766,36 +2778,37 @@ int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc) { 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; - fixed_t s1, s2, s3, s4; - int bad, ix1, ix2, iy1, iy2; + double x, y, den, z1, z2, oz1, oz2; + double s1, s2, s3, s4; + int bad, ix1, ix2; + double iy1, iy2; if (MirrorFlags & RF_XFLIP) { - x = curline->v2->fixX(); - y = curline->v2->fixY(); - if (wallc->sx1 == 0 && 0 != (den = wallc->tx1 - wallc->tx2 + wallc->ty1 - wallc->ty2)) + x = curline->v2->fX(); + y = curline->v2->fY(); + 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); - x -= MulScale30 (frac, x - curline->v1->fixX()); - y -= MulScale30 (frac, y - curline->v1->fixY()); + double frac = (wallc->tleft.Y + wallc->tleft.X) / den; + x -= frac * (x - curline->v1->fX()); + 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) { - x = curline->v1->fixX(); - y = curline->v1->fixY(); - if (wallc->sx2 == viewwidth && 0 != (den = wallc->tx1 - wallc->tx2 - wallc->ty1 + wallc->ty2)) + x = curline->v1->fX(); + y = curline->v1->fY(); + 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); - x += MulScale30 (frac, curline->v2->fixX() - x); - y += MulScale30 (frac, curline->v2->fixY() - y); + double frac = (wallc->tright.Y - wallc->tright.X) / den; + x += frac * (curline->v2->fX() - x); + y += frac * (curline->v2->fY() - y); } - z2 = viewz - plane.ZatPointFixed(x, y); + z2 = ViewPos.Z - plane.ZatPoint(x, y); } else { @@ -2804,27 +2817,27 @@ int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc) } else { - x = curline->v1->fixX(); - y = curline->v1->fixY(); - if (wallc->sx1 == 0 && 0 != (den = wallc->tx1 - wallc->tx2 + wallc->ty1 - wallc->ty2)) + x = curline->v1->fX(); + y = curline->v1->fY(); + 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); - x += MulScale30 (frac, curline->v2->fixX() - x); - y += MulScale30 (frac, curline->v2->fixY() - y); + double frac = (wallc->tleft.Y + wallc->tleft.X) / den; + x += frac * (curline->v2->fX() - x); + 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) { - x = curline->v2->fixX(); - y = curline->v2->fixY(); - if (wallc->sx2 == viewwidth && 0 != (den = wallc->tx1 - wallc->tx2 - wallc->ty1 + wallc->ty2)) + x = curline->v2->fX(); + y = curline->v2->fY(); + 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); - x -= MulScale30 (frac, x - curline->v1->fixX()); - y -= MulScale30 (frac, y - curline->v1->fixY()); + double frac = (wallc->tright.Y - wallc->tright.X) / den; + x -= frac * (x - curline->v1->fX()); + y -= frac * (y - curline->v1->fY()); } - z2 = viewz - plane.ZatPointFixed(x, y); + z2 = ViewPos.Z - plane.ZatPoint(x, y); } 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); - s3 = MulScale12 (globaldclip, wallc->sz1); s4 = MulScale12 (globaldclip, wallc->sz2); + s1 = globaluclip * wallc->sz1; s2 = globaluclip * wallc->sz2; + s3 = globaldclip * wallc->sz1; s4 = globaldclip * wallc->sz2; bad = (z1s3)<<2)+((z2>s4)<<3); ix1 = wallc->sx1; ix2 = wallc->sx2; @@ -2856,10 +2869,10 @@ int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc) if (bad&3) { //inty = intz / (globaluclip>>16) - int t = SafeDivScale30 (oz1-s1, s2-s1+oz1-oz2); - int inty = wallc->sz1 + MulScale30 (wallc->sz2-wallc->sz1,t); - int intz = oz1 + MulScale30 (oz2-oz1,t); - int xcross = wallc->sx1 + Scale (MulScale30 (wallc->sz2, t), wallc->sx2-wallc->sx1, inty); + double t = (oz1-s1) / (s2-s1+oz1-oz2); + double inty = wallc->sz1 + t * (wallc->sz2-wallc->sz1); + double intz = oz1 + t * (oz2-oz1); + 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)); //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) { //inty = intz / (globaldclip>>16) - int t = SafeDivScale30 (oz1-s3, s4-s3+oz1-oz2); - int inty = wallc->sz1 + MulScale30 (wallc->sz2-wallc->sz1,t); - int intz = oz1 + MulScale30 (oz2-oz1,t); - int xcross = wallc->sx1 + Scale (MulScale30 (wallc->sz2, t), wallc->sx2-wallc->sx1,inty); + double t = (oz1-s3) / (s4-s3+oz1-oz2); + double inty = wallc->sz1 + t * (wallc->sz2-wallc->sz1); + double intz = oz1 + t * (oz2-oz1); + 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)); //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) { - mostbuf[ix1] = (short)((y + centeryfrac) >> FRACBITS); + mostbuf[ix1] = (short)xs_RoundToInt(y/65536.0 + CenterY); } else { - fixed_t yinc = (Scale (z2>>4, InvZtoScale, iy2) - y) / (ix2-ix1); - qinterpolatedown16short (&mostbuf[ix1], ix2-ix1, y + centeryfrac,yinc); + fixed_t yinc = FLOAT2FIXED(((z2 * InvZtoScale / iy2) - y) / (ix2-ix1)); + qinterpolatedown16short (&mostbuf[ix1], ix2-ix1, FLOAT2FIXED(y/65536.0 + CenterY), yinc); } 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 double top, bot, i; - double xrepeat = fabs((double)walxrepeat); + double xrepeat = fabs(walxrepeat * 65536); double depth_scale = WallT.InvZstep * 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; 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 double top, bot, i; - double xrepeat = fabs((double)walxrepeat); - double topstep; + double xrepeat = fabs(walxrepeat * 65536); + double topstep, botstep; i = x1 - centerx; top = WallT.UoverZorg + WallT.UoverZstep * i; @@ -2991,6 +3004,7 @@ void PrepLWall (fixed_t *lwall, fixed_t walxrepeat, int x1, int x2) top *= xrepeat; topstep = WallT.UoverZstep * xrepeat; + botstep = WallT.InvZstep; 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); } 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 @@ -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) { - fixed_t lx, ly, lx2, ly2, decalx, decaly; + DVector2 decal_left, decal_right, decal_pos; int x1, x2; fixed_t xscale, yscale; fixed_t topoff; @@ -3095,16 +3109,14 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, double dcx, dcy; decal->GetXY(wall, dcx, dcy); - decalx = FLOAT2FIXED(dcx); - decaly = FLOAT2FIXED(dcy); + decal_pos = { dcx, dcy }; - angle_t ang = R_PointToAngle2 (curline->v1->fixX(), curline->v1->fixY(), curline->v2->fixX(), curline->v2->fixY()) >> ANGLETOFINESHIFT; - 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; + DVector2 angvec = (curline->v2->fPos() - curline->v1->fPos()).Unit(); - 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; x1 = WallC.sx1; @@ -3169,10 +3181,8 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, break; } - fixed_t fzpos; - fzpos = FLOAT2FIXED(zpos); // pacify GCC 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 x1 = MAX(clipper->x1, x1); diff --git a/src/r_segs.h b/src/r_segs.h index 74b5b6bba..8e528bca0 100644 --- a/src/r_segs.h +++ b/src/r_segs.h @@ -31,10 +31,10 @@ extern short *openings; extern ptrdiff_t lastopening; 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); -void PrepWall (fixed_t *swall, fixed_t *lwall, fixed_t walxrepeat, int x1, int x2); -void PrepLWall (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, double walxrepeat, int x1, int x2); ptrdiff_t R_NewOpening (ptrdiff_t len); diff --git a/src/r_things.cpp b/src/r_things.cpp index bbecd1559..5ca1f7dcc 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -88,10 +88,10 @@ struct FCoverageBuffer 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) EXTERN_CVAR (Bool, st_scale) @@ -151,7 +151,7 @@ static vissprite_t **spritesorter; static int spritesortersize = 0; 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) { + fixed_t centeryfrac = FLOAT2FIXED(CenterY); while (span->Length != 0) { const int length = span->Length; @@ -357,13 +358,13 @@ 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. if (CurrentPortalInSkybox) return false; - for(drawseg_t *seg : portaldrawsegs) + for (drawseg_t *seg : portaldrawsegs) { // ignore segs from other portals if (seg->CurrentPortalUniq != CurrentPortalUniq) @@ -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.) - line_t* line = seg->curline->linedef; - // 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; // 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; fixed_t xiscale; 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) { // scaled to 0; can't see return; } + fixed_t centeryfrac = FLOAT2FIXED(CenterY); dc_colormap = vis->Style.colormap; 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)) { pixels = tex->GetColumn (frac >> FRACBITS, &spans); - if (ispsprite || !R_ClipSpriteColumnWithPortals(vis->gx, vis->gy, vis)) + if (ispsprite || !R_ClipSpriteColumnWithPortals(vis)) R_DrawMaskedColumn (pixels, spans); dc_x++; frac += xiscale; @@ -473,7 +473,7 @@ void R_DrawVisSprite (vissprite_t *vis) for (int zz = 4; zz; --zz) { pixels = tex->GetColumn (frac >> FRACBITS, &spans); - if (ispsprite || !R_ClipSpriteColumnWithPortals(vis->gx, vis->gy, vis)) + if (ispsprite || !R_ClipSpriteColumnWithPortals(vis)) R_DrawMaskedColumnHoriz (pixels, spans); dc_x++; frac += xiscale; @@ -484,7 +484,7 @@ void R_DrawVisSprite (vissprite_t *vis) while (dc_x < x2) { pixels = tex->GetColumn (frac >> FRACBITS, &spans); - if (ispsprite || !R_ClipSpriteColumnWithPortals(vis->gx, vis->gy, vis)) + if (ispsprite || !R_ClipSpriteColumnWithPortals(vis)) R_DrawMaskedColumn (pixels, spans); dc_x++; frac += xiscale; @@ -509,7 +509,7 @@ void R_DrawWallSprite(vissprite_t *spr) WallT.InitFromWallCoords(&spr->wallc); PrepWall(swall, lwall, spr->pic->GetWidth() << FRACBITS, x1, x2); yscale = spr->yscale; - dc_texturemid = FixedDiv(spr->gzt - viewz, yscale); + dc_texturemid = FixedDiv(FLOAT2FIXED(spr->gzt - ViewPos.Z), yscale); if (spr->renderflags & RF_XFLIP) { 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); GlobVis = r_WallVisibility; - rw_lightleft = SafeDivScale12(GlobVis, spr->wallc.sz1); - rw_lightstep = (SafeDivScale12(GlobVis, spr->wallc.sz2) - rw_lightleft) / (spr->wallc.sx2 - spr->wallc.sx1); + rw_lightleft = SafeDivScale12(GlobVis, xs_Fix<12>::ToFix(spr->wallc.sz1)); + 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; if (fixedlightlev >= 0) dc_colormap = usecolormap->Maps + fixedlightlev; @@ -595,7 +595,7 @@ void R_DrawWallSprite(vissprite_t *spr) { // calculate lighting 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); dc_x++; } @@ -609,7 +609,7 @@ void R_DrawWallSprite(vissprite_t *spr) rt_initcols(); for (int zz = 4; zz; --zz) { - if (!R_ClipSpriteColumnWithPortals(spr->gx, spr->gy, spr)) + if (!R_ClipSpriteColumnWithPortals(spr)) R_WallSpriteColumn(R_DrawMaskedColumnHoriz); dc_x++; } @@ -622,7 +622,7 @@ void R_DrawWallSprite(vissprite_t *spr) { // calculate lighting 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); 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); spryscale = SafeDivScale32 (1, dc_iscale); if (sprflipvert) - sprtopscreen = centeryfrac + FixedMul (dc_texturemid, spryscale); + sprtopscreen = FLOAT2FIXED(CenterY) + FixedMul (dc_texturemid, spryscale); else - sprtopscreen = centeryfrac - FixedMul (dc_texturemid, spryscale); + sprtopscreen = FLOAT2FIXED(CenterY) - FixedMul (dc_texturemid, spryscale); const BYTE *column; 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. - 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, 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) { - fixed_t tr_x; - fixed_t tr_y; + double tr_x; + double tr_y; - fixed_t gzt; // killough 3/27/98 - fixed_t gzb; // [RH] use bottom of sprite, not actor - fixed_t tx, tx2; - fixed_t tz; + double gzt; // killough 3/27/98 + double gzb; // [RH] use bottom of sprite, not actor + double tx;// , tx2; + double tz; - fixed_t xscale = FRACUNIT, yscale = FRACUNIT; + double xscale = 1, yscale = 1; int x1; 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 DVector3 pos = thing->InterpolatedPosition(r_TicFracF); - const fixed_t fx = FLOAT2FIXED(pos.X); - const fixed_t fy = FLOAT2FIXED(pos.Y); - fixed_t fz = FLOAT2FIXED(pos.Z + thing->GetBobOffset(r_TicFracF)); + pos.Z += thing->GetBobOffset(r_TicFracF); tex = 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 spriteframe_t *sprframe = &SpriteFrames[tex->Rotations]; - angle_t ang = R_PointToAngle2 (viewx, viewy, fx, fy); + DAngle ang = (pos - ViewPos).Angle(); angle_t rot; 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 { - 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]; 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]; // choose a different rotation based on player view 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; 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 { - 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]; if (sprframe->Flip & (1 << rot)) @@ -872,37 +870,35 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor return; } - fixed_t spritescaleX = FLOAT2FIXED(spriteScale.X); - fixed_t spritescaleY = FLOAT2FIXED(spriteScale.Y); if ((renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE) { - R_ProjectWallSprite(thing, fx, fy, fz, picnum, spritescaleX, spritescaleY, renderflags); + R_ProjectWallSprite(thing, pos, picnum, spriteScale, renderflags); return; } // transform the origin point - tr_x = fx - viewx; - tr_y = fy - viewy; + tr_x = pos.X - ViewPos.X; + 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? if (voxel == NULL && tz < MINZ) return; - tx = DMulScale16 (tr_x, viewsin, -tr_y, viewcos); + tx = tr_x * ViewSin - tr_y * ViewCos; // [RH] Flip for mirrors if (MirrorFlags & RF_XFLIP) { tx = -tx; } - tx2 = tx >> 4; + //tx2 = tx >> 4; // too far off the side? // if it's a voxel, it can be further off the side - if ((voxel == NULL && (abs(tx) >> 6) > abs(tz)) || - (voxel != NULL && (abs(tx) >> 7) > abs(tz))) + if ((voxel == NULL && (fabs(tx / 64) > fabs(tz))) || + (voxel != NULL && (fabs(tx / 128) > abs(tz)))) { return; } @@ -912,16 +908,16 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor // [RH] Added scaling int scaled_to = tex->GetScaledTopOffset(); int scaled_bo = scaled_to - tex->GetScaledHeight(); - gzt = fz + spritescaleY * scaled_to; - gzb = fz + spritescaleY * scaled_bo; + gzt = pos.Z + spriteScale.Y * scaled_to; + gzb = pos.Z + spriteScale.Y * scaled_bo; } else { - xscale = fixed_t(spritescaleX * voxel->Scale); - yscale = fixed_t(spritescaleY * voxel->Scale); - fixed_t piv = fixed_t(voxel->Voxel->Mips[0].Pivot.Z*256.); - gzt = fz + MulScale8(yscale, piv) - FLOAT2FIXED(thing->Floorclip); - gzb = fz + MulScale8(yscale, piv - (voxel->Voxel->Mips[0].SizeZ << 8)); + xscale = spriteScale.X * voxel->Scale; + yscale = spriteScale.Y * voxel->Scale; + double piv = voxel->Voxel->Mips[0].Pivot.Z; + gzt = pos.Z + yscale * piv - thing->Floorclip; + gzb = pos.Z + yscale * (piv - voxel->Voxel->Mips[0].SizeZ); if (gzt <= gzb) return; } @@ -955,11 +951,10 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor if (voxel == NULL) { - xscale = DivScale12 (centerxfrac, tz); + xscale = CenterX / tz; // [RH] Reject sprites that are off the top or bottom of the screen - if (MulScale12 (globaluclip, tz) > viewz - gzb || - MulScale12 (globaldclip, tz) < viewz - gzt) + if (globaluclip * tz > ViewPos.Z - gzb || globaldclip * tz < ViewPos.Z - gzt) { return; } @@ -968,36 +963,36 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor renderflags ^= MirrorFlags & RF_XFLIP; // 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; - x1 = centerx + MulScale32 (tx, xscale); + x1 = centerx + xs_RoundToInt(tx * xscale); // off the right side? if (x1 >= WindowRight) return; tx += tex->GetWidth() * thingxscalemul; - x2 = centerx + MulScale32 (tx, xscale); + x2 = centerx + xs_RoundToInt(tx * xscale); // off the left side or too small? if ((x2 < WindowLeft || x2 <= x1)) return; - xscale = fixed_t(FixedMul(spritescaleX, xscale) / tex->Scale.X); + xscale = spriteScale.X * xscale / tex->Scale.X; 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 vis = R_NewVisSprite(); vis->CurrentPortalUniq = CurrentPortalUniq; - vis->xscale = xscale; - vis->yscale = Scale(InvZtoScale, yscale, tz << 4); - 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->xscale = FLOAT2FIXED(xscale); + vis->yscale = fixed_t(InvZtoScale * yscale / tz); + vis->idepth = float(1 / tz); 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->x2 = x2 > WindowRight ? WindowRight : x2; vis->angle = thing->Angles.Yaw.BAMs(); @@ -1021,14 +1016,14 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor vis = R_NewVisSprite(); vis->CurrentPortalUniq = CurrentPortalUniq; - vis->xscale = xscale; - vis->yscale = yscale; + vis->xscale = FLOAT2FIXED(xscale); + vis->yscale = FLOAT2FIXED(yscale); vis->x1 = WindowLeft; vis->x2 = WindowRight; - vis->idepth = (unsigned)DivScale32(1, MAX(tz, MINZ)) >> 1; + vis->idepth = 1 / MINZ; vis->floorclip = FLOAT2FIXED(thing->Floorclip); - fz -= FLOAT2FIXED(thing->Floorclip); + pos.Z -= thing->Floorclip; 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->vx = viewx; - vis->vy = viewy; - vis->vz = viewz; - vis->vang = viewangle; + vis->vpos = { (float)ViewPos.X, (float)ViewPos.Y, (float)ViewPos.Z }; + vis->vang = FAngle((float)ViewAngle.Degrees); } // killough 3/27/98: save sector for special clipping later vis->heightsec = heightsec; vis->sector = thing->Sector; - vis->depth = tz; - vis->gx = fx; - vis->gy = fy; - vis->gz = fz; - vis->gzb = gzb; // [RH] use gzb, not thing->z - vis->gzt = gzt; // killough 3/27/98 - vis->deltax = fx - viewx; - vis->deltay = fy - viewy; + vis->depth = (float)tz; + vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z }; + vis->gzb = (float)gzb; // [RH] use gzb, not thing->z + vis->gzt = (float)gzt; // killough 3/27/98 + vis->deltax = float(pos.X - ViewPos.X); + vis->deltay = float(pos.Y - ViewPos.Y); vis->renderflags = renderflags; if(thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D vis->Style.RenderStyle = thing->RenderStyle; @@ -1137,20 +1128,22 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor else { // diminished light 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); } } } -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; - int x1, x2; - fixed_t lx1, lx2, ly1, ly2; - fixed_t gzb, gzt, tz; + double x1, x2; + DVector2 left, right; + double gzb, gzt, tz; 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; // 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(); x1 = pic->GetScaledLeftOffset(); - x1 *= xscale; - x2 *= xscale; + x1 *= scale.X; + x2 *= scale.X; - lx1 = fx - FixedMul(x1, finecosine[ang]) - viewx; - ly1 = fy - FixedMul(x1, finesine[ang]) - viewy; - lx2 = lx1 + FixedMul(x2, finecosine[ang]); - ly2 = ly1 + FixedMul(x2, finesine[ang]); + left.X = pos.X - x1 * angcos - ViewPos.X; + left.Y = pos.Y - x1 * angsin - ViewPos.Y; + right.X = left.X + x2 * angcos; + right.Y = right.Y + x2 * angsin; // Is it off-screen? - if (wallc.Init(lx1, ly1, lx2, ly2, TOO_CLOSE_Z)) + if (wallc.Init(left, right, TOO_CLOSE_Z)) return; 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, // 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_bo = scaled_to - pic->GetScaledHeight(); - gzt = fz + yscale * scaled_to; - gzb = fz + yscale * scaled_bo; + gzt = pos.Z + scale.Y * scaled_to; + gzb = pos.Z + scale.Y * scaled_bo; vis = R_NewVisSprite(); vis->CurrentPortalUniq = CurrentPortalUniq; vis->x1 = wallc.sx1 < WindowLeft ? WindowLeft : wallc.sx1; vis->x2 = wallc.sx2 >= WindowRight ? WindowRight : wallc.sx2; - vis->yscale = yscale; - vis->idepth = (unsigned)DivScale32(1, tz) >> 1; - vis->depth = tz; + vis->yscale = FLOAT2FIXED(scale.Y); + vis->idepth = float(1 / tz); + vis->depth = (float)tz; vis->sector = thing->Sector; vis->heightsec = NULL; - vis->gx = fx; - vis->gy = fy; - vis->gz = fz; - vis->gzb = gzb; - vis->gzt = gzt; - vis->deltax = fx - viewx; - vis->deltay = fy - viewy; + vis->gpos = { (float)pos.X, (float)pos.Y, (float)pos.Z }; + vis->gzb = (float)gzb; + vis->gzt = (float)gzt; + vis->deltax = float(pos.X - ViewPos.X); + vis->deltay = float(pos.Y - ViewPos.Y); vis->renderflags = renderflags; if(thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D 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->bWallSprite = true; 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->wallc = wallc; } @@ -1325,14 +1316,14 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_ tx = sx-((320/2)<GetScaledLeftOffset() << FRACBITS; - x1 = (centerxfrac + FixedMul (tx, pspritexscale)) >>FRACBITS; + x1 = centerx + (FixedMul(tx, pspritexscale) >> FRACBITS); // off the right side if (x1 > viewwidth) return; tx += tex->GetScaledWidth() << FRACBITS; - x2 = ((centerxfrac + FixedMul (tx, pspritexscale)) >>FRACBITS); + x2 = centerx + (FixedMul(tx, pspritexscale) >> FRACBITS); // off the left side if (x2 <= 0) @@ -1544,10 +1535,10 @@ void R_DrawPlayerSprites () if(fixedlightlev < 0 && viewsector->e && viewsector->e->XFloor.lightlist.Size()) { 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; if(rover) { - if(rover->flags & FF_DOUBLESHADOW && viewz <= rover->bottom.plane->Zat0()) + if(rover->flags & FF_DOUBLESHADOW && ViewPos.Z <= rover->bottom.plane->Zat0()) break; sec = rover->model; if(rover->flags & FF_FADEWALLS) @@ -1586,11 +1577,10 @@ void R_DrawPlayerSprites () if (camera->player != NULL) { - fixed_t centerhack = centeryfrac; + double centerhack = CenterY; float ofsx, ofsy; - centery = viewheight >> 1; - centeryfrac = centery << FRACBITS; + CenterY = viewheight / 2; P_BobWeapon (camera->player, &camera->player->psprites[ps_weapon], &ofsx, &ofsy, r_TicFracF); @@ -1611,8 +1601,7 @@ void R_DrawPlayerSprites () } } - centeryfrac = centerhack; - centery = centerhack >> FRACBITS; + CenterY = centerhack; } } @@ -1914,8 +1903,8 @@ void R_DrawSprite (vissprite_t *spr) if (!spr->bIsVoxel && spr->pic == NULL) { // kg3D - reject invisible parts - if ((fake3D & FAKE3D_CLIPBOTTOM) && spr->gz <= sclipBottom) return; - if ((fake3D & FAKE3D_CLIPTOP) && spr->gz >= sclipTop) return; + if ((fake3D & FAKE3D_CLIPBOTTOM) && spr->gpos.Z <= sclipBottom) return; + if ((fake3D & FAKE3D_CLIPTOP) && spr->gpos.Z >= sclipTop) return; R_DrawParticle (spr); return; } @@ -1940,7 +1929,7 @@ void R_DrawSprite (vissprite_t *spr) { if (!(fake3D & FAKE3D_CLIPTOP)) { - sclipTop = spr->sector->ceilingplane.ZatPointFixed(viewx, viewy); + sclipTop = spr->sector->ceilingplane.ZatPointFixed(ViewPos); } sector_t *sec = NULL; for (i = spr->sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) @@ -2013,7 +2002,7 @@ void R_DrawSprite (vissprite_t *spr) { // diminished light spriteshade = LIGHT2SHADE(sec->lightlevel + r_actualextralight); 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. // [RH] rewrote this to be based on which part of the sector is really visible - fixed_t scale = MulScale19 (InvZtoScale, spr->idepth); - fixed_t hzb = FIXED_MIN, hzt = FIXED_MAX; + double scale = InvZtoScale * spr->idepth; + double hzb = DBL_MIN, hzt = DBL_MAX; if (spr->bIsVoxel && spr->floorclip != 0) { @@ -2040,8 +2029,8 @@ void R_DrawSprite (vissprite_t *spr) { // only things in specially marked sectors if (spr->FakeFlatStat != FAKED_AboveCeiling) { - fixed_t hz = spr->heightsec->floorplane.ZatPointFixed(spr->gx, spr->gy); - fixed_t h = (centeryfrac - FixedMul (hz-viewz, scale)) >> FRACBITS; + double hz = spr->heightsec->floorplane.ZatPoint(spr->gpos); + int h = xs_RoundToInt(CenterY - (hz - ViewPos.Z) * scale); if (spr->FakeFlatStat == FAKED_BelowFloor) { // 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)) { - fixed_t hz = spr->heightsec->ceilingplane.ZatPointFixed(spr->gx, spr->gy); - fixed_t h = (centeryfrac - FixedMul (hz-viewz, scale)) >> FRACBITS; + double hz = spr->heightsec->ceilingplane.ZatPoint(spr->gpos); + int h = xs_RoundToInt(CenterY - (hz - ViewPos.Z) * scale); if (spr->FakeFlatStat == FAKED_AboveCeiling) { // 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 else if (!spr->bIsVoxel && spr->floorclip) { // [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->floorclip, spr->yscale)) >> FRACBITS); if (clip < botclip) @@ -2099,16 +2088,16 @@ void R_DrawSprite (vissprite_t *spr) { if (!spr->bIsVoxel) { - fixed_t h = sclipBottom; + double hz = sclipBottom; if (spr->fakefloor) { - fixed_t floorz = spr->fakefloor->top.plane->Zat0(); - if (viewz > floorz && floorz == sclipBottom ) + double floorz = spr->fakefloor->top.plane->Zat0(); + 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) { botclip = MAX(0, h); @@ -2120,17 +2109,16 @@ void R_DrawSprite (vissprite_t *spr) { if (!spr->bIsVoxel) { - fixed_t h = sclipTop; - + double hz = sclipTop; if (spr->fakeceiling != NULL) { - fixed_t ceilingZ = spr->fakeceiling->bottom.plane->Zat0(); - if (viewz < ceilingZ && ceilingZ == sclipTop) + double ceilingZ = spr->fakeceiling->bottom.plane->Zat0(); + 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) { topclip = MIN(h, viewheight); @@ -2206,7 +2194,7 @@ void R_DrawSprite (vissprite_t *spr) r1 = MAX (ds->x1, x1); r2 = MIN (ds->x2, x2); - fixed_t neardepth, fardepth; + float neardepth, fardepth; if (!spr->bWallSprite) { if (ds->sz1 < ds->sz2) @@ -2220,8 +2208,8 @@ void R_DrawSprite (vissprite_t *spr) } // Check if sprite is in front of draw seg: 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(), - ds->curline->v1->fixX() - spr->gx, ds->curline->v2->fixY() - ds->curline->v1->fixY()) <= 0)) + (spr->gpos.Y - ds->curline->v1->fY()) * (ds->curline->v2->fX() - ds->curline->v1->fX()) - + (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 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); } - int minvoxely = spr->gzt <= hzt ? 0 : (spr->gzt - hzt) / spr->yscale; - int maxvoxely = spr->gzb > hzb ? INT_MAX : (spr->gzt - hzb) / spr->yscale; + int minvoxely = spr->gzt <= hzt ? 0 : FLOAT2FIXED(spr->gzt - hzt) / spr->yscale; + int maxvoxely = spr->gzb > hzb ? INT_MAX : FLOAT2FIXED(spr->gzt - hzb) / spr->yscale; R_DrawVisVoxel(spr, minvoxely, maxvoxely, cliptop, clipbot); } 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) { @@ -2376,7 +2364,7 @@ void R_DrawMasked (void) HeightLevel *hl; // 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) { @@ -2397,7 +2385,7 @@ void R_DrawMasked (void) sclipTop = height_top->height; R_DrawMaskedSingle(true); 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); 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) { - fixed_t tr_x; - fixed_t tr_y; - fixed_t tx, ty; - fixed_t tz, tiz; - fixed_t xscale, yscale; + double tr_x, tr_y; + double tx, ty; + double tz, tiz; + double xscale, yscale; int x1, x2, y1, y2; vissprite_t* vis; sector_t* heightsec = NULL; @@ -2436,16 +2423,16 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade, return; // transform the origin point - tr_x = FLOAT2FIXED(particle->Pos.X - ViewPos.X); - tr_y = FLOAT2FIXED(particle->Pos.Y - ViewPos.Y); + tr_x = particle->Pos.X - ViewPos.X; + 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? if (tz < MINZ) return; - tx = DMulScale20 (tr_x, viewsin, -tr_y, viewcos); + tx = tr_x * ViewSin - tr_y * ViewCos; // Flip for mirrors 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? - if (tz <= abs (tx)) + if (tz <= fabs(tx)) return; - tiz = 268435456 / tz; + tiz = 1 / tz; xscale = centerx * tiz; // calculate edges of the shape - int psize = particle->size << (12-3); + double psize = particle->size / 8.0; - x1 = MAX (WindowLeft, (centerxfrac + MulScale12 (tx-psize, xscale)) >> FRACBITS); - x2 = MIN (WindowRight, (centerxfrac + MulScale12 (tx+psize, xscale)) >> FRACBITS); + x1 = MAX(WindowLeft, centerx + xs_RoundToInt((tx - psize) * xscale)); + x2 = MIN(WindowRight, centerx + xs_RoundToInt((tx + psize) * xscale)); if (x1 >= x2) return; - yscale = MulScale16(yaspectmul, xscale); + yscale = xs_RoundToInt(YaspectMul * xscale); ty = FLOAT2FIXED(particle->Pos.Z - ViewPos.Z); - psize <<= 4; - y1 = (centeryfrac - FixedMul (ty+psize, yscale)) >> FRACBITS; - y2 = (centeryfrac - FixedMul (ty-psize, yscale)) >> FRACBITS; + y1 = xs_RoundToInt(CenterY - (ty + psize) * yscale); + y2 = xs_RoundToInt(CenterY - (ty - psize) * yscale); // 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. @@ -2540,16 +2526,13 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade, vis = R_NewVisSprite (); vis->CurrentPortalUniq = CurrentPortalUniq; vis->heightsec = heightsec; - vis->xscale = xscale; + vis->yscale = vis->xscale = FLOAT2FIXED(xscale); // vis->yscale = FixedMul (xscale, InvZtoScale); - vis->yscale = xscale; - vis->depth = tz; - vis->idepth = (DWORD)DivScale32 (1, tz) >> 1; - vis->gx = FLOAT2FIXED(particle->Pos.X); - vis->gy = FLOAT2FIXED(particle->Pos.Y); - vis->gz = FLOAT2FIXED(particle->Pos.Z); - vis->gzb = y1; - vis->gzt = y2; + vis->depth = (float)tz; + vis->idepth = float(1 / tz); + vis->gpos = { (float)particle->Pos.X, (float)particle->Pos.Y, (float)particle->Pos.Z }; + vis->y1 = y1; + vis->y2 = y2; vis->x1 = x1; vis->x2 = x2; vis->Translation = 0; @@ -2569,14 +2552,15 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade, { vis->Style.colormap = fixedcolormap; } - else if(particle->bright) { + else if (particle->bright) + { vis->Style.colormap = map; } else { // Using MulScale15 instead of 16 makes particles slightly more visible // 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); } } @@ -2597,7 +2581,7 @@ static void R_DrawMaskedSegsBehindParticle (const vissprite_t *vis) { 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 if (ds->CurrentPortalUniq == vis->CurrentPortalUniq) @@ -2613,8 +2597,8 @@ void R_DrawParticle (vissprite_t *vis) BYTE *dest; DWORD fg; BYTE color = vis->Style.colormap[vis->startfrac]; - int yl = vis->gzb; - int ycount = vis->gzt - yl + 1; + int yl = vis->y1; + int ycount = vis->y2 - yl + 1; int x1 = vis->x1; int countbase = vis->x2 - x1; @@ -2658,7 +2642,7 @@ void R_DrawParticle (vissprite_t *vis) for (int x = x1; x < (x1+countbase); x++) { dc_x = x; - if (R_ClipSpriteColumnWithPortals(vis->gx, vis->gy, vis)) + if (R_ClipSpriteColumnWithPortals(vis)) continue; dest = ylookup[yl] + x + dc_destorg; 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, - fixed_t dasprx, fixed_t daspry, fixed_t dasprz, angle_t dasprang, +void R_DrawVoxel(const FVector3 &globalpos, FAngle viewangle, + const FVector3 &dasprpos, angle_t dasprang, fixed_t daxscale, fixed_t dayscale, FVoxel *voxobj, 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]; 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 centerxwidebig_f = centerxwide_f * 65536*65536*8; // Convert to Build's coordinate system. - globalposx = globalposx >> 12; - globalposy = -globalposy >> 12; - globalposz = -globalposz >> 8; + fixed_t globalposx = xs_Fix<4>::ToFix(globalpos.X); + fixed_t globalposy = xs_Fix<4>::ToFix(-globalpos.Y); + fixed_t globalposz = xs_Fix<8>::ToFix(-globalpos.Z); - dasprx = dasprx >> 12; - daspry = -daspry >> 12; - dasprz = -dasprz >> 8; + fixed_t dasprx = xs_Fix<4>::ToFix(dasprpos.X); + fixed_t daspry = xs_Fix<4>::ToFix(-dasprpos.Y); + fixed_t dasprz = xs_Fix<8>::ToFix(-dasprpos.Z); // Shift the scales from 16 bits of fractional precision to 6. // Also do some magic voodoo scaling to make them the right size. daxscale = daxscale / (0xC000 >> 6); dayscale = dayscale / (0xC000 >> 6); + angle_t viewang = viewangle.BAMs(); cosang = finecosine[viewang >> ANGLETOFINESHIFT] >> 2; sinang = -finesine[viewang >> 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 i = abs(DMulScale6(dasprx - globalposx, cosang, daspry - globalposy, sinang)); i = DivScale6(i, MIN(daxscale, dayscale)); - j = FocalLengthX >> 3; + j = xs_Fix<13>::ToFix(FocalLengthX); for (k = 0; i >= j && k < voxobj->NumMips; ++k) { i >>= 1; @@ -2730,8 +2715,8 @@ void R_DrawVoxel(fixed_t globalposx, fixed_t globalposy, fixed_t globalposz, ang maxslabz >>= k; daxscale <<= (k+8); dayscale <<= (k+8); - dazscale = FixedDiv(dayscale, baseyaspectmul); - daxscale = FixedDiv(daxscale, yaspectmul); + dazscale = FixedDiv(dayscale, FLOAT2FIXED(BaseYaspectMul)); + daxscale = fixed_t(daxscale / YaspectMul); daxscale = Scale(daxscale, xdimenscale, centerxwide << 9); dayscale = Scale(dayscale, FixedMul(xdimenscale, viewingrangerecip), centerxwide << 9); diff --git a/src/r_things.h b/src/r_things.h index a80466d5b..17b9d9845 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -32,13 +32,17 @@ struct vissprite_t { 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; - fixed_t gzb, gzt; // global bottom / top for silhouette clipping fixed_t xscale, yscale; - fixed_t depth; - fixed_t idepth; // 1/z - fixed_t deltax, deltay; + float depth; + float idepth; // 1/z + float deltax, deltay; DWORD FillColor; fixed_t floorclip; union @@ -63,8 +67,8 @@ struct vissprite_t // Used by voxels struct { - fixed_t vx, vy, vz; // view origin - angle_t vang; // view angle + FVector3 vpos; // view origin + FAngle vang; // view angle }; }; 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 visstyle_t Style; 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; @@ -128,9 +135,9 @@ void R_CheckOffscreenBuffer(int width, int height, bool spansonly); 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, - fixed_t dasprx, fixed_t daspry, fixed_t dasprz, angle_t dasprang, - fixed_t daxscale, fixed_t dayscale, FVoxel *voxobj, +void R_DrawVoxel(const FVector3 &viewpos, FAngle viewangle, + const FVector3 &sprpos, angle_t dasprang, + fixed_t daxscale, fixed_t dayscale, struct FVoxel *voxobj, lighttable_t *colormap, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags); void R_ClipVisSprite (vissprite_t *vis, int xl, int xh); diff --git a/src/r_utility.cpp b/src/r_utility.cpp index b8608daba..fbc390ef4 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -123,8 +123,8 @@ int otic; sector_t *viewsector; -fixed_t viewcos, viewtancos; -fixed_t viewsin, viewtansin; +double ViewCos, ViewTanCos; +double ViewSin, ViewTanSin; AActor *camera; // [RH] camera to draw from. doesn't have to be a player @@ -142,7 +142,7 @@ int WidescreenRatio; int setblocks; int extralight; bool setsizeneeded; -fixed_t FocalTangent; +double FocalTangent; unsigned int R_OldBlend = ~0; 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; -fixed_t viewx, viewy, viewz; -angle_t viewangle; -int viewpitch; +DVector3a view; +DAngle viewpitch; // CODE -------------------------------------------------------------------- @@ -463,7 +462,7 @@ void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight) fov = 170*FINEANGLES/360; } - FocalTangent = finetangent[FINEANGLES/4+fov/2]; + FocalTangent = FIXED2FLOAT(finetangent[FINEANGLES/4+fov/2]); Renderer->SetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio); } @@ -737,11 +736,11 @@ void R_ResetViewInterpolation () void R_SetViewAngle () { - viewsin = FLOAT2FIXED(ViewAngle.Sin()); - viewcos = FLOAT2FIXED(ViewAngle.Cos()); + ViewSin = ViewAngle.Sin(); + ViewCos = ViewAngle.Cos(); - viewtansin = FixedMul (FocalTangent, viewsin); - viewtancos = FixedMul (FocalTangent, viewcos); + ViewTanSin = FocalTangent * ViewSin; + 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->SetupFrame(player); diff --git a/src/r_utility.h b/src/r_utility.h index 06ed29654..1cdfda6eb 100644 --- a/src/r_utility.h +++ b/src/r_utility.h @@ -17,18 +17,14 @@ extern DAngle ViewAngle; extern DAngle ViewPitch; 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 centery; extern int setblocks; -extern fixed_t viewtancos; -extern fixed_t viewtansin; -extern fixed_t FocalTangent; +extern double ViewTanCos; +extern double ViewTanSin; +extern double FocalTangent; extern bool r_NoInterpolate; extern int validcount; diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 0a839eb7f..7097ebd27 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -199,8 +199,8 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) unmaskedSpan[1].Length = 0; } - fixed_t centeryback = centeryfrac; - centeryfrac = 0; + double centeryback = CenterY; + CenterY = 0; sprtopscreen = FLOAT2FIXED(y0); // 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_iscale = 0xffffffffu / (unsigned)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; double xiscale = img->GetWidth() / parms.destwidth; double x2 = x0 + parms.destwidth; @@ -325,7 +325,7 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) frac += xiscale_i; } } - centeryfrac = centeryback; + CenterY = centeryback; } R_FinishSetPatchStyle (); From 4416d88eb225c70063a5e1827537b17d3cf0bf65 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 14 Apr 2016 17:18:17 -0500 Subject: [PATCH 04/12] Renderer floatification: Use floating point for visibility values --- src/r_main.cpp | 47 +++++++++++++++++++++++------------------------ src/r_main.h | 17 ++++++++--------- src/r_plane.cpp | 18 +++++++++--------- src/r_plane.h | 2 +- src/r_segs.cpp | 4 ++-- src/r_things.cpp | 15 +++++++-------- 6 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index ed9593390..b30b02e33 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -93,9 +93,9 @@ extern bool r_showviewer; // PRIVATE DATA DECLARATIONS ----------------------------------------------- -static float CurrentVisibility = 8.f; -static fixed_t MaxVisForWall; -static fixed_t MaxVisForFloor; +static double CurrentVisibility = 8.f; +static double MaxVisForWall; +static double MaxVisForFloor; bool r_dontmaplines; // PUBLIC DATA DEFINITIONS ------------------------------------------------- @@ -103,15 +103,14 @@ bool r_dontmaplines; CVAR (String, r_viewsize, "", CVAR_NOSET) CVAR (Bool, r_shadercolormaps, true, CVAR_ARCHIVE) -fixed_t r_BaseVisibility; -fixed_t r_WallVisibility; -fixed_t r_FloorVisibility; +double r_BaseVisibility; +double r_WallVisibility; +double r_FloorVisibility; float r_TiltVisibility; -fixed_t r_SpriteVisibility; -fixed_t r_ParticleVisibility; -fixed_t r_SkyVisibility; +double r_SpriteVisibility; +double r_ParticleVisibility; -fixed_t GlobVis; +double GlobVis; fixed_t viewingrangerecip; double FocalLengthX; double FocalLengthY; @@ -250,10 +249,10 @@ void R_InitTextureMapping () // //========================================================================== -void R_SetVisibility (float vis) +void R_SetVisibility(double vis) { // Allow negative visibilities, just for novelty's sake - vis = clamp (vis, -204.7f, 204.7f); // (205 and larger do not work in 5:4 aspect ratio) + vis = clamp(vis, -204.7, 204.7); // (205 and larger do not work in 5:4 aspect ratio) CurrentVisibility = vis; @@ -264,7 +263,7 @@ void R_SetVisibility (float vis) return; } - r_BaseVisibility = xs_RoundToInt(vis * 65536.f); + r_BaseVisibility = vis; // Prevent overflow on walls if (r_BaseVisibility < 0 && r_BaseVisibility < -MaxVisForWall) @@ -274,8 +273,8 @@ void R_SetVisibility (float vis) else r_WallVisibility = r_BaseVisibility; - r_WallVisibility = FixedMul (FLOAT2FIXED(InvZtoScale * SCREENWIDTH*BaseRatioSizes[WidescreenRatio][1] / - (viewwidth*SCREENHEIGHT*3)), xs_ToInt(r_WallVisibility * FocalTangent)); + r_WallVisibility = (InvZtoScale * SCREENWIDTH*BaseRatioSizes[WidescreenRatio][1] / + (viewwidth*SCREENHEIGHT*3)) * (r_WallVisibility * FocalTangent); // Prevent overflow on floors/ceilings. Note that the calculation of // MaxVisForFloor means that planes less than two units from the player's @@ -288,9 +287,9 @@ void R_SetVisibility (float vis) else r_FloorVisibility = r_BaseVisibility; - r_FloorVisibility = xs_ToInt(160.0 * r_FloorVisibility / FocalLengthY); + r_FloorVisibility = 160.0 * r_FloorVisibility / FocalLengthY; - r_TiltVisibility = vis * (float)FocalTangent * (16.f * 320.f) / (float)viewwidth; + r_TiltVisibility = float(vis * FocalTangent * (16.f * 320.f) / viewwidth); r_SpriteVisibility = r_WallVisibility; } @@ -300,7 +299,7 @@ void R_SetVisibility (float vis) // //========================================================================== -float R_GetVisibility () +double R_GetVisibility() { return CurrentVisibility; } @@ -323,7 +322,7 @@ CCMD (r_visibility) } else if (!netgame) { - R_SetVisibility ((float)atof (argv[1])); + R_SetVisibility(atof(argv[1])); } else { @@ -396,13 +395,13 @@ void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, R_InitTextureMapping (); - MaxVisForWall = FLOAT2FIXED((InvZtoScale * (SCREENWIDTH*r_Yaspect) / - (viewwidth*SCREENHEIGHT * FocalTangent))); - MaxVisForWall = FixedDiv (0x7fff0000, MaxVisForWall); - MaxVisForFloor = int(0x7fff0000 / (viewheight * FocalLengthY / 160)); + MaxVisForWall = (InvZtoScale * (SCREENWIDTH*r_Yaspect) / + (viewwidth*SCREENHEIGHT * FocalTangent)); + MaxVisForWall = 32767.0 / MaxVisForWall; + MaxVisForFloor = 32767.0 / (viewheight * FocalLengthY / 160); // Reset r_*Visibility vars - R_SetVisibility (R_GetVisibility ()); + R_SetVisibility(R_GetVisibility()); } //========================================================================== diff --git a/src/r_main.h b/src/r_main.h index ede0c5b3b..374c71ea3 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -82,17 +82,16 @@ extern bool r_dontmaplines; // Change R_CalcTiltedLighting() when this changes. #define GETPALOOKUP(vis,shade) (clamp (((shade)-MIN(MAXLIGHTVIS,(vis)))>>FRACBITS, 0, NUMCOLORMAPS-1)) -extern fixed_t GlobVis; +extern double GlobVis; -void R_SetVisibility (float visibility); -float R_GetVisibility (); +void R_SetVisibility(double visibility); +double R_GetVisibility(); -extern fixed_t r_BaseVisibility; -extern fixed_t r_WallVisibility; -extern fixed_t r_FloorVisibility; +extern double r_BaseVisibility; +extern double r_WallVisibility; +extern double r_FloorVisibility; extern float r_TiltVisibility; -extern fixed_t r_SpriteVisibility; -extern fixed_t r_SkyVisibility; +extern double r_SpriteVisibility; extern int r_actualextralight; extern bool foggy; @@ -137,7 +136,7 @@ void R_MultiresInit (void); extern int stacked_extralight; -extern float stacked_visibility; +extern double stacked_visibility; extern DVector3 stacked_viewpos; extern DAngle stacked_angle; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 61c204f94..c991871dd 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -98,7 +98,7 @@ visplane_t *ceilingplane; // you are changing them to draw a stacked sector. Otherwise, stacked sectors // won't draw in skyboxes properly. int stacked_extralight; -float stacked_visibility; +double stacked_visibility; DVector3 stacked_viewpos; DAngle stacked_angle; @@ -123,7 +123,7 @@ short ceilingclip[MAXWIDTH]; // texture mapping // -static fixed_t planeheight; +static double planeheight; extern "C" { // @@ -217,7 +217,7 @@ void R_MapPlane (int y, int x1) // [RH] Notice that I dumped the caching scheme used by Doom. // It did not offer any appreciable speedup. - distance = FixedMul (planeheight, yslope[y]); + distance = xs_ToInt(planeheight * yslope[y]); ds_xstep = FixedMul (distance, xstepscale); ds_ystep = FixedMul (distance, ystepscale); @@ -228,7 +228,7 @@ void R_MapPlane (int y, int x1) { // Determine lighting based on the span's distance from the viewer. ds_colormap = basecolormap->Maps + (GETPALOOKUP ( - xs_ToInt(GlobVis * fabs(CenterY - y)), planeshade) << COLORMAPSHIFT); + FLOAT2FIXED(GlobVis * fabs(CenterY - y)), planeshade) << COLORMAPSHIFT); } #ifdef X86_ASM @@ -1187,7 +1187,7 @@ void R_DrawPortals () ptrdiff_t savedds_p = ds_p - drawsegs; ptrdiff_t savedlastopening = lastopening; size_t savedinteresting = FirstInterestingDrawseg; - float savedvisibility = R_GetVisibility (); + double savedvisibility = R_GetVisibility(); AActor *savedcamera = camera; sector_t *savedsector = viewsector; @@ -1359,7 +1359,7 @@ void R_DrawPortals () camera = savedcamera; viewsector = savedsector; ViewPos = savedpos; - R_SetVisibility (savedvisibility); + R_SetVisibility(savedvisibility); extralight = savedextralight; ViewAngle = savedangle; R_SetViewAngle (); @@ -1559,9 +1559,9 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske basexfrac = FixedMul (xscale, finecosine[planeang]) + x*xstepscale; baseyfrac = FixedMul (yscale, -finesine[planeang]) + x*ystepscale; - planeheight = FLOAT2FIXED(fabs(pl->height.Zat0() - ViewPos.Z)); + planeheight = fabs(pl->height.Zat0() - ViewPos.Z); - GlobVis = FixedDiv (r_FloorVisibility, planeheight); + GlobVis = r_FloorVisibility / planeheight; if (fixedlightlev >= 0) ds_colormap = basecolormap->Maps + fixedlightlev, plane_shade = false; else if (fixedcolormap) @@ -1709,7 +1709,7 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske plane_sz[0] = -plane_sz[0]; } - planelightfloat = (r_TiltVisibility * lxscale * lyscale) / (fabs(pl->height.ZatPoint(ViewPos)) / 65536.0); + planelightfloat = (r_TiltVisibility * lxscale * lyscale) / fabs(pl->height.ZatPoint(ViewPos)); if (pl->height.fC() > 0) planelightfloat = -planelightfloat; diff --git a/src/r_plane.h b/src/r_plane.h index d0cb0304b..c95137773 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -50,7 +50,7 @@ struct visplane_s // have stacked sectors inside a skybox. If the visplane is not for a // stack, then they are unused. int extralight; - float visibility; + double visibility; DVector3 viewpos; DAngle viewangle; fixed_t Alpha; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 3ad6d6316..a6fa63d68 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -2312,8 +2312,8 @@ void R_NewWall (bool needlights) wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, frontsector->lightlevel) + r_actualextralight); GlobVis = r_WallVisibility; - rw_lightleft = FLOAT2FIXED(FIXED2DBL(GlobVis) / WallC.sz1); - rw_lightstep = (FLOAT2FIXED(FIXED2DBL(GlobVis) / WallC.sz2) - rw_lightleft) / (WallC.sx2 - WallC.sx1); + rw_lightleft = FLOAT2FIXED(GlobVis / WallC.sz1); + rw_lightstep = (FLOAT2FIXED(GlobVis / WallC.sz2) - rw_lightleft) / (WallC.sx2 - WallC.sx1); } else { diff --git a/src/r_things.cpp b/src/r_things.cpp index 5ca1f7dcc..e53f57cfc 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -533,8 +533,8 @@ void R_DrawWallSprite(vissprite_t *spr) int shade = LIGHT2SHADE(spr->sector->lightlevel + r_actualextralight); GlobVis = r_WallVisibility; - rw_lightleft = SafeDivScale12(GlobVis, xs_Fix<12>::ToFix(spr->wallc.sz1)); - rw_lightstep = (SafeDivScale12(GlobVis, xs_Fix<12>::ToFix(spr->wallc.sz2)) - rw_lightleft) / (spr->wallc.sx2 - spr->wallc.sx1); + rw_lightleft = FLOAT2FIXED(GlobVis / spr->wallc.sz1); + rw_lightstep = (FLOAT2FIXED(GlobVis / spr->wallc.sz2) - rw_lightleft) / (spr->wallc.sx2 - spr->wallc.sx1); rw_light = rw_lightleft + (x1 - spr->wallc.sx1) * rw_lightstep; if (fixedlightlev >= 0) dc_colormap = usecolormap->Maps + fixedlightlev; @@ -1128,7 +1128,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor else { // diminished light vis->ColormapNum = GETPALOOKUP( - (fixed_t)(r_SpriteVisibility / MAX(tz, MINZ)), spriteshade); + FLOAT2FIXED(r_SpriteVisibility / MAX(tz, MINZ)), spriteshade); vis->Style.colormap = mybasecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT); } } @@ -1204,7 +1204,7 @@ static void R_ProjectWallSprite(AActor *thing, const DVector3 &pos, FTextureID p vis->bIsVoxel = false; vis->bWallSprite = true; vis->ColormapNum = GETPALOOKUP( - (fixed_t)DivScale12 (r_SpriteVisibility, xs_Fix<20>::ToFix(MAX(tz, MINZ))), spriteshade); + FLOAT2FIXED(r_SpriteVisibility / MAX(tz, MINZ)), spriteshade); vis->Style.colormap = basecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT); vis->wallc = wallc; } @@ -2002,7 +2002,7 @@ void R_DrawSprite (vissprite_t *spr) { // diminished light spriteshade = LIGHT2SHADE(sec->lightlevel + r_actualextralight); spr->Style.colormap = mybasecolormap->Maps + (GETPALOOKUP ( - (fixed_t)DivScale12 (r_SpriteVisibility, xs_Fix<20>::ToFix(MAX(MINZ, (double)spr->depth))), spriteshade) << COLORMAPSHIFT); + FLOAT2FIXED(r_SpriteVisibility / MAX(MINZ, (double)spr->depth)), spriteshade) << COLORMAPSHIFT); } } } @@ -2558,9 +2558,8 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade, } else { - // Using MulScale15 instead of 16 makes particles slightly more visible - // than regular sprites. - vis->ColormapNum = GETPALOOKUP(MulScale15 (FLOAT2FIXED(tiz), r_SpriteVisibility), shade); + // Particles are slightly more visible than regular sprites. + vis->ColormapNum = GETPALOOKUP(FLOAT2FIXED(tiz * r_SpriteVisibility * 0.5), shade); vis->Style.colormap = map + (vis->ColormapNum << COLORMAPSHIFT); } } From ec8d038c991807ea0f75d65bed1eb662aabd0184 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 14 Apr 2016 19:14:04 -0500 Subject: [PATCH 05/12] Renderer floatification: Use floats for lighting values --- src/asm_ia32/tmap2.asm | 8 ++++---- src/r_bsp.h | 2 +- src/r_draw.cpp | 12 ++++++------ src/r_main.h | 4 ++-- src/r_plane.cpp | 14 +++++++------- src/r_plane.h | 2 +- src/r_segs.cpp | 24 ++++++++++++------------ src/r_segs.h | 6 +++--- src/r_things.cpp | 12 ++++++------ 9 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/asm_ia32/tmap2.asm b/src/asm_ia32/tmap2.asm index 8fa141e3f..9a7aa5534 100644 --- a/src/asm_ia32/tmap2.asm +++ b/src/asm_ia32/tmap2.asm @@ -294,11 +294,11 @@ R_DrawTiltedPlane_ASM: fmul dword [planelightfloat] fxch st1 fmul dword [planelightfloat] - sub esp,8 - fistp dword [esp] - fistp dword [esp+4] + sub esp,16 + fstp qword [esp] + fstp qword [esp+8] call R_CalcTiltedLighting - add esp, 12 + add esp, 20 xor eax, eax .litup add esp, 8 diff --git a/src/r_bsp.h b/src/r_bsp.h index 3fa1788d4..4c5f5f611 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -65,7 +65,7 @@ enum struct drawseg_t { seg_t* curline; - fixed_t light, lightstep; + float light, lightstep; fixed_t iscale, iscalestep; short x1, x2; // Same as sx1 and sx2, but clipped to the drawseg short sx1, sx2; // left, right of parent seg on screen diff --git a/src/r_draw.cpp b/src/r_draw.cpp index c12fce97a..a25770ebd 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -1757,8 +1757,8 @@ void mvlinec4 () #endif extern "C" short spanend[MAXHEIGHT]; -extern fixed_t rw_light; -extern fixed_t rw_lightstep; +extern float rw_light; +extern float rw_lightstep; extern int wallshade; static void R_DrawFogBoundarySection (int y, int y2, int x1) @@ -1795,12 +1795,12 @@ void R_DrawFogBoundary (int x1, int x2, short *uclip, short *dclip) // to create new horizontal spans whenever the light changes enough that // we need to use a new colormap. - fixed_t lightstep = rw_lightstep; - fixed_t light = rw_light+lightstep*(x2-x1-1); + double lightstep = rw_lightstep; + double light = rw_light + rw_lightstep*(x2-x1-1); int x = x2-1; int t2 = uclip[x]; int b2 = dclip[x]; - int rcolormap = GETPALOOKUP (light, wallshade); + int rcolormap = GETPALOOKUP(light, wallshade); int lcolormap; BYTE *basecolormapdata = basecolormap->Maps; @@ -1819,7 +1819,7 @@ void R_DrawFogBoundary (int x1, int x2, short *uclip, short *dclip) int stop; light -= rw_lightstep; - lcolormap = GETPALOOKUP (light, wallshade); + lcolormap = GETPALOOKUP(light, wallshade); if (lcolormap != rcolormap) { if (t2 < b2 && rcolormap != 0) diff --git a/src/r_main.h b/src/r_main.h index 374c71ea3..24103393d 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -75,12 +75,12 @@ extern bool r_dontmaplines; #define LIGHT2SHADE(l) ((NUMCOLORMAPS*2*FRACUNIT)-(((l)+12)*(FRACUNIT*NUMCOLORMAPS/128))) // MAXLIGHTSCALE from original DOOM, divided by 2. -#define MAXLIGHTVIS (24*FRACUNIT) +#define MAXLIGHTVIS (24.0) // Convert a shade and visibility to a clamped colormap index. // Result is not fixed point. // Change R_CalcTiltedLighting() when this changes. -#define GETPALOOKUP(vis,shade) (clamp (((shade)-MIN(MAXLIGHTVIS,(vis)))>>FRACBITS, 0, NUMCOLORMAPS-1)) +#define GETPALOOKUP(vis,shade) (clamp (((shade)-FLOAT2FIXED(MIN(MAXLIGHTVIS,double(vis))))>>FRACBITS, 0, NUMCOLORMAPS-1)) extern double GlobVis; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index c991871dd..9390249cb 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -228,7 +228,7 @@ void R_MapPlane (int y, int x1) { // Determine lighting based on the span's distance from the viewer. ds_colormap = basecolormap->Maps + (GETPALOOKUP ( - FLOAT2FIXED(GlobVis * fabs(CenterY - y)), planeshade) << COLORMAPSHIFT); + GlobVis * fabs(CenterY - y), planeshade) << COLORMAPSHIFT); } #ifdef X86_ASM @@ -253,9 +253,9 @@ void R_MapPlane (int y, int x1) //========================================================================== extern "C" { -void R_CalcTiltedLighting (fixed_t lval, fixed_t lend, int width) +void R_CalcTiltedLighting (double lval, double lend, int width) { - fixed_t lstep; + double lstep; BYTE *lightfiller; BYTE *basecolormapdata = basecolormap->Maps; int i = 0; @@ -311,7 +311,7 @@ void R_CalcTiltedLighting (fixed_t lval, fixed_t lend, int width) } while (i <= width && lval >= 0) { - tiltlighting[i++] = basecolormapdata + ((lval >> FRACBITS) << COLORMAPSHIFT); + tiltlighting[i++] = basecolormapdata + (xs_ToInt(lval) << COLORMAPSHIFT); lval += lstep; } lightfiller = basecolormapdata; @@ -334,7 +334,7 @@ void R_CalcTiltedLighting (fixed_t lval, fixed_t lend, int width) return; while (i <= width && lval < (NUMCOLORMAPS-1)*FRACUNIT) { - tiltlighting[i++] = basecolormapdata + ((lval >> FRACBITS) << COLORMAPSHIFT); + tiltlighting[i++] = basecolormapdata + (xs_ToInt(lval) << COLORMAPSHIFT); lval += lstep; } lightfiller = basecolormapdata + ((NUMCOLORMAPS-1) << COLORMAPSHIFT); @@ -371,7 +371,7 @@ void R_MapTiltedPlane (int y, int x1) { uz = (iz + plane_sz[0]*width) * planelightfloat; vz = iz * planelightfloat; - R_CalcTiltedLighting (xs_RoundToInt(vz), xs_RoundToInt(uz), width); + R_CalcTiltedLighting (vz, uz, width); } uz = plane_su[2] + plane_su[1]*(centery-y) + plane_su[0]*(x1-centerx); @@ -1709,7 +1709,7 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske plane_sz[0] = -plane_sz[0]; } - planelightfloat = (r_TiltVisibility * lxscale * lyscale) / fabs(pl->height.ZatPoint(ViewPos)); + planelightfloat = (r_TiltVisibility * lxscale * lyscale) / (fabs(pl->height.ZatPoint(ViewPos) - ViewPos.Z)) / 65536.f; if (pl->height.fC() > 0) planelightfloat = -planelightfloat; diff --git a/src/r_plane.h b/src/r_plane.h index c95137773..b99c61be0 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -39,7 +39,7 @@ struct visplane_s int lightlevel; fixed_t xoffs, yoffs; // killough 2/28/98: Support scrolling flats int left, right; - FDynamicColormap *colormap; // [RH] Support multiple colormaps + FDynamicColormap *colormap; // [RH] Support multiple colormaps fixed_t xscale, yscale; // [RH] Support flat scaling angle_t angle; // [RH] Support flat rotation int sky; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index a6fa63d68..9ffd82b8b 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -110,9 +110,9 @@ bool rw_markportal; bool rw_havehigh; bool rw_havelow; -fixed_t rw_light; // [RH] Scale lights with viewsize adjustments -fixed_t rw_lightstep; -fixed_t rw_lightleft; +float rw_light; // [RH] Scale lights with viewsize adjustments +float rw_lightstep; +float rw_lightleft; static double rw_frontlowertop; @@ -1080,7 +1080,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t int x, shiftval; int y1ve[4], y2ve[4], u4, d4, z; char bad; - fixed_t light = rw_light - rw_lightstep; + float light = rw_light - rw_lightstep; SDWORD texturemid, xoffset; BYTE *basecolormapdata; @@ -1158,7 +1158,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t } if (bad == 15) { - light += rw_lightstep << 2; + light += rw_lightstep * 4; continue; } @@ -1432,7 +1432,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe BYTE *p; int y1ve[4], y2ve[4], u4, d4, startx, dax, z; char bad; - fixed_t light = rw_light - rw_lightstep; + float light = rw_light - rw_lightstep; SDWORD texturemid, xoffset; BYTE *basecolormapdata; @@ -1507,7 +1507,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe } if (bad == 15) { - light += rw_lightstep << 2; + light += rw_lightstep * 4; continue; } @@ -1605,7 +1605,7 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, BYTE *p; int y1ve[4], y2ve[4], u4, d4, startx, dax, z; char bad; - fixed_t light = rw_light - rw_lightstep; + float light = rw_light - rw_lightstep; SDWORD texturemid, xoffset; BYTE *basecolormapdata; @@ -1681,7 +1681,7 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, } if (bad == 15) { - light += rw_lightstep << 2; + light += rw_lightstep * 4; continue; } @@ -2312,12 +2312,12 @@ void R_NewWall (bool needlights) wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, frontsector->lightlevel) + r_actualextralight); GlobVis = r_WallVisibility; - rw_lightleft = FLOAT2FIXED(GlobVis / WallC.sz1); - rw_lightstep = (FLOAT2FIXED(GlobVis / WallC.sz2) - rw_lightleft) / (WallC.sx2 - WallC.sx1); + rw_lightleft = float (GlobVis / WallC.sz1); + rw_lightstep = float((GlobVis / WallC.sz2 - rw_lightleft) / (WallC.sx2 - WallC.sx1)); } else { - rw_lightleft = FRACUNIT; + rw_lightleft = 1; rw_lightstep = 0; } } diff --git a/src/r_segs.h b/src/r_segs.h index 8e528bca0..7d1703423 100644 --- a/src/r_segs.h +++ b/src/r_segs.h @@ -44,9 +44,9 @@ void R_RenderSegLoop (); extern fixed_t swall[MAXWIDTH]; extern fixed_t lwall[MAXWIDTH]; -extern fixed_t rw_light; // [RH] Scale lights with viewsize adjustments -extern fixed_t rw_lightstep; -extern fixed_t rw_lightleft; +extern float rw_light; // [RH] Scale lights with viewsize adjustments +extern float rw_lightstep; +extern float rw_lightleft; extern fixed_t rw_offset; /* portal structure, this is used in r_ code in order to store drawsegs with portals (and mirrors) */ diff --git a/src/r_things.cpp b/src/r_things.cpp index e53f57cfc..c7961f1b5 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -533,8 +533,8 @@ void R_DrawWallSprite(vissprite_t *spr) int shade = LIGHT2SHADE(spr->sector->lightlevel + r_actualextralight); GlobVis = r_WallVisibility; - rw_lightleft = FLOAT2FIXED(GlobVis / spr->wallc.sz1); - rw_lightstep = (FLOAT2FIXED(GlobVis / spr->wallc.sz2) - rw_lightleft) / (spr->wallc.sx2 - spr->wallc.sx1); + rw_lightleft = float (GlobVis / spr->wallc.sz1); + rw_lightstep = float((GlobVis / spr->wallc.sz2 - rw_lightleft) / (spr->wallc.sx2 - spr->wallc.sx1)); rw_light = rw_lightleft + (x1 - spr->wallc.sx1) * rw_lightstep; if (fixedlightlev >= 0) dc_colormap = usecolormap->Maps + fixedlightlev; @@ -1128,7 +1128,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor else { // diminished light vis->ColormapNum = GETPALOOKUP( - FLOAT2FIXED(r_SpriteVisibility / MAX(tz, MINZ)), spriteshade); + r_SpriteVisibility / MAX(tz, MINZ), spriteshade); vis->Style.colormap = mybasecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT); } } @@ -1204,7 +1204,7 @@ static void R_ProjectWallSprite(AActor *thing, const DVector3 &pos, FTextureID p vis->bIsVoxel = false; vis->bWallSprite = true; vis->ColormapNum = GETPALOOKUP( - FLOAT2FIXED(r_SpriteVisibility / MAX(tz, MINZ)), spriteshade); + r_SpriteVisibility / MAX(tz, MINZ), spriteshade); vis->Style.colormap = basecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT); vis->wallc = wallc; } @@ -2002,7 +2002,7 @@ void R_DrawSprite (vissprite_t *spr) { // diminished light spriteshade = LIGHT2SHADE(sec->lightlevel + r_actualextralight); spr->Style.colormap = mybasecolormap->Maps + (GETPALOOKUP ( - FLOAT2FIXED(r_SpriteVisibility / MAX(MINZ, (double)spr->depth)), spriteshade) << COLORMAPSHIFT); + r_SpriteVisibility / MAX(MINZ, (double)spr->depth), spriteshade) << COLORMAPSHIFT); } } } @@ -2559,7 +2559,7 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade, else { // Particles are slightly more visible than regular sprites. - vis->ColormapNum = GETPALOOKUP(FLOAT2FIXED(tiz * r_SpriteVisibility * 0.5), shade); + vis->ColormapNum = GETPALOOKUP(tiz * r_SpriteVisibility * 0.5, shade); vis->Style.colormap = map + (vis->ColormapNum << COLORMAPSHIFT); } } From 4a1cc618228aaf6bdbe55fc73e852649b8d72da1 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 14 Apr 2016 20:09:38 -0500 Subject: [PATCH 06/12] Renderer floatification: Restore playersprite rendering --- src/r_main.cpp | 6 +++--- src/r_things.cpp | 32 ++++++++++++++++---------------- src/r_things.h | 6 +++--- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index b30b02e33..92e131e26 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -386,9 +386,9 @@ void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, WallTMapScale2 = IYaspectMul * (1 << 18) / CenterX; // psprite scales - pspritexscale = (centerxwide << FRACBITS) / 160; - pspriteyscale = FLOAT2FIXED(pspritexscale * YaspectMul); - pspritexiscale = FixedDiv(FRACUNIT, pspritexscale); + pspritexscale = centerxwide / 160.0; + pspriteyscale = pspritexscale * YaspectMul; + pspritexiscale = 1 / pspritexscale; // thing clipping clearbufshort (screenheightarray, viewwidth, (short)viewheight); diff --git a/src/r_things.cpp b/src/r_things.cpp index c7961f1b5..ec9822a71 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -105,9 +105,9 @@ EXTERN_CVAR(Bool, r_deathcamera); // This is not the same as the angle, // which increases counter clockwise (protractor). // -fixed_t pspritexscale; -fixed_t pspriteyscale; -fixed_t pspritexiscale; +double pspritexscale; +double pspritexiscale; +double pspriteyscale; fixed_t sky1scale; // [RH] Sky 1 scale factor fixed_t sky2scale; // [RH] Sky 2 scale factor @@ -1274,9 +1274,9 @@ void R_AddSprites (sector_t *sec, int lightlevel, int fakeside) // // R_DrawPSprite // -void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_t sy) +void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, double sx, double sy) { - fixed_t tx; + double tx; int x1; int x2; spritedef_t* sprdef; @@ -1313,17 +1313,17 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_ return; // calculate edges of the shape - tx = sx-((320/2)<GetScaledLeftOffset() << FRACBITS; - x1 = centerx + (FixedMul(tx, pspritexscale) >> FRACBITS); + tx -= tex->GetScaledLeftOffset(); + x1 = xs_RoundToInt(CenterX + tx * pspritexscale); // off the right side if (x1 > viewwidth) return; - tx += tex->GetScaledWidth() << FRACBITS; - x2 = centerx + (FixedMul(tx, pspritexscale) >> FRACBITS); + tx += tex->GetScaledWidth(); + x2 = xs_RoundToInt(CenterX + tx * pspritexscale); // off the left side if (x2 <= 0) @@ -1334,7 +1334,7 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_ vis->renderflags = owner->renderflags; vis->floorclip = 0; - vis->texturemid = int(((BASEYCENTER<Scale.Y) + (tex->TopOffset << FRACBITS); + vis->texturemid = FLOAT2FIXED((BASEYCENTER - sy) * tex->Scale.Y + tex->TopOffset); if (camera->player && (RenderTarget != screen || viewheight == RenderTarget->GetHeight() || @@ -1363,20 +1363,20 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_ } vis->x1 = x1 < 0 ? 0 : x1; vis->x2 = x2 >= viewwidth ? viewwidth : x2; - vis->xscale = fixed_t(pspritexscale / tex->Scale.X); - vis->yscale = fixed_t(pspriteyscale / tex->Scale.Y); + vis->xscale = FLOAT2FIXED(pspritexscale / tex->Scale.X); + vis->yscale = FLOAT2FIXED(pspriteyscale / tex->Scale.Y); vis->Translation = 0; // [RH] Use default colors vis->pic = tex; vis->ColormapNum = 0; if (flip) { - vis->xiscale = -int(pspritexiscale * tex->Scale.X); + vis->xiscale = -FLOAT2FIXED(pspritexiscale * tex->Scale.X); vis->startfrac = (tex->GetWidth() << FRACBITS) - 1; } else { - vis->xiscale = int(pspritexiscale * tex->Scale.X); + vis->xiscale = FLOAT2FIXED(pspritexiscale * tex->Scale.X); vis->startfrac = 0; } @@ -1592,7 +1592,7 @@ void R_DrawPlayerSprites () // [RH] Don't draw the targeter's crosshair if the player already has a crosshair set. if (psp->state && (i != ps_targetcenter || CrosshairImage == NULL)) { - R_DrawPSprite (psp, i, camera, FLOAT2FIXED(psp->sx + ofsx), FLOAT2FIXED(psp->sy + ofsy)); + R_DrawPSprite (psp, i, camera, psp->sx + ofsx, psp->sy + ofsy); } // [RH] Don't bob the targeter. if (i == ps_flash) diff --git a/src/r_things.h b/src/r_things.h index 17b9d9845..5723a5737 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -112,9 +112,9 @@ extern fixed_t spryscale; extern fixed_t sprtopscreen; extern bool sprflipvert; -extern fixed_t pspritexscale; -extern fixed_t pspriteyscale; -extern fixed_t pspritexiscale; +extern double pspritexscale; +extern double pspritexiscale; +extern double pspriteyscale; extern FTexture *WallSpriteTile; From 3ef5a678d5176fe926717732b44ca8d21a36d31f Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 15 Apr 2016 20:30:05 -0500 Subject: [PATCH 07/12] Renderer floatification: Use floating point for texturemids and Y scales --- src/r_bsp.h | 4 +- src/r_draw.cpp | 2 +- src/r_draw.h | 2 +- src/r_drawt.cpp | 9 +-- src/r_plane.cpp | 41 +++++------- src/r_segs.cpp | 170 ++++++++++++++++++++++++----------------------- src/r_sky.cpp | 8 +-- src/r_sky.h | 2 +- src/r_things.cpp | 84 +++++++++++------------ src/r_things.h | 11 +-- src/v_draw.cpp | 21 ++---- src/xs_Float.h | 13 +++- 12 files changed, 185 insertions(+), 182 deletions(-) diff --git a/src/r_bsp.h b/src/r_bsp.h index 4c5f5f611..ba302c686 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -66,13 +66,13 @@ struct drawseg_t { seg_t* curline; float light, lightstep; - fixed_t iscale, iscalestep; + float iscale, iscalestep; short x1, x2; // Same as sx1 and sx2, but clipped to the drawseg short sx1, sx2; // left, right of parent seg on screen float sz1, sz2; // z for left, right of parent seg on screen float siz1, siz2; // 1/z for left, right of parent seg on screen float cx, cy, cdx, cdy; - fixed_t yrepeat; + float yscale; BYTE silhouette; // 0=none, 1=bottom, 2=top, 3=both BYTE bFogBoundary; BYTE bFakeBoundary; // for fake walls diff --git a/src/r_draw.cpp b/src/r_draw.cpp index a25770ebd..c58175912 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -86,6 +86,7 @@ void (*rt_map4cols)(int,int,int); // R_DrawColumn // Source is the top of the column to scale. // +double dc_texturemid; extern "C" { int dc_pitch=0xABadCafe; // [RH] Distance between rows @@ -94,7 +95,6 @@ int dc_x; int dc_yl; int dc_yh; fixed_t dc_iscale; -fixed_t dc_texturemid; fixed_t dc_texturefrac; int dc_color; // [RH] Color for column filler DWORD dc_srccolor; diff --git a/src/r_draw.h b/src/r_draw.h index 80dc77768..72b51dfa4 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -34,7 +34,7 @@ extern "C" int dc_x; extern "C" int dc_yl; extern "C" int dc_yh; extern "C" fixed_t dc_iscale; -extern "C" fixed_t dc_texturemid; +extern double dc_texturemid; extern "C" fixed_t dc_texturefrac; extern "C" int dc_color; // [RH] For flat colors (no texturing) extern "C" DWORD dc_srccolor; diff --git a/src/r_drawt.cpp b/src/r_drawt.cpp index d4b9d5f1e..e8faff0ce 100644 --- a/src/r_drawt.cpp +++ b/src/r_drawt.cpp @@ -1108,14 +1108,15 @@ void R_FillColumnHorizP (void) void R_DrawMaskedColumnHoriz (const BYTE *column, const FTexture::Span *span) { + const fixed_t texturemid = FLOAT2FIXED(dc_texturemid); while (span->Length != 0) { const int length = span->Length; const int top = span->TopOffset; // calculate unclipped screen coordinates for post - dc_yl = (sprtopscreen + spryscale * top) >> FRACBITS; - dc_yh = (sprtopscreen + spryscale * (top + length) - FRACUNIT) >> FRACBITS; + dc_yl = xs_RoundToInt(sprtopscreen + spryscale * top); + dc_yh = xs_RoundToInt(sprtopscreen + spryscale * (top + length) - 1); if (sprflipvert) { @@ -1136,7 +1137,7 @@ void R_DrawMaskedColumnHoriz (const BYTE *column, const FTexture::Span *span) if (sprflipvert) { dc_texturefrac = (dc_yl*dc_iscale) - (top << FRACBITS) - - fixed_t(CenterY * dc_iscale) - dc_texturemid; + - fixed_t(CenterY * dc_iscale) - texturemid; const fixed_t maxfrac = length << FRACBITS; while (dc_texturefrac >= maxfrac) { @@ -1154,7 +1155,7 @@ void R_DrawMaskedColumnHoriz (const BYTE *column, const FTexture::Span *span) } else { - dc_texturefrac = dc_texturemid - (top << FRACBITS) + dc_texturefrac = texturemid - (top << FRACBITS) + (dc_yl*dc_iscale) - fixed_t((CenterY-1) * dc_iscale); while (dc_texturefrac < 0) { diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 9390249cb..40fbba1f5 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -842,11 +842,11 @@ inline void R_MakeSpans (int x, int t1, int b1, int t2, int b2, void (*mapfunc)( static FTexture *frontskytex, *backskytex; static angle_t skyflip; static int frontpos, backpos; -static fixed_t frontyScale; +static double frontyScale; static fixed_t frontcyl, backcyl; -static fixed_t skymid; +static double skymid; static angle_t skyangle; -int frontiScale; +static double frontiScale; extern fixed_t swall[MAXWIDTH]; extern fixed_t lwall[MAXWIDTH]; @@ -947,8 +947,8 @@ static void R_DrawSky (visplane_t *pl) rw_pic = frontskytex; rw_offset = 0; - frontyScale = FLOAT2FIXED(rw_pic->Scale.Y); - dc_texturemid = MulScale16 (skymid, frontyScale); + frontyScale = rw_pic->Scale.Y; + dc_texturemid = skymid * frontyScale; if (1 << frontskytex->HeightBits == frontskytex->GetHeight()) { // The texture tiles nicely @@ -957,19 +957,19 @@ static void R_DrawSky (visplane_t *pl) lastskycol[x] = 0xffffffff; } wallscan (pl->left, pl->right, (short *)pl->top, (short *)pl->bottom, swall, lwall, - frontyScale, backskytex == NULL ? R_GetOneSkyColumn : R_GetTwoSkyColumns); + FLOAT2FIXED(frontyScale), backskytex == NULL ? R_GetOneSkyColumn : R_GetTwoSkyColumns); } else { // The texture does not tile nicely - frontyScale = DivScale16 (skyscale, frontyScale); - frontiScale = DivScale32 (1, frontyScale); + frontyScale *= skyscale; + frontiScale = 1 / frontyScale; // Sodding crap. Fixed point sucks when you want precision. // TODO (if I'm feeling adventurous): Rewrite the renderer to use floating point // coordinates to keep as much precision as possible until the final // rasterization stage so fudges like this aren't needed. if (viewheight <= 600) { - skymid -= FRACUNIT; + skymid -= 1; } R_DrawSkyStriped (pl); } @@ -977,22 +977,18 @@ static void R_DrawSky (visplane_t *pl) static void R_DrawSkyStriped (visplane_t *pl) { - double centerysave = CenterY; - short drawheight = (short)MulScale16 (frontskytex->GetHeight(), frontyScale); - fixed_t topfrac; - fixed_t iscale = frontiScale; + short drawheight = short(frontskytex->GetHeight() * frontyScale); + double topfrac; + double iscale = frontiScale; short top[MAXWIDTH], bot[MAXWIDTH]; short yl, yh; int x; - // So that I don't have to worry about fractional precision, chop off the - // fractional part of centeryfrac. - CenterY = centery; - topfrac = (skymid + iscale * (1-centery)) % (frontskytex->GetHeight() << FRACBITS); - if (topfrac < 0) topfrac += frontskytex->GetHeight() << FRACBITS; + topfrac = fmod(skymid + iscale * (1 - CenterY), frontskytex->GetHeight()); + if (topfrac < 0) topfrac += frontskytex->GetHeight(); yl = 0; - yh = (short)MulScale32 ((frontskytex->GetHeight() << FRACBITS) - topfrac, frontyScale); - dc_texturemid = topfrac - iscale * (1-centery); + yh = short((frontskytex->GetHeight() - topfrac) * frontyScale); + dc_texturemid = topfrac - iscale * (1 - CenterY); fixed_t yScale = FLOAT2FIXED(rw_pic->Scale.Y); while (yl < viewheight) @@ -1012,7 +1008,6 @@ static void R_DrawSkyStriped (visplane_t *pl) yh += drawheight; dc_texturemid = iscale * (centery-yl-1); } - CenterY = centerysave; } //========================================================================== @@ -1461,7 +1456,7 @@ void R_DrawSkyPlane (visplane_t *pl) skyangle += s->GetTextureXOffset(pos); // Vertical offset allows careful sky positioning. - skymid = s->GetTextureYOffset(pos) - 28*FRACUNIT; + skymid = s->GetTextureYOffsetF(pos) - 28; // We sometimes flip the picture horizontally. // @@ -1474,7 +1469,7 @@ void R_DrawSkyPlane (visplane_t *pl) frontcyl = MAX(frontskytex->GetWidth(), frontxscale); if (skystretch) { - skymid = Scale(skymid, frontskytex->GetScaledHeight(), SKYSTRETCH_HEIGHT); + skymid = skymid * frontskytex->GetScaledHeightDouble() / SKYSTRETCH_HEIGHT; } } } diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 9ffd82b8b..c979a6b87 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -119,10 +119,10 @@ static double rw_frontlowertop; static int rw_x; static int rw_stopx; fixed_t rw_offset; -static fixed_t rw_scalestep; -static fixed_t rw_midtexturemid; -static fixed_t rw_toptexturemid; -static fixed_t rw_bottomtexturemid; +static double rw_scalestep; +static double rw_midtexturemid; +static double rw_toptexturemid; +static double rw_bottomtexturemid; static double rw_midtexturescalex; static double rw_midtexturescaley; static double rw_toptexturescalex; @@ -170,7 +170,7 @@ CVAR(Bool, r_drawmirrors, true, 0) // R_RenderMaskedSegRange // fixed_t *MaskedSWall; -fixed_t MaskedScaleY; +double MaskedScaleY; static void BlastMaskedColumn (void (*blastfunc)(const BYTE *pixels, const FTexture::Span *spans), FTexture *tex) { @@ -180,11 +180,11 @@ static void BlastMaskedColumn (void (*blastfunc)(const BYTE *pixels, const FText dc_colormap = basecolormap->Maps + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); } - dc_iscale = MulScale18 (MaskedSWall[dc_x], MaskedScaleY); + dc_iscale = xs_RoundToInt(MaskedSWall[dc_x] * MaskedScaleY); if (sprflipvert) - sprtopscreen = FLOAT2FIXED(CenterY) + FixedMul(dc_texturemid, spryscale); + sprtopscreen = CenterY + dc_texturemid * spryscale; else - sprtopscreen = FLOAT2FIXED(CenterY) - FixedMul(dc_texturemid, spryscale); + sprtopscreen = CenterY - dc_texturemid * spryscale; // killough 1/25/98: here's where Medusa came in, because // it implicitly assumed that the column was all one patch. @@ -230,7 +230,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) sector_t tempsec; // killough 4/13/98 double texheight, texheightscale; bool notrelevant = false; - fixed_t rowoffset; + double rowoffset; const sector_t *sec; @@ -306,7 +306,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) } MaskedSWall = (fixed_t *)(openings + ds->swall) - ds->x1; - MaskedScaleY = ds->yrepeat; + MaskedScaleY = ds->yscale; maskedtexturecol = (fixed_t *)(openings + ds->maskedtexturecol) - ds->x1; spryscale = ds->iscale + ds->iscalestep * (x1 - ds->x1); rw_scalestep = ds->iscalestep; @@ -325,14 +325,14 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) } if (curline->linedef->flags & ML_DONTPEGBOTTOM) { - dc_texturemid = FLOAT2FIXED(MAX(frontsector->GetPlaneTexZF(sector_t::floor), backsector->GetPlaneTexZF(sector_t::floor)) + texheight); + dc_texturemid = MAX(frontsector->GetPlaneTexZF(sector_t::floor), backsector->GetPlaneTexZF(sector_t::floor)) + texheight; } else { - dc_texturemid = FLOAT2FIXED(MIN(frontsector->GetPlaneTexZF(sector_t::ceiling), backsector->GetPlaneTexZF(sector_t::ceiling))); + dc_texturemid = MIN(frontsector->GetPlaneTexZF(sector_t::ceiling), backsector->GetPlaneTexZF(sector_t::ceiling)); } - rowoffset = curline->sidedef->GetTextureYOffset(side_t::mid); + rowoffset = curline->sidedef->GetTextureYOffsetF(side_t::mid); if (!(curline->linedef->flags & ML_WRAP_MIDTEX) && !(curline->sidedef->Flags & WALLF_WRAP_MIDTEX)) @@ -346,18 +346,18 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) } if (tex->bWorldPanning) { - // rowoffset is added before the MulScale3 so that the masked texture will + // rowoffset is added before the multiply so that the masked texture will // still be positioned in world units rather than texels. - dc_texturemid += rowoffset - FLOAT2FIXED(ViewPos.Z); - textop = FIXED2FLOAT(dc_texturemid); - dc_texturemid = MulScale16 (dc_texturemid, MaskedScaleY); + dc_texturemid += rowoffset - ViewPos.Z; + textop = dc_texturemid; + dc_texturemid *= MaskedScaleY; } else { // rowoffset is added outside the multiply so that it positions the texture // by texels instead of world units. - textop = FIXED2FLOAT(dc_texturemid + SafeDivScale16 (rowoffset, MaskedScaleY)) - ViewPos.Z; - dc_texturemid = MulScale16 (dc_texturemid - FLOAT2FIXED(ViewPos.Z), MaskedScaleY) + rowoffset; + textop = dc_texturemid + rowoffset / MaskedScaleY - ViewPos.Z; + dc_texturemid = (dc_texturemid - ViewPos.Z) * MaskedScaleY + rowoffset; } if (sprflipvert) { @@ -433,6 +433,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) mfloorclip = walllower; mceilingclip = wallupper; + MaskedScaleY /= 4; // [RH] Wish I could remember why this needs to be done // draw the columns one at a time if (drawmode == DoDraw0) @@ -480,16 +481,15 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) { // Texture does wrap vertically. if (tex->bWorldPanning) { - // rowoffset is added before the MulScale3 so that the masked texture will + // rowoffset is added before the multiply so that the masked texture will // still be positioned in world units rather than texels. - dc_texturemid += rowoffset - FLOAT2FIXED(ViewPos.Z); - dc_texturemid = MulScale16 (dc_texturemid, MaskedScaleY); + dc_texturemid = (dc_texturemid + rowoffset - ViewPos.Z) * MaskedScaleY; } else { // rowoffset is added outside the multiply so that it positions the texture // by texels instead of world units. - dc_texturemid = MulScale16 (dc_texturemid - FLOAT2FIXED(ViewPos.Z), MaskedScaleY) + rowoffset; + dc_texturemid = (dc_texturemid - ViewPos.Z) * MaskedScaleY + rowoffset; } WallC.sz1 = ds->sz1; @@ -531,7 +531,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) rw_offset = 0; rw_pic = tex; - wallscan_np2_ds(ds, x1, x2, mceilingclip, mfloorclip, MaskedSWall, maskedtexturecol, ds->yrepeat); + wallscan_np2_ds(ds, x1, x2, mceilingclip, mfloorclip, MaskedSWall, maskedtexturecol, FLOAT2FIXED(ds->yscale)); } clearfog: @@ -601,23 +601,23 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover) scaledpart = side_t::mid; } xscale = fixed_t(rw_pic->Scale.X * scaledside->GetTextureXScale(scaledpart)); - yscale = rw_pic->Scale.Y * scaledside->GetTextureYScale(scaledpart); + yscale = rw_pic->Scale.Y * scaledside->GetTextureYScaleF(scaledpart); - fixed_t rowoffset = curline->sidedef->GetTextureYOffset(side_t::mid) + rover->master->sidedef[0]->GetTextureYOffset(side_t::mid); + double rowoffset = curline->sidedef->GetTextureYOffsetF(side_t::mid) + rover->master->sidedef[0]->GetTextureYOffsetF(side_t::mid); double planez = rover->model->GetPlaneTexZF(sector_t::ceiling); rw_offset = curline->sidedef->GetTextureXOffset(side_t::mid) + rover->master->sidedef[0]->GetTextureXOffset(side_t::mid); if (rowoffset < 0) { - rowoffset += rw_pic->GetHeight() << FRACBITS; + rowoffset += rw_pic->GetHeight(); } - dc_texturemid = FLOAT2FIXED((planez - ViewPos.Z) * yscale); + dc_texturemid = (planez - ViewPos.Z) * yscale; if (rw_pic->bWorldPanning) { - // rowoffset is added before the MulScale3 so that the masked texture will + // rowoffset is added before the multiply so that the masked texture will // still be positioned in world units rather than texels. - dc_texturemid += xs_FloorToInt(rowoffset * yscale); - rw_offset = MulScale16 (rw_offset, xscale); ///Is this really supposed to be xscale and not yscale? + dc_texturemid = dc_texturemid + rowoffset * yscale; + rw_offset = MulScale16 (rw_offset, xscale); } else { @@ -1101,7 +1101,7 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t shiftval = rw_pic->HeightBits; setupvline (32-shiftval); yrepeat >>= 2 + shiftval; - texturemid = dc_texturemid << (16 - shiftval); + texturemid = xs_ToFixed(32 - shiftval, dc_texturemid); xoffset = rw_offset; basecolormapdata = basecolormap->Maps; fixed_t centeryfrac = FLOAT2FIXED(CenterY); @@ -1317,32 +1317,33 @@ 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 itop, fixed_t ibot, bool mask) +void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrep, fixed_t itop, fixed_t ibot, bool mask) { if (!r_np2) { - call_wallscan(x1, x2, uwal, dwal, swal, lwal, yrepeat, mask); + call_wallscan(x1, x2, uwal, dwal, swal, lwal, yrep, mask); } else { short most1[MAXWIDTH], most2[MAXWIDTH], most3[MAXWIDTH]; short *up, *down; - fixed_t texheight = rw_pic->GetHeight() << FRACBITS; - double scaledtexheight = FIXED2FLOAT(FixedDiv(texheight, yrepeat)); + double texheight = rw_pic->GetHeight(); double partition; double top = FIXED2FLOAT(itop); double bot = FIXED2FLOAT(ibot); + double yrepeat = FIXED2FLOAT(yrep); + double scaledtexheight = texheight / yrepeat; if (yrepeat >= 0) { // normal orientation: draw strips from top to bottom - partition = top - fmod(top - FIXED2FLOAT(FixedDiv(dc_texturemid, yrepeat)) - ViewPos.Z, scaledtexheight); + partition = top - fmod(top - dc_texturemid / yrepeat - ViewPos.Z, scaledtexheight); if (partition == top) { partition -= scaledtexheight; } up = uwal; down = most1; - dc_texturemid = xs_RoundToInt((partition - ViewPos.Z) * yrepeat + texheight); + dc_texturemid = (partition - ViewPos.Z) * yrepeat + texheight; while (partition > bot) { int j = OWallMost(most3, partition - ViewPos.Z, &WallC); @@ -1352,21 +1353,21 @@ void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed { down[j] = clamp(most3[j], up[j], dwal[j]); } - call_wallscan(x1, x2, up, down, swal, lwal, yrepeat, mask); + call_wallscan(x1, x2, up, down, swal, lwal, yrep, mask); up = down; down = (down == most1) ? most2 : most1; } partition -= scaledtexheight; dc_texturemid -= texheight; } - call_wallscan(x1, x2, up, dwal, swal, lwal, yrepeat, mask); + call_wallscan(x1, x2, up, dwal, swal, lwal, yrep, mask); } else { // upside down: draw strips from bottom to top - partition = bot - fmod(bot - FIXED2FLOAT(FixedDiv(dc_texturemid, yrepeat)) - ViewPos.Z, scaledtexheight); + partition = bot - fmod(bot - dc_texturemid / yrepeat - ViewPos.Z, scaledtexheight); up = most1; down = dwal; - dc_texturemid = xs_RoundToInt((partition - ViewPos.Z) * yrepeat + texheight); + dc_texturemid = (partition - ViewPos.Z) * yrepeat + texheight; while (partition < top) { int j = OWallMost(most3, partition - ViewPos.Z, &WallC); @@ -1376,14 +1377,14 @@ void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed { up[j] = clamp(most3[j], uwal[j], down[j]); } - call_wallscan(x1, x2, up, down, swal, lwal, yrepeat, mask); + call_wallscan(x1, x2, up, down, swal, lwal, yrep, mask); down = up; up = (up == most1) ? most2 : most1; } partition -= scaledtexheight; dc_texturemid -= texheight; } - call_wallscan(x1, x2, uwal, down, swal, lwal, yrepeat, mask); + call_wallscan(x1, x2, uwal, down, swal, lwal, yrep, mask); } } } @@ -1454,7 +1455,7 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe shiftval = rw_pic->HeightBits; setupmvline (32-shiftval); yrepeat >>= 2 + shiftval; - texturemid = dc_texturemid << (16 - shiftval); + texturemid = xs_ToFixed(32 - shiftval, dc_texturemid); xoffset = rw_offset; basecolormapdata = basecolormap->Maps; fixed_t centeryfrac = FLOAT2FIXED(CenterY); @@ -1628,7 +1629,7 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, shiftval = rw_pic->HeightBits; setuptmvline (32-shiftval); yrepeat >>= 2 + shiftval; - texturemid = dc_texturemid << (16 - shiftval); + texturemid = xs_ToFixed(32 - shiftval, dc_texturemid); xoffset = rw_offset; basecolormapdata = basecolormap->Maps; fixed_t centeryfrac = FLOAT2FIXED(CenterY); @@ -1997,7 +1998,7 @@ void R_RenderSegLoop () void R_NewWall (bool needlights) { - fixed_t rowoffset; + double rowoffset; double yrepeat; rw_markportal = false; @@ -2026,7 +2027,7 @@ void R_NewWall (bool needlights) { midtexture = TexMan(sidedef->GetTexture(side_t::mid), true); rw_offset_mid = sidedef->GetTextureXOffset(side_t::mid); - rowoffset = sidedef->GetTextureYOffset(side_t::mid); + rowoffset = sidedef->GetTextureYOffsetF(side_t::mid); rw_midtexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::mid)); rw_midtexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::mid)); yrepeat = midtexture->Scale.Y * rw_midtexturescaley; @@ -2034,14 +2035,14 @@ void R_NewWall (bool needlights) { // normal orientation if (linedef->flags & ML_DONTPEGBOTTOM) { // bottom of texture at bottom - rw_midtexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::floor) - ViewPos.Z) * yrepeat + midtexture->GetHeight()); + rw_midtexturemid = (frontsector->GetPlaneTexZF(sector_t::floor) - ViewPos.Z) * yrepeat + midtexture->GetHeight(); } else { // top of texture at top - rw_midtexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat); + rw_midtexturemid = (frontsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat; if (rowoffset < 0 && midtexture != NULL) { - rowoffset += midtexture->GetHeight() << FRACBITS; + rowoffset += midtexture->GetHeight(); } } } @@ -2050,16 +2051,16 @@ void R_NewWall (bool needlights) rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGBOTTOM) { // top of texture at bottom - rw_midtexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::floor) - ViewPos.Z) * yrepeat); + rw_midtexturemid = (frontsector->GetPlaneTexZF(sector_t::floor) - ViewPos.Z) * yrepeat; } else { // bottom of texture at top - rw_midtexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZ(sector_t::ceiling) - ViewPos.Z) * yrepeat + midtexture->GetHeight()); + rw_midtexturemid = (frontsector->GetPlaneTexZ(sector_t::ceiling) - ViewPos.Z) * yrepeat + midtexture->GetHeight(); } } if (midtexture->bWorldPanning) { - rw_midtexturemid += xs_FloorToInt(rowoffset * yrepeat); + rw_midtexturemid += rowoffset * yrepeat; } else { @@ -2181,7 +2182,7 @@ void R_NewWall (bool needlights) toptexture = TexMan(sidedef->GetTexture(side_t::top), true); rw_offset_top = sidedef->GetTextureXOffset(side_t::top); - rowoffset = sidedef->GetTextureYOffset(side_t::top); + rowoffset = sidedef->GetTextureYOffsetF(side_t::top); rw_toptexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::top)); rw_toptexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::top)); yrepeat = toptexture->Scale.Y * rw_toptexturescaley; @@ -2189,15 +2190,15 @@ void R_NewWall (bool needlights) { // normal orientation if (linedef->flags & ML_DONTPEGTOP) { // top of texture at top - rw_toptexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat); + rw_toptexturemid = (frontsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat; if (rowoffset < 0 && toptexture != NULL) { - rowoffset += toptexture->GetHeight() << FRACBITS; + rowoffset += toptexture->GetHeight(); } } else { // bottom of texture at bottom - rw_toptexturemid = FLOAT2FIXED((backsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat + toptexture->GetHeight()); + rw_toptexturemid = (backsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat + toptexture->GetHeight(); } } else @@ -2205,16 +2206,16 @@ void R_NewWall (bool needlights) rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGTOP) { // bottom of texture at top - rw_toptexturemid = FLOAT2FIXED((frontsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat + toptexture->GetHeight()); + rw_toptexturemid = (frontsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat + toptexture->GetHeight(); } else { // top of texture at bottom - rw_toptexturemid = FLOAT2FIXED((backsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat); + rw_toptexturemid = (backsector->GetPlaneTexZF(sector_t::ceiling) - ViewPos.Z) * yrepeat; } } if (toptexture->bWorldPanning) { - rw_toptexturemid += xs_FloorToInt(rowoffset * yrepeat); + rw_toptexturemid += rowoffset * yrepeat; } else { @@ -2226,7 +2227,7 @@ void R_NewWall (bool needlights) bottomtexture = TexMan(sidedef->GetTexture(side_t::bottom), true); rw_offset_bottom = sidedef->GetTextureXOffset(side_t::bottom); - rowoffset = sidedef->GetTextureYOffset(side_t::bottom); + rowoffset = sidedef->GetTextureYOffsetF(side_t::bottom); rw_bottomtexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::bottom)); rw_bottomtexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::bottom)); yrepeat = fixed_t(bottomtexture->Scale.Y * rw_bottomtexturescaley); @@ -2234,14 +2235,14 @@ void R_NewWall (bool needlights) { // normal orientation if (linedef->flags & ML_DONTPEGBOTTOM) { // bottom of texture at bottom - rw_bottomtexturemid = FLOAT2FIXED((rw_frontlowertop - ViewPos.Z) * yrepeat); + rw_bottomtexturemid = (rw_frontlowertop - ViewPos.Z) * yrepeat; } else { // top of texture at top - rw_bottomtexturemid = FLOAT2FIXED((backsector->GetPlaneTexZF(sector_t::floor) - ViewPos.Z) * yrepeat); + rw_bottomtexturemid = (backsector->GetPlaneTexZF(sector_t::floor) - ViewPos.Z) * yrepeat; if (rowoffset < 0 && bottomtexture != NULL) { - rowoffset += bottomtexture->GetHeight() << FRACBITS; + rowoffset += bottomtexture->GetHeight(); } } } @@ -2250,16 +2251,16 @@ void R_NewWall (bool needlights) rowoffset = -rowoffset; if (linedef->flags & ML_DONTPEGBOTTOM) { // top of texture at bottom - rw_bottomtexturemid = FLOAT2FIXED((rw_frontlowertop - ViewPos.Z) * yrepeat); + rw_bottomtexturemid = (rw_frontlowertop - ViewPos.Z) * yrepeat; } else { // bottom of texture at top - rw_bottomtexturemid = FLOAT2FIXED((backsector->GetPlaneTexZ(sector_t::floor) - ViewPos.Z) * yrepeat + bottomtexture->GetHeight()); + rw_bottomtexturemid = (backsector->GetPlaneTexZ(sector_t::floor) - ViewPos.Z) * yrepeat + bottomtexture->GetHeight(); } } if (bottomtexture->bWorldPanning) { - rw_bottomtexturemid += xs_FloorToInt(rowoffset * yrepeat); + rw_bottomtexturemid += rowoffset * yrepeat; } else { @@ -2515,7 +2516,7 @@ void R_StoreWallRange (int start, int stop) lwal = (fixed_t *)(openings + ds_p->maskedtexturecol); swal = (fixed_t *)(openings + ds_p->swall); FTexture *pic = TexMan(sidedef->GetTexture(side_t::mid), true); - fixed_t yrepeat = int(pic->Scale.X * sidedef->GetTextureYScale(side_t::mid)); + double yscale = pic->Scale.X * sidedef->GetTextureYScaleF(side_t::mid); fixed_t xoffset = sidedef->GetTextureXOffset(side_t::mid); if (pic->bWorldPanning) @@ -2529,20 +2530,23 @@ void R_StoreWallRange (int start, int stop) *swal++ = swall[i]; } - fixed_t istart = MulScale18 (*((fixed_t *)(openings + ds_p->swall)), yrepeat); - fixed_t iend = MulScale18 (*(swal - 1), yrepeat); - - if (istart < 3 && istart >= 0) istart = 3; - if (istart > -3 && istart < 0) istart = -3; - if (iend < 3 && iend >= 0) iend = 3; - if (iend > -3 && iend < 0) iend = -3; - istart = DivScale32 (1, istart); - iend = DivScale32 (1, iend); - ds_p->yrepeat = yrepeat; - ds_p->iscale = istart; + double istart = *((fixed_t *)(openings + ds_p->swall)) * yscale / (1 << 18); + double iend = *(swal - 1) * yscale / (1 << 18); +#if 0 + ///This was for avoiding overflow when using fixed point. It might not be needed anymore. + const double mini = 3 / 65536.0; + if (istart < mini && istart >= 0) istart = mini; + if (istart > -mini && istart < 0) istart = -mini; + if (iend < mini && iend >= 0) iend = mini; + if (iend > -mini && iend < 0) iend = -mini; +#endif + istart = 1 / istart; + iend = 1 / iend; + ds_p->yscale = (float)yscale; + ds_p->iscale = (float)istart; if (stop - start > 0) { - ds_p->iscalestep = (iend - istart) / (stop - start); + ds_p->iscalestep = float((iend - istart) / (stop - start)); } else { @@ -3182,7 +3186,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, } topoff = WallSpriteTile->TopOffset << FRACBITS; - dc_texturemid = topoff + xs_ToInt((zpos - ViewPos.Z) * 65536 / yscale); + dc_texturemid = topoff + (zpos - ViewPos.Z) / yscale; // Clip sprite to drawseg x1 = MAX(clipper->x1, x1); @@ -3232,7 +3236,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, { sprflipvert = true; yscale = -yscale; - dc_texturemid = dc_texturemid - (WallSpriteTile->GetHeight() << FRACBITS); + dc_texturemid -= WallSpriteTile->GetHeight(); } else { diff --git a/src/r_sky.cpp b/src/r_sky.cpp index f3bdbed35..727d0bbbf 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -40,7 +40,7 @@ // FTextureID skyflatnum; FTextureID sky1texture, sky2texture; -fixed_t skytexturemid; +double skytexturemid; fixed_t skyscale; fixed_t skyiscale; bool skystretch; @@ -103,11 +103,11 @@ void R_InitSkyMap () && skyheight >= 128 && level.IsFreelookAllowed() && !(level.flags & LEVEL_FORCENOSKYSTRETCH)) ? 1 : 0; - skytexturemid = -28*FRACUNIT; + skytexturemid = -28; } else if (skyheight > 200) { - skytexturemid = FLOAT2FIXED((200 - skyheight) * skytex1->Scale.Y); + skytexturemid = (200 - skyheight) * skytex1->Scale.Y; } if (viewwidth != 0 && viewheight != 0) @@ -124,7 +124,7 @@ void R_InitSkyMap () { skyscale = Scale(skyscale, SKYSTRETCH_HEIGHT, skyheight); skyiscale = Scale(skyiscale, skyheight, SKYSTRETCH_HEIGHT); - skytexturemid = Scale(skytexturemid, skyheight, SKYSTRETCH_HEIGHT); + skytexturemid = skytexturemid * skyheight / SKYSTRETCH_HEIGHT; } // The standard Doom sky texture is 256 pixels wide, repeated 4 times over 360 degrees, diff --git a/src/r_sky.h b/src/r_sky.h index 6b9df2f14..30b106185 100644 --- a/src/r_sky.h +++ b/src/r_sky.h @@ -29,7 +29,7 @@ extern FTextureID skyflatnum; extern fixed_t sky1cyl, sky2cyl; extern FTextureID sky1texture, sky2texture; extern double sky1pos, sky2pos; -extern fixed_t skytexturemid; +extern double skytexturemid; extern fixed_t skyiscale; extern fixed_t skyscale; extern bool skystretch; diff --git a/src/r_things.cpp b/src/r_things.cpp index ec9822a71..60ae7213b 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -237,22 +237,23 @@ vissprite_t *R_NewVisSprite (void) short* mfloorclip; short* mceilingclip; -fixed_t spryscale; -fixed_t sprtopscreen; +double spryscale; +double sprtopscreen; bool sprflipvert; void R_DrawMaskedColumn (const BYTE *column, const FTexture::Span *span) { - fixed_t centeryfrac = FLOAT2FIXED(CenterY); + const fixed_t centeryfrac = FLOAT2FIXED(CenterY); + const fixed_t texturemid = FLOAT2FIXED(dc_texturemid); while (span->Length != 0) { const int length = span->Length; const int top = span->TopOffset; // calculate unclipped screen coordinates for post - dc_yl = (sprtopscreen + spryscale * top) >> FRACBITS; - dc_yh = (sprtopscreen + spryscale * (top + length) - FRACUNIT) >> FRACBITS; + dc_yl = xs_RoundToInt(sprtopscreen + spryscale * top); + dc_yh = xs_RoundToInt(sprtopscreen + spryscale * (top + length)) - 1; if (sprflipvert) { @@ -273,7 +274,7 @@ void R_DrawMaskedColumn (const BYTE *column, const FTexture::Span *span) if (sprflipvert) { dc_texturefrac = (dc_yl*dc_iscale) - (top << FRACBITS) - - FixedMul (centeryfrac, dc_iscale) - dc_texturemid; + - FixedMul (centeryfrac, dc_iscale) - texturemid; const fixed_t maxfrac = length << FRACBITS; while (dc_texturefrac >= maxfrac) { @@ -291,7 +292,7 @@ void R_DrawMaskedColumn (const BYTE *column, const FTexture::Span *span) } else { - dc_texturefrac = dc_texturemid - (top << FRACBITS) + dc_texturefrac = texturemid - (top << FRACBITS) + (dc_yl*dc_iscale) - FixedMul (centeryfrac-FRACUNIT, dc_iscale); while (dc_texturefrac < 0) { @@ -433,24 +434,23 @@ void R_DrawVisSprite (vissprite_t *vis) tex = vis->pic; spryscale = vis->yscale; sprflipvert = false; - dc_iscale = 0xffffffffu / (unsigned)vis->yscale; + dc_iscale = FLOAT2FIXED(1 / vis->yscale); frac = vis->startfrac; xiscale = vis->xiscale; dc_texturemid = vis->texturemid; - if (vis->renderflags & RF_YFLIP) { sprflipvert = true; spryscale = -spryscale; dc_iscale = -dc_iscale; - dc_texturemid -= (vis->pic->GetHeight() << FRACBITS); - sprtopscreen = centeryfrac + FixedMul(dc_texturemid, spryscale); + dc_texturemid -= vis->pic->GetHeight(); + sprtopscreen = CenterY + dc_texturemid * spryscale; } else { sprflipvert = false; - sprtopscreen = centeryfrac - FixedMul(dc_texturemid, spryscale); + sprtopscreen = CenterY - dc_texturemid * spryscale; } dc_x = vis->x1; @@ -500,7 +500,7 @@ void R_DrawVisSprite (vissprite_t *vis) void R_DrawWallSprite(vissprite_t *spr) { int x1, x2; - fixed_t yscale; + double iyscale; x1 = MAX(spr->x1, spr->wallc.sx1); x2 = MIN(spr->x2, spr->wallc.sx2); @@ -508,8 +508,8 @@ void R_DrawWallSprite(vissprite_t *spr) return; WallT.InitFromWallCoords(&spr->wallc); PrepWall(swall, lwall, spr->pic->GetWidth() << FRACBITS, x1, x2); - yscale = spr->yscale; - dc_texturemid = FixedDiv(FLOAT2FIXED(spr->gzt - ViewPos.Z), yscale); + iyscale = 1 / spr->yscale; + dc_texturemid = (spr->gzt - ViewPos.Z) * iyscale; if (spr->renderflags & RF_XFLIP) { int right = (spr->pic->GetWidth() << FRACBITS) - 1; @@ -550,8 +550,8 @@ void R_DrawWallSprite(vissprite_t *spr) if (spr->renderflags & RF_YFLIP) { sprflipvert = true; - yscale = -yscale; - dc_texturemid = dc_texturemid - (spr->pic->GetHeight() << FRACBITS); + iyscale = -iyscale; + dc_texturemid -= spr->pic->GetHeight(); } else { @@ -559,7 +559,7 @@ void R_DrawWallSprite(vissprite_t *spr) } // rw_offset is used as the texture's vertical scale - rw_offset = SafeDivScale30(1, yscale); + rw_offset = xs_Fix<30>::ToFix(iyscale); dc_x = x1; ESPSResult mode; @@ -636,9 +636,9 @@ void R_WallSpriteColumn (void (*drawfunc)(const BYTE *column, const FTexture::Sp dc_iscale = MulScale16 (swall[dc_x], rw_offset); spryscale = SafeDivScale32 (1, dc_iscale); if (sprflipvert) - sprtopscreen = FLOAT2FIXED(CenterY) + FixedMul (dc_texturemid, spryscale); + sprtopscreen = CenterY + dc_texturemid * spryscale; else - sprtopscreen = FLOAT2FIXED(CenterY) - FixedMul (dc_texturemid, spryscale); + sprtopscreen = CenterY - dc_texturemid * spryscale; const BYTE *column; const FTexture::Span *spans; @@ -680,7 +680,7 @@ void R_DrawVisVoxel(vissprite_t *spr, int minslabz, int maxslabz, short *cliptop // Render the voxel, either directly to the screen or offscreen. R_DrawVoxel(spr->vpos, spr->vang, spr->gpos, spr->angle, - spr->xscale, spr->yscale, spr->voxel, spr->Style.colormap, cliptop, clipbot, + spr->xscale, FLOAT2FIXED(spr->yscale), spr->voxel, spr->Style.colormap, cliptop, clipbot, minslabz, maxslabz, flags); // Blend the voxel, if that's what we need to do. @@ -982,17 +982,17 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor xscale = spriteScale.X * xscale / tex->Scale.X; iscale = (tex->GetWidth() << FRACBITS) / (x2 - x1); - fixed_t yscale = FLOAT2FIXED(spriteScale.Y / tex->Scale.Y); + double yscale = spriteScale.Y / tex->Scale.Y; // store information in a vissprite vis = R_NewVisSprite(); vis->CurrentPortalUniq = CurrentPortalUniq; vis->xscale = FLOAT2FIXED(xscale); - vis->yscale = fixed_t(InvZtoScale * yscale / tz); + vis->yscale = float(InvZtoScale * yscale / tz); vis->idepth = float(1 / tz); - vis->floorclip = FixedDiv (FLOAT2FIXED(thing->Floorclip), yscale); - vis->texturemid = (tex->TopOffset << FRACBITS) - FixedDiv(FLOAT2FIXED(ViewPos.Z - pos.Z + thing->Floorclip), yscale); + vis->floorclip = thing->Floorclip / yscale; + vis->texturemid = tex->TopOffset - (ViewPos.Z - pos.Z + thing->Floorclip) / yscale; vis->x1 = x1 < WindowLeft ? WindowLeft : x1; vis->x2 = x2 > WindowRight ? WindowRight : x2; vis->angle = thing->Angles.Yaw.BAMs(); @@ -1017,11 +1017,11 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor vis->CurrentPortalUniq = CurrentPortalUniq; vis->xscale = FLOAT2FIXED(xscale); - vis->yscale = FLOAT2FIXED(yscale); + vis->yscale = (float)yscale; vis->x1 = WindowLeft; vis->x2 = WindowRight; vis->idepth = 1 / MINZ; - vis->floorclip = FLOAT2FIXED(thing->Floorclip); + vis->floorclip = thing->Floorclip; pos.Z -= thing->Floorclip; @@ -1179,7 +1179,7 @@ static void R_ProjectWallSprite(AActor *thing, const DVector3 &pos, FTextureID p vis->CurrentPortalUniq = CurrentPortalUniq; vis->x1 = wallc.sx1 < WindowLeft ? WindowLeft : wallc.sx1; vis->x2 = wallc.sx2 >= WindowRight ? WindowRight : wallc.sx2; - vis->yscale = FLOAT2FIXED(scale.Y); + vis->yscale = (float)scale.Y; vis->idepth = float(1 / tz); vis->depth = (float)tz; vis->sector = thing->Sector; @@ -1334,7 +1334,7 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, double sx, double vis->renderflags = owner->renderflags; vis->floorclip = 0; - vis->texturemid = FLOAT2FIXED((BASEYCENTER - sy) * tex->Scale.Y + tex->TopOffset); + vis->texturemid = (BASEYCENTER - sy) * tex->Scale.Y + tex->TopOffset; if (camera->player && (RenderTarget != screen || viewheight == RenderTarget->GetHeight() || @@ -1349,11 +1349,11 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, double sx, double { if (RenderTarget != screen || viewheight == RenderTarget->GetHeight()) { - vis->texturemid -= FLOAT2FIXED(weapon->YAdjust); + vis->texturemid -= weapon->YAdjust; } else { - vis->texturemid -= FLOAT2FIXED(StatusBar->GetDisplacement () * weapon->YAdjust); + vis->texturemid -= StatusBar->GetDisplacement () * weapon->YAdjust; } } } @@ -1364,7 +1364,7 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, double sx, double vis->x1 = x1 < 0 ? 0 : x1; vis->x2 = x2 >= viewwidth ? viewwidth : x2; vis->xscale = FLOAT2FIXED(pspritexscale / tex->Scale.X); - vis->yscale = FLOAT2FIXED(pspriteyscale / tex->Scale.Y); + vis->yscale = float(pspriteyscale / tex->Scale.Y); vis->Translation = 0; // [RH] Use default colors vis->pic = tex; vis->ColormapNum = 0; @@ -1655,9 +1655,9 @@ void R_DrawRemainingPlayerSprites() } screen->DrawTexture(vis->pic, viewwindowx + VisPSpritesX1[i], - viewwindowy + viewheight/2 - (vis->texturemid / 65536.0) * (vis->yscale / 65536.0) - 0.5, + viewwindowy + viewheight/2 - vis->texturemid * vis->yscale - 0.5, DTA_DestWidthF, FIXED2DBL(vis->pic->GetWidth() * vis->xscale), - DTA_DestHeightF, FIXED2DBL(vis->pic->GetHeight() * vis->yscale), + DTA_DestHeightF, vis->pic->GetHeight() * vis->yscale, DTA_Translation, TranslationToTable(vis->Translation), DTA_FlipX, flip, DTA_TopOffset, 0, @@ -2075,12 +2075,11 @@ void R_DrawSprite (vissprite_t *spr) // killough 3/27/98: end special clipping for deep water / fake ceilings else if (!spr->bIsVoxel && spr->floorclip) { // [RH] Move floorclip stuff from R_DrawVisSprite to here - int clip = ((FLOAT2FIXED(CenterY) - FixedMul (spr->texturemid - - (spr->pic->GetHeight() << FRACBITS) + - spr->floorclip, spr->yscale)) >> FRACBITS); + //int clip = ((FLOAT2FIXED(CenterY) - FixedMul (spr->texturemid - (spr->pic->GetHeight() << FRACBITS) + spr->floorclip, spr->yscale)) >> FRACBITS); + int clip = xs_RoundToInt(CenterY - (spr->texturemid - spr->pic->GetHeight() + spr->floorclip) * spr->yscale); if (clip < botclip) { - botclip = MAX (0, clip); + botclip = MAX(0, clip); } } @@ -2295,8 +2294,8 @@ void R_DrawSprite (vissprite_t *spr) { clearbufshort(cliptop + x2, viewwidth - x2, viewheight); } - int minvoxely = spr->gzt <= hzt ? 0 : FLOAT2FIXED(spr->gzt - hzt) / spr->yscale; - int maxvoxely = spr->gzb > hzb ? INT_MAX : FLOAT2FIXED(spr->gzt - hzb) / spr->yscale; + int minvoxely = spr->gzt <= hzt ? 0 : xs_RoundToInt((spr->gzt - hzt) / spr->yscale); + int maxvoxely = spr->gzb > hzb ? INT_MAX : xs_RoundToInt((spr->gzt - hzb) / spr->yscale); R_DrawVisVoxel(spr, minvoxely, maxvoxely, cliptop, clipbot); } spr->Style.colormap = colormap; @@ -2526,8 +2525,9 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade, vis = R_NewVisSprite (); vis->CurrentPortalUniq = CurrentPortalUniq; vis->heightsec = heightsec; - vis->yscale = vis->xscale = FLOAT2FIXED(xscale); -// vis->yscale = FixedMul (xscale, InvZtoScale); + vis->xscale = FLOAT2FIXED(xscale); + vis->yscale = (float)xscale; +// vis->yscale *= InvZtoScale; vis->depth = (float)tz; vis->idepth = float(1 / tz); vis->gpos = { (float)particle->Pos.X, (float)particle->Pos.Y, (float)particle->Pos.Z }; diff --git a/src/r_things.h b/src/r_things.h index 5723a5737..64dcb82b8 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -39,12 +39,13 @@ struct vissprite_t int y1, y2; // top / bottom of particle on screen }; angle_t angle; - fixed_t xscale, yscale; + fixed_t xscale; + float yscale; float depth; float idepth; // 1/z float deltax, deltay; DWORD FillColor; - fixed_t floorclip; + double floorclip; union { FTexture *pic; @@ -55,7 +56,7 @@ struct vissprite_t // Used by face sprites struct { - fixed_t texturemid; + double texturemid; fixed_t startfrac; // horizontal position of x1 fixed_t xiscale; // negative if flipped }; @@ -108,8 +109,8 @@ extern short screenheightarray[MAXWIDTH]; // vars for R_DrawMaskedColumn extern short* mfloorclip; extern short* mceilingclip; -extern fixed_t spryscale; -extern fixed_t sprtopscreen; +extern double spryscale; +extern double sprtopscreen; extern bool sprflipvert; extern double pspritexscale; diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 7097ebd27..dccbfdc93 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -202,30 +202,23 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) double centeryback = CenterY; CenterY = 0; - sprtopscreen = FLOAT2FIXED(y0); // There is not enough precision in the drawing routines to keep the full // precision for y0. :( - sprtopscreen &= ~(FRACUNIT - 1); + double dummy; + sprtopscreen = modf(y0, &dummy); double yscale = parms.destheight / img->GetHeight(); double iyscale = 1 / yscale; - spryscale = FLOAT2FIXED(yscale); - assert(spryscale > 2); -#if 0 - // Fix precision errors that are noticeable at some resolutions - if ((y0 + parms.destheight) > (y0 + yscale * img->GetHeight())) - { - spryscale++; - } -#endif + spryscale = yscale; + assert(spryscale > 0); sprflipvert = false; //dc_iscale = FLOAT2FIXED(iyscale); - //dc_texturemid = FLOAT2FIXED((-y0) * iyscale); + //dc_texturemid = (-y0) * iyscale; //dc_iscale = 0xffffffffu / (unsigned)spryscale; - dc_iscale = DivScale32(1, spryscale); - dc_texturemid = FixedMul(-sprtopscreen, dc_iscale) + xs_ToInt((CenterY - 1) * dc_iscale); + dc_iscale = FLOAT2FIXED(1 / spryscale); + dc_texturemid = (CenterY - 1 - sprtopscreen) * dc_iscale / 65536; fixed_t frac = 0; double xiscale = img->GetWidth() / parms.destwidth; double x2 = x0 + parms.destwidth; diff --git a/src/xs_Float.h b/src/xs_Float.h index 33150e4ea..6c676ee3a 100644 --- a/src/xs_Float.h +++ b/src/xs_Float.h @@ -87,14 +87,14 @@ public: // ==================================================================================================================== // Basic Conversion from Numbers // ==================================================================================================================== - finline static Fix ToFix (int32_t val) {return val<>N;} + finline static int32_t ToInt (Fix f) {return f>>N;} @@ -112,6 +112,15 @@ protected: } }; +finline static int32_t xs_ToFixed(int32_t n, real64 val) +{ + #if _xs_DEFAULT_CONVERSION==0 + return xs_CRoundToInt(val, _xs_doublemagic/(1< Date: Thu, 21 Apr 2016 19:46:03 -0500 Subject: [PATCH 08/12] Renderer floatification: Use floating point for geometry Zs --- src/r_bsp.cpp | 24 ++++++++++++------------ src/r_segs.cpp | 16 +++++++--------- src/r_things.cpp | 10 +++++----- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 1cc2fa918..420cfbd21 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -78,10 +78,10 @@ extern short wallbottom[MAXWIDTH]; extern short wallupper[MAXWIDTH]; extern short walllower[MAXWIDTH]; -fixed_t rw_backcz1, rw_backcz2; -fixed_t rw_backfz1, rw_backfz2; -fixed_t rw_frontcz1, rw_frontcz2; -fixed_t rw_frontfz1, rw_frontfz2; +double rw_backcz1, rw_backcz2; +double rw_backfz1, rw_backfz2; +double rw_frontcz1, rw_frontcz2; +double rw_frontfz1, rw_frontfz2; size_t MaxDrawSegs; @@ -596,10 +596,10 @@ void R_AddLine (seg_t *line) { backsector = line->backsector; } - rw_frontcz1 = frontsector->ceilingplane.ZatPointFixed(line->v1); - rw_frontfz1 = frontsector->floorplane.ZatPointFixed(line->v1); - rw_frontcz2 = frontsector->ceilingplane.ZatPointFixed(line->v2); - rw_frontfz2 = frontsector->floorplane.ZatPointFixed(line->v2); + rw_frontcz1 = frontsector->ceilingplane.ZatPoint(line->v1); + rw_frontfz1 = frontsector->floorplane.ZatPoint(line->v1); + rw_frontcz2 = frontsector->ceilingplane.ZatPoint(line->v2); + rw_frontfz2 = frontsector->floorplane.ZatPoint(line->v2); rw_mustmarkfloor = rw_mustmarkceiling = false; rw_havehigh = rw_havelow = false; @@ -618,10 +618,10 @@ void R_AddLine (seg_t *line) } doorclosed = 0; // killough 4/16/98 - rw_backcz1 = backsector->ceilingplane.ZatPointFixed (line->v1); - rw_backfz1 = backsector->floorplane.ZatPointFixed(line->v1); - rw_backcz2 = backsector->ceilingplane.ZatPointFixed(line->v2); - rw_backfz2 = backsector->floorplane.ZatPointFixed(line->v2); + rw_backcz1 = backsector->ceilingplane.ZatPoint(line->v1); + rw_backfz1 = backsector->floorplane.ZatPoint(line->v1); + rw_backcz2 = backsector->ceilingplane.ZatPoint(line->v2); + rw_backfz2 = backsector->floorplane.ZatPoint(line->v2); // Cannot make these walls solid, because it can result in // sprite clipping problems for sprites near the wall diff --git a/src/r_segs.cpp b/src/r_segs.cpp index c979a6b87..e689e5a89 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -98,10 +98,10 @@ double lwallscale; // // regular wall // -extern fixed_t rw_backcz1, rw_backcz2; -extern fixed_t rw_backfz1, rw_backfz2; -extern fixed_t rw_frontcz1, rw_frontcz2; -extern fixed_t rw_frontfz1, rw_frontfz2; +extern double rw_backcz1, rw_backcz2; +extern double rw_backfz1, rw_backfz2; +extern double rw_frontcz1, rw_frontcz2; +extern double rw_frontfz1, rw_frontfz2; int rw_ceilstat, rw_floorstat; bool rw_mustmarkfloor, rw_mustmarkceiling; @@ -136,7 +136,7 @@ static fixed_t *maskedtexturecol; static void R_RenderDecal (side_t *wall, DBaseDecal *first, drawseg_t *clipper, int pass); static void WallSpriteColumn (void (*drawfunc)(const BYTE *column, const FTexture::Span *spans)); -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, double top, double bot, bool mask); static void wallscan_np2_ds(drawseg_t *ds, int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat); static void call_wallscan(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat, bool mask); @@ -1317,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 yrep, fixed_t itop, fixed_t ibot, bool mask) +void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrep, double top, double bot, bool mask) { if (!r_np2) { @@ -1329,8 +1329,6 @@ void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed short *up, *down; double texheight = rw_pic->GetHeight(); double partition; - double top = FIXED2FLOAT(itop); - double bot = FIXED2FLOAT(ibot); double yrepeat = FIXED2FLOAT(yrep); double scaledtexheight = texheight / yrepeat; @@ -1407,7 +1405,7 @@ static void wallscan_np2_ds(drawseg_t *ds, int x1, int x2, short *uwal, short *d { bot = MAX(bot, sclipBottom); } - wallscan_np2(x1, x2, uwal, dwal, swal, lwal, yrepeat, FLOAT2FIXED(top), FLOAT2FIXED(bot), true); + wallscan_np2(x1, x2, uwal, dwal, swal, lwal, yrepeat, top, bot, true); } else { diff --git a/src/r_things.cpp b/src/r_things.cpp index 60ae7213b..42308a9e7 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -932,19 +932,19 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor { if (fakeside == FAKED_AboveCeiling) { - if (gzt < heightsec->ceilingplane.ZatPointFixed(pos)) + if (gzt < heightsec->ceilingplane.ZatPoint(pos)) return; } else if (fakeside == FAKED_BelowFloor) { - if (gzb >= heightsec->floorplane.ZatPointFixed(pos)) + if (gzb >= heightsec->floorplane.ZatPoint(pos)) return; } else { - if (gzt < heightsec->floorplane.ZatPointFixed(pos)) + if (gzt < heightsec->floorplane.ZatPoint(pos)) return; - if (!(heightsec->MoreFlags & SECF_FAKEFLOORONLY) && gzb >= heightsec->ceilingplane.ZatPointFixed(pos)) + if (!(heightsec->MoreFlags & SECF_FAKEFLOORONLY) && gzb >= heightsec->ceilingplane.ZatPoint(pos)) return; } } @@ -1929,7 +1929,7 @@ void R_DrawSprite (vissprite_t *spr) { if (!(fake3D & FAKE3D_CLIPTOP)) { - sclipTop = spr->sector->ceilingplane.ZatPointFixed(ViewPos); + sclipTop = spr->sector->ceilingplane.ZatPoint(ViewPos); } sector_t *sec = NULL; for (i = spr->sector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) From cb0fe38dfe3d2f0df47e84694cca66e601e99ea9 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 21 Apr 2016 19:48:52 -0500 Subject: [PATCH 09/12] Renderer floatification: "fix for signed divide" isn't needed when using xs_RoundToInt --- src/r_bsp.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 420cfbd21..43bff5ba0 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -791,8 +791,7 @@ bool FWallCoords::Init(const DVector2 &pt1, const DVector2 &pt2, double too_clos { if (tleft.X > tleft.Y) return true; // left edge is off the right side if (tleft.Y == 0) return true; - sx1 = xs_ToInt(CenterX + tleft.X * CenterX / tleft.Y); - if (tleft.X >= 0) sx1 = MIN(viewwidth, sx1+1); // fix for signed divide + sx1 = xs_RoundToInt(CenterX + tleft.X * CenterX / tleft.Y); sz1 = tleft.Y; } else @@ -811,8 +810,7 @@ bool FWallCoords::Init(const DVector2 &pt1, const DVector2 &pt2, double too_clos { if (tright.X < -tright.Y) return true; // right edge is off the left side if (tright.Y == 0) return true; - sx2 = xs_ToInt(CenterX + tright.X * CenterX / tright.Y); - if (tright.X >= 0) sx2 = MIN(viewwidth, sx2+1); // fix for signed divide + sx2 = xs_RoundToInt(CenterX + tright.X * CenterX / tright.Y); sz2 = tright.Y; } else @@ -945,8 +943,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 (ry1 == 0) return false; - sx1 = xs_ToInt(CenterX + rx1 * CenterX / ry1); - if (rx1 >= 0) sx1 = MIN(viewwidth, sx1+1); // fix for signed divide + sx1 = xs_RoundToInt(CenterX + rx1 * CenterX / ry1); } else { @@ -959,8 +956,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 (ry2 == 0) return false; - sx2 = xs_ToInt(CenterX + rx2 * CenterX / ry2); - if (rx2 >= 0) sx2 = MIN(viewwidth, sx2+1); // fix for signed divide + sx2 = xs_RoundToInt(CenterX + rx2 * CenterX / ry2); } else { From 1f97488945ab15a72f89a4099334aaa42acdd9bd Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 21 Apr 2016 20:17:02 -0500 Subject: [PATCH 10/12] Renderer floatification: Use floating point for decals --- src/r_segs.cpp | 28 +++++++++++----------------- src/r_things.cpp | 7 +++---- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index e689e5a89..6d71fc11e 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -3032,8 +3032,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, { DVector2 decal_left, decal_right, decal_pos; int x1, x2; - fixed_t xscale, yscale; - fixed_t topoff; + double yscale; BYTE flipx; double zpos; int needrepeat = 0; @@ -3085,9 +3084,6 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, } } - xscale = FLOAT2FIXED(decal->ScaleX); - yscale = FLOAT2FIXED(decal->ScaleY); - WallSpriteTile = TexMan(decal->PicNum, true); flipx = (BYTE)(decal->RenderFlags & RF_XFLIP); @@ -3102,12 +3098,10 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, FWallCoords savecoord = WallC; - x2 = WallSpriteTile->GetWidth(); - x1 = WallSpriteTile->LeftOffset; - x2 = x2 - x1; - - x1 *= xscale; - x2 *= xscale; + double edge_right = WallSpriteTile->GetWidth(); + double edge_left = WallSpriteTile->LeftOffset; + edge_right = (edge_right - edge_left) * decal->ScaleX; + edge_left *= decal->ScaleX; double dcx, dcy; decal->GetXY(wall, dcx, dcy); @@ -3115,8 +3109,8 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, DVector2 angvec = (curline->v2->fPos() - curline->v1->fPos()).Unit(); - decal_left = decal_pos - x1 * angvec - ViewPos; - decal_right = decal_pos + x2 * angvec - ViewPos; + decal_left = decal_pos - edge_left * angvec - ViewPos; + decal_right = decal_pos + edge_right * angvec - ViewPos; if (WallC.Init(decal_left, decal_right, TOO_CLOSE_Z)) goto done; @@ -3183,8 +3177,8 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, break; } - topoff = WallSpriteTile->TopOffset << FRACBITS; - dc_texturemid = topoff + (zpos - ViewPos.Z) / yscale; + yscale = decal->ScaleY; + dc_texturemid = WallSpriteTile->TopOffset + (zpos - ViewPos.Z) / yscale; // Clip sprite to drawseg x1 = MAX(clipper->x1, x1); @@ -3194,7 +3188,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, goto done; } - PrepWall (swall, lwall, WallSpriteTile->GetWidth() << FRACBITS, x1, x2); + PrepWall (swall, lwall, WallSpriteTile->GetWidth(), x1, x2); if (flipx) { @@ -3242,7 +3236,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, } // rw_offset is used as the texture's vertical scale - rw_offset = SafeDivScale30(1, yscale); + rw_offset = FLOAT2FIXED(1 / yscale); do { diff --git a/src/r_things.cpp b/src/r_things.cpp index 42308a9e7..3cda3cb91 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -632,9 +632,8 @@ void R_DrawWallSprite(vissprite_t *spr) void R_WallSpriteColumn (void (*drawfunc)(const BYTE *column, const FTexture::Span *spans)) { - unsigned int texturecolumn = lwall[dc_x] >> FRACBITS; - dc_iscale = MulScale16 (swall[dc_x], rw_offset); - spryscale = SafeDivScale32 (1, dc_iscale); + dc_iscale = MulScale16 (swall[dc_x], rw_offset/4); + spryscale = 65536.0 / dc_iscale; if (sprflipvert) sprtopscreen = CenterY + dc_texturemid * spryscale; else @@ -642,7 +641,7 @@ void R_WallSpriteColumn (void (*drawfunc)(const BYTE *column, const FTexture::Sp const BYTE *column; const FTexture::Span *spans; - column = WallSpriteTile->GetColumn (texturecolumn, &spans); + column = WallSpriteTile->GetColumn (lwall[dc_x] >> FRACBITS, &spans); dc_texturefrac = 0; drawfunc (column, spans); rw_light += rw_lightstep; From f1b3f59bcc557e0a2fd3375d2ae58cceea047f6f Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 22 Apr 2016 22:54:04 -0500 Subject: [PATCH 11/12] Renderer floatification: Use floating point for wall scale and yrepeat --- src/r_bsp.h | 2 +- src/r_draw.h | 6 +- src/r_main.cpp | 2 +- src/r_plane.cpp | 24 +++---- src/r_segs.cpp | 160 +++++++++++++++++++++++------------------------ src/r_segs.h | 4 +- src/r_sky.cpp | 21 +++---- src/r_sky.h | 6 +- src/r_things.cpp | 10 +-- src/r_utility.h | 2 +- 10 files changed, 115 insertions(+), 122 deletions(-) diff --git a/src/r_bsp.h b/src/r_bsp.h index ba302c686..48ca7565b 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -82,7 +82,7 @@ struct drawseg_t ptrdiff_t sprtopclip; // type short ptrdiff_t sprbottomclip; // type short ptrdiff_t maskedtexturecol; // type short - ptrdiff_t swall; // type fixed_t + ptrdiff_t swall; // type float int fake; // ident fake drawseg, don't draw and clip sprites // backups ptrdiff_t bkup; // sprtopclip backup, for mid and fake textures diff --git a/src/r_draw.h b/src/r_draw.h index 72b51dfa4..cb2f68f33 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -285,12 +285,12 @@ bool R_GetTransMaskDrawers (fixed_t (**tmvline1)(), void (**tmvline4)()); // to just use the texture's GetColumn() method. It just exists // for double-layer skies. const BYTE *R_GetColumn (FTexture *tex, int col); -void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat, const BYTE *(*getcol)(FTexture *tex, int col)=R_GetColumn); +void wallscan (int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, const BYTE *(*getcol)(FTexture *tex, int col)=R_GetColumn); // maskwallscan is exactly like wallscan but does not draw anything where the texture is color 0. -void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat, const BYTE *(*getcol)(FTexture *tex, int col)=R_GetColumn); +void maskwallscan (int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, const BYTE *(*getcol)(FTexture *tex, int col)=R_GetColumn); // transmaskwallscan is like maskwallscan, but it can also blend to the background -void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat, const BYTE *(*getcol)(FTexture *tex, int col)=R_GetColumn); +void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, const BYTE *(*getcol)(FTexture *tex, int col)=R_GetColumn); #endif diff --git a/src/r_main.cpp b/src/r_main.cpp index 92e131e26..62360f647 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -383,7 +383,7 @@ void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, IYaspectMul = (double)virtwidth * r_Yaspect / 320.0 / virtheight; InvZtoScale = YaspectMul * CenterX; - WallTMapScale2 = IYaspectMul * (1 << 18) / CenterX; + WallTMapScale2 = IYaspectMul / CenterX; // psprite scales pspritexscale = centerxwide / 160.0; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 40fbba1f5..6cf52e2c8 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -848,7 +848,7 @@ static double skymid; static angle_t skyangle; static double frontiScale; -extern fixed_t swall[MAXWIDTH]; +extern float swall[MAXWIDTH]; extern fixed_t lwall[MAXWIDTH]; extern fixed_t rw_offset; extern FTexture *rw_pic; @@ -916,13 +916,16 @@ static const BYTE *R_GetTwoSkyColumns (FTexture *fronttex, int x) static void R_DrawSky (visplane_t *pl) { int x; + float swal; if (pl->left >= pl->right) return; - dc_iscale = skyiscale; - - clearbuf (swall+pl->left, pl->right-pl->left, dc_iscale<<2); + swal = skyiscale; + for (x = pl->left; x < pl->right; ++x) + { + swall[x] = swal; + } if (MirrorFlags & RF_XFLIP) { @@ -957,20 +960,12 @@ static void R_DrawSky (visplane_t *pl) lastskycol[x] = 0xffffffff; } wallscan (pl->left, pl->right, (short *)pl->top, (short *)pl->bottom, swall, lwall, - FLOAT2FIXED(frontyScale), backskytex == NULL ? R_GetOneSkyColumn : R_GetTwoSkyColumns); + frontyScale, backskytex == NULL ? R_GetOneSkyColumn : R_GetTwoSkyColumns); } else { // The texture does not tile nicely frontyScale *= skyscale; frontiScale = 1 / frontyScale; - // Sodding crap. Fixed point sucks when you want precision. - // TODO (if I'm feeling adventurous): Rewrite the renderer to use floating point - // coordinates to keep as much precision as possible until the final - // rasterization stage so fudges like this aren't needed. - if (viewheight <= 600) - { - skymid -= 1; - } R_DrawSkyStriped (pl); } } @@ -989,7 +984,6 @@ static void R_DrawSkyStriped (visplane_t *pl) yl = 0; yh = short((frontskytex->GetHeight() - topfrac) * frontyScale); dc_texturemid = topfrac - iscale * (1 - CenterY); - fixed_t yScale = FLOAT2FIXED(rw_pic->Scale.Y); while (yl < viewheight) { @@ -1002,7 +996,7 @@ static void R_DrawSkyStriped (visplane_t *pl) { lastskycol[x] = 0xffffffff; } - wallscan (pl->left, pl->right, top, bot, swall, lwall, yScale, + wallscan (pl->left, pl->right, top, bot, swall, lwall, rw_pic->Scale.Y, backskytex == NULL ? R_GetOneSkyColumn : R_GetTwoSkyColumns); yl = yh; yh += drawheight; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 6d71fc11e..1ef0d76b0 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -91,7 +91,7 @@ short walltop[MAXWIDTH]; // [RH] record max extents of wall short wallbottom[MAXWIDTH]; short wallupper[MAXWIDTH]; short walllower[MAXWIDTH]; -fixed_t swall[MAXWIDTH]; +float swall[MAXWIDTH]; fixed_t lwall[MAXWIDTH]; double lwallscale; @@ -136,9 +136,9 @@ static fixed_t *maskedtexturecol; static void R_RenderDecal (side_t *wall, DBaseDecal *first, drawseg_t *clipper, int pass); static void WallSpriteColumn (void (*drawfunc)(const BYTE *column, const FTexture::Span *spans)); -void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat, double top, double bot, bool mask); -static void wallscan_np2_ds(drawseg_t *ds, int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat); -static void call_wallscan(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat, bool mask); +void wallscan_np2(int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, double top, double bot, bool mask); +static void wallscan_np2_ds(drawseg_t *ds, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat); +static void call_wallscan(int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat, bool mask); //============================================================================= // @@ -169,8 +169,8 @@ CVAR(Bool, r_drawmirrors, true, 0) // // R_RenderMaskedSegRange // -fixed_t *MaskedSWall; -double MaskedScaleY; +float *MaskedSWall; +float MaskedScaleY; static void BlastMaskedColumn (void (*blastfunc)(const BYTE *pixels, const FTexture::Span *spans), FTexture *tex) { @@ -180,7 +180,7 @@ static void BlastMaskedColumn (void (*blastfunc)(const BYTE *pixels, const FText dc_colormap = basecolormap->Maps + (GETPALOOKUP (rw_light, wallshade) << COLORMAPSHIFT); } - dc_iscale = xs_RoundToInt(MaskedSWall[dc_x] * MaskedScaleY); + dc_iscale = xs_Fix<16>::ToFix(MaskedSWall[dc_x] * MaskedScaleY); if (sprflipvert) sprtopscreen = CenterY + dc_texturemid * spryscale; else @@ -305,7 +305,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) goto clearfog; } - MaskedSWall = (fixed_t *)(openings + ds->swall) - ds->x1; + MaskedSWall = (float *)(openings + ds->swall) - ds->x1; MaskedScaleY = ds->yscale; maskedtexturecol = (fixed_t *)(openings + ds->maskedtexturecol) - ds->x1; spryscale = ds->iscale + ds->iscalestep * (x1 - ds->x1); @@ -433,7 +433,6 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) mfloorclip = walllower; mceilingclip = wallupper; - MaskedScaleY /= 4; // [RH] Wish I could remember why this needs to be done // draw the columns one at a time if (drawmode == DoDraw0) @@ -531,7 +530,7 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2) rw_offset = 0; rw_pic = tex; - wallscan_np2_ds(ds, x1, x2, mceilingclip, mfloorclip, MaskedSWall, maskedtexturecol, FLOAT2FIXED(ds->yscale)); + wallscan_np2_ds(ds, x1, x2, mceilingclip, mfloorclip, MaskedSWall, maskedtexturecol, ds->yscale); } clearfog: @@ -580,7 +579,7 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover) spryscale = ds->iscale + ds->iscalestep * (x1 - ds->x1); rw_scalestep = ds->iscalestep; - MaskedSWall = (fixed_t *)(openings + ds->swall) - ds->x1; + MaskedSWall = (float *)(openings + ds->swall) - ds->x1; // find positioning side_t *scaledside; @@ -656,7 +655,7 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover) } PrepLWall (lwall, curline->sidedef->TexelLength*xscale, ds->sx1, ds->sx2); - wallscan_np2_ds(ds, x1, x2, wallupper, walllower, MaskedSWall, lwall, FLOAT2FIXED(yscale)); + wallscan_np2_ds(ds, x1, x2, wallupper, walllower, MaskedSWall, lwall, yscale); R_FinishSetPatchStyle(); } @@ -1074,15 +1073,16 @@ inline fixed_t prevline1 (fixed_t vince, BYTE *colormap, int count, fixed_t vplc return doprevline1 (); } -void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, - fixed_t yrepeat, const BYTE *(*getcol)(FTexture *tex, int x)) +void wallscan (int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, + double yrepeat, const BYTE *(*getcol)(FTexture *tex, int x)) { - int x, shiftval; + int x, fracbits; int y1ve[4], y2ve[4], u4, d4, z; char bad; float light = rw_light - rw_lightstep; - SDWORD texturemid, xoffset; + SDWORD xoffset; BYTE *basecolormapdata; + double iscale; // This function also gets used to draw skies. Unlike BUILD, skies are // drawn by visplane instead of by bunch, so these checks are invalid. @@ -1098,13 +1098,10 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t //clock (WallScanCycles); rw_pic->GetHeight(); // Make sure texture size is loaded - shiftval = rw_pic->HeightBits; - setupvline (32-shiftval); - yrepeat >>= 2 + shiftval; - texturemid = xs_ToFixed(32 - shiftval, dc_texturemid); + fracbits = 32 - rw_pic->HeightBits; + setupvline(fracbits); xoffset = rw_offset; basecolormapdata = basecolormap->Maps; - fixed_t centeryfrac = FLOAT2FIXED(CenterY); x = x1; //while ((umost[x] > dmost[x]) && (x < x2)) x++; @@ -1134,9 +1131,10 @@ void wallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t dc_source = getcol (rw_pic, (lwal[x] + xoffset) >> FRACBITS); dc_dest = ylookup[y1ve[0]] + x + dc_destorg; - dc_iscale = swal[x] * yrepeat; dc_count = y2ve[0] - y1ve[0]; - dc_texturefrac = texturemid + FixedMul (dc_iscale, (y1ve[0]<> FRACBITS); - vince[z] = swal[x+z] * yrepeat; - vplce[z] = texturemid + FixedMul (vince[z], (y1ve[z]<> FRACBITS); dc_dest = ylookup[y1ve[0]] + x + dc_destorg; - dc_iscale = swal[x] * yrepeat; dc_count = y2ve[0] - y1ve[0]; - dc_texturefrac = texturemid + FixedMul (dc_iscale, (y1ve[0]<GetHeight(); double partition; - double yrepeat = FIXED2FLOAT(yrep); double scaledtexheight = texheight / yrepeat; if (yrepeat >= 0) @@ -1351,14 +1350,14 @@ void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed { down[j] = clamp(most3[j], up[j], dwal[j]); } - call_wallscan(x1, x2, up, down, swal, lwal, yrep, mask); + call_wallscan(x1, x2, up, down, swal, lwal, yrepeat, mask); up = down; down = (down == most1) ? most2 : most1; } partition -= scaledtexheight; dc_texturemid -= texheight; } - call_wallscan(x1, x2, up, dwal, swal, lwal, yrep, mask); + call_wallscan(x1, x2, up, dwal, swal, lwal, yrepeat, mask); } else { // upside down: draw strips from bottom to top @@ -1375,19 +1374,19 @@ void wallscan_np2(int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed { up[j] = clamp(most3[j], uwal[j], down[j]); } - call_wallscan(x1, x2, up, down, swal, lwal, yrep, mask); + call_wallscan(x1, x2, up, down, swal, lwal, yrepeat, mask); down = up; up = (up == most1) ? most2 : most1; } partition -= scaledtexheight; dc_texturemid -= texheight; } - call_wallscan(x1, x2, uwal, down, swal, lwal, yrep, mask); + call_wallscan(x1, x2, uwal, down, swal, lwal, yrepeat, mask); } } } -static void wallscan_np2_ds(drawseg_t *ds, int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, fixed_t yrepeat) +static void wallscan_np2_ds(drawseg_t *ds, int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, double yrepeat) { if (rw_pic->GetHeight() != 1 << rw_pic->HeightBits) { @@ -1424,16 +1423,17 @@ inline fixed_t mvline1 (fixed_t vince, BYTE *colormap, int count, fixed_t vplce, return domvline1 (); } -void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixed_t *lwal, - fixed_t yrepeat, const BYTE *(*getcol)(FTexture *tex, int x)) +void maskwallscan (int x1, int x2, short *uwal, short *dwal, float *swal, fixed_t *lwal, + double yrepeat, const BYTE *(*getcol)(FTexture *tex, int x)) { - int x, shiftval; + int x, fracbits; BYTE *p; int y1ve[4], y2ve[4], u4, d4, startx, dax, z; char bad; float light = rw_light - rw_lightstep; - SDWORD texturemid, xoffset; + SDWORD xoffset; BYTE *basecolormapdata; + double iscale; if (rw_pic->UseType == FTexture::TEX_Null) { @@ -1450,13 +1450,10 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe //clock (WallScanCycles); rw_pic->GetHeight(); // Make sure texture size is loaded - shiftval = rw_pic->HeightBits; - setupmvline (32-shiftval); - yrepeat >>= 2 + shiftval; - texturemid = xs_ToFixed(32 - shiftval, dc_texturemid); + fracbits = 32- rw_pic->HeightBits; + setupmvline(fracbits); xoffset = rw_offset; basecolormapdata = basecolormap->Maps; - fixed_t centeryfrac = FLOAT2FIXED(CenterY); x = startx = x1; p = x + dc_destorg; @@ -1484,9 +1481,10 @@ void maskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, fixe dc_source = getcol (rw_pic, (lwal[x] + xoffset) >> FRACBITS); dc_dest = ylookup[y1ve[0]] + p; - dc_iscale = swal[x] * yrepeat; dc_count = y2ve[0] - y1ve[0]; - dc_texturefrac = texturemid + FixedMul (dc_iscale, (y1ve[0]<> FRACBITS); - vince[z] = swal[dax] * yrepeat; - vplce[z] = texturemid + FixedMul (vince[z], (y1ve[z]<> FRACBITS); dc_dest = ylookup[y1ve[0]] + p; - dc_iscale = swal[x] * yrepeat; dc_count = y2ve[0] - y1ve[0]; - dc_texturefrac = texturemid + FixedMul (dc_iscale, (y1ve[0]<UseType == FTexture::TEX_Null) { @@ -1624,10 +1625,8 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, //clock (WallScanCycles); rw_pic->GetHeight(); // Make sure texture size is loaded - shiftval = rw_pic->HeightBits; - setuptmvline (32-shiftval); - yrepeat >>= 2 + shiftval; - texturemid = xs_ToFixed(32 - shiftval, dc_texturemid); + fracbits = 32 - rw_pic->HeightBits; + setuptmvline(fracbits); xoffset = rw_offset; basecolormapdata = basecolormap->Maps; fixed_t centeryfrac = FLOAT2FIXED(CenterY); @@ -1658,9 +1657,10 @@ void transmaskwallscan (int x1, int x2, short *uwal, short *dwal, fixed_t *swal, dc_source = getcol (rw_pic, (lwal[x] + xoffset) >> FRACBITS); dc_dest = ylookup[y1ve[0]] + p; - dc_iscale = swal[x] * yrepeat; dc_count = y2ve[0] - y1ve[0]; - dc_texturefrac = texturemid + FixedMul (dc_iscale, (y1ve[0]<> FRACBITS); - vince[z] = swal[dax] * yrepeat; - vplce[z] = texturemid + FixedMul (vince[z], (y1ve[z]<> FRACBITS); dc_dest = ylookup[y1ve[0]] + p; - dc_iscale = swal[x] * yrepeat; dc_count = y2ve[0] - y1ve[0]; - dc_texturefrac = texturemid + FixedMul (dc_iscale, (y1ve[0]<= 0) @@ -1868,7 +1870,7 @@ void R_RenderSegLoop () dc_texturemid = rw_midtexturemid; rw_pic = midtexture; xscale = rw_pic->Scale.X * rw_midtexturescalex; - yscale = FLOAT2FIXED(rw_pic->Scale.Y * rw_midtexturescaley); + yscale = rw_pic->Scale.Y * rw_midtexturescaley; if (xscale != lwallscale) { PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2); @@ -1911,7 +1913,7 @@ void R_RenderSegLoop () dc_texturemid = rw_toptexturemid; rw_pic = toptexture; xscale = rw_pic->Scale.X * rw_toptexturescalex; - yscale = FLOAT2FIXED(rw_pic->Scale.Y * rw_toptexturescaley); + yscale = rw_pic->Scale.Y * rw_toptexturescaley; if (xscale != lwallscale) { PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2); @@ -1957,7 +1959,7 @@ void R_RenderSegLoop () dc_texturemid = rw_bottomtexturemid; rw_pic = bottomtexture; xscale = rw_pic->Scale.X * rw_bottomtexturescalex; - yscale = FLOAT2FIXED(rw_pic->Scale.Y * rw_bottomtexturescaley); + yscale = rw_pic->Scale.Y * rw_bottomtexturescaley; if (xscale != lwallscale) { PrepLWall (lwall, curline->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2); @@ -2228,7 +2230,7 @@ void R_NewWall (bool needlights) rowoffset = sidedef->GetTextureYOffsetF(side_t::bottom); rw_bottomtexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::bottom)); rw_bottomtexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::bottom)); - yrepeat = fixed_t(bottomtexture->Scale.Y * rw_bottomtexturescaley); + yrepeat = bottomtexture->Scale.Y * rw_bottomtexturescaley; if (yrepeat >= 0) { // normal orientation if (linedef->flags & ML_DONTPEGBOTTOM) @@ -2492,7 +2494,7 @@ void R_StoreWallRange (int start, int stop) (rw_floorstat != 3 || !sidedef->GetTexture(side_t::bottom).isValid()) && (WallC.sz1 >= TOO_CLOSE_Z && WallC.sz2 >= TOO_CLOSE_Z)) { - fixed_t *swal; + float *swal; fixed_t *lwal; int i; @@ -2512,7 +2514,7 @@ void R_StoreWallRange (int start, int stop) ds_p->swall = R_NewOpening ((stop - start) * 2); lwal = (fixed_t *)(openings + ds_p->maskedtexturecol); - swal = (fixed_t *)(openings + ds_p->swall); + swal = (float *)(openings + ds_p->swall); FTexture *pic = TexMan(sidedef->GetTexture(side_t::mid), true); double yscale = pic->Scale.X * sidedef->GetTextureYScaleF(side_t::mid); fixed_t xoffset = sidedef->GetTextureXOffset(side_t::mid); @@ -2528,8 +2530,8 @@ void R_StoreWallRange (int start, int stop) *swal++ = swall[i]; } - double istart = *((fixed_t *)(openings + ds_p->swall)) * yscale / (1 << 18); - double iend = *(swal - 1) * yscale / (1 << 18); + double istart = *((float *)(openings + ds_p->swall)) * yscale; + double iend = *(swal - 1) * yscale; #if 0 ///This was for avoiding overflow when using fixed point. It might not be needed anymore. const double mini = 3 / 65536.0; @@ -2965,7 +2967,7 @@ static void PrepWallRoundFix(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 PrepWall (float *swall, fixed_t *lwall, double walxrepeat, int x1, int x2) { // swall = scale, lwall = texturecolumn double top, bot, i; double xrepeat = fabs(walxrepeat * 65536); @@ -2987,7 +2989,7 @@ void PrepWall (fixed_t *swall, fixed_t *lwall, double walxrepeat, int x1, int x2 { lwall[x] = xs_RoundToInt(frac * xrepeat); } - swall[x] = xs_RoundToInt(frac * depth_scale + depth_org); + swall[x] = float(frac * depth_scale + depth_org); top += WallT.UoverZstep; bot += WallT.InvZstep; } @@ -3235,9 +3237,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, sprflipvert = false; } - // rw_offset is used as the texture's vertical scale - rw_offset = FLOAT2FIXED(1 / yscale); - + MaskedScaleY = float(1 / yscale); do { dc_x = x1; diff --git a/src/r_segs.h b/src/r_segs.h index 7d1703423..1fc428c96 100644 --- a/src/r_segs.h +++ b/src/r_segs.h @@ -33,7 +33,7 @@ extern size_t maxopenings; int OWallMost (short *mostbuf, double z, const FWallCoords *wallc); int WallMost (short *mostbuf, const secplane_t &plane, const FWallCoords *wallc); -void PrepWall (fixed_t *swall, fixed_t *lwall, double walxrepeat, int x1, int x2); +void PrepWall (float *swall, fixed_t *lwall, double walxrepeat, int x1, int x2); void PrepLWall (fixed_t *lwall, double walxrepeat, int x1, int x2); ptrdiff_t R_NewOpening (ptrdiff_t len); @@ -42,7 +42,7 @@ void R_CheckDrawSegs (); void R_RenderSegLoop (); -extern fixed_t swall[MAXWIDTH]; +extern float swall[MAXWIDTH]; extern fixed_t lwall[MAXWIDTH]; extern float rw_light; // [RH] Scale lights with viewsize adjustments extern float rw_lightstep; diff --git a/src/r_sky.cpp b/src/r_sky.cpp index 727d0bbbf..0e0bc412a 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -41,8 +41,8 @@ FTextureID skyflatnum; FTextureID sky1texture, sky2texture; double skytexturemid; -fixed_t skyscale; -fixed_t skyiscale; +double skyscale; +float skyiscale; bool skystretch; fixed_t sky1cyl, sky2cyl; @@ -54,7 +54,7 @@ CUSTOM_CVAR (Bool, r_stretchsky, true, CVAR_ARCHIVE) R_InitSkyMap (); } -fixed_t freelookviewheight; +int freelookviewheight; //========================================================================== // @@ -112,19 +112,18 @@ void R_InitSkyMap () if (viewwidth != 0 && viewheight != 0) { - skyiscale = (r_Yaspect*FRACUNIT) / ((freelookviewheight * viewwidth) / viewwidth); - skyscale = (((freelookviewheight * viewwidth) / viewwidth) << FRACBITS) / - (r_Yaspect); + skyiscale = float(r_Yaspect / freelookviewheight); + skyscale = freelookviewheight / r_Yaspect; - skyiscale = Scale (skyiscale, FieldOfView, 2048); - skyscale = Scale (skyscale, 2048, FieldOfView); + skyiscale *= FieldOfView / 2048.f; + skyscale *= 2048.0 / FieldOfView; } if (skystretch) { - skyscale = Scale(skyscale, SKYSTRETCH_HEIGHT, skyheight); - skyiscale = Scale(skyiscale, skyheight, SKYSTRETCH_HEIGHT); - skytexturemid = skytexturemid * skyheight / SKYSTRETCH_HEIGHT; + skyscale *= (double)SKYSTRETCH_HEIGHT / skyheight; + skyiscale *= skyheight / (float)SKYSTRETCH_HEIGHT; + skytexturemid *= skyheight / (double)SKYSTRETCH_HEIGHT; } // The standard Doom sky texture is 256 pixels wide, repeated 4 times over 360 degrees, diff --git a/src/r_sky.h b/src/r_sky.h index 30b106185..6ece74d74 100644 --- a/src/r_sky.h +++ b/src/r_sky.h @@ -30,10 +30,10 @@ extern fixed_t sky1cyl, sky2cyl; extern FTextureID sky1texture, sky2texture; extern double sky1pos, sky2pos; extern double skytexturemid; -extern fixed_t skyiscale; -extern fixed_t skyscale; +extern float skyiscale; +extern double skyscale; extern bool skystretch; -extern fixed_t freelookviewheight; +extern int freelookviewheight; #define SKYSTRETCH_HEIGHT 228 diff --git a/src/r_things.cpp b/src/r_things.cpp index 3cda3cb91..ed77170fd 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -89,7 +89,7 @@ struct FCoverageBuffer }; extern double globaluclip, globaldclip; - +extern float MaskedScaleY; #define MINZ double((2048*4) / double(1 << 20)) #define BASEYCENTER (100) @@ -558,8 +558,7 @@ void R_DrawWallSprite(vissprite_t *spr) sprflipvert = false; } - // rw_offset is used as the texture's vertical scale - rw_offset = xs_Fix<30>::ToFix(iyscale); + MaskedScaleY = (float)iyscale; dc_x = x1; ESPSResult mode; @@ -632,8 +631,9 @@ void R_DrawWallSprite(vissprite_t *spr) void R_WallSpriteColumn (void (*drawfunc)(const BYTE *column, const FTexture::Span *spans)) { - dc_iscale = MulScale16 (swall[dc_x], rw_offset/4); - spryscale = 65536.0 / dc_iscale; + float iscale = swall[dc_x] * MaskedScaleY; + dc_iscale = FLOAT2FIXED(iscale); + spryscale = 1 / iscale; if (sprflipvert) sprtopscreen = CenterY + dc_texturemid * spryscale; else diff --git a/src/r_utility.h b/src/r_utility.h index 1cdfda6eb..d1de9336c 100644 --- a/src/r_utility.h +++ b/src/r_utility.h @@ -39,7 +39,7 @@ extern DWORD r_FrameTime; extern int extralight; extern unsigned int R_OldBlend; -const int r_Yaspect = 200; // Why did I make this a variable? It's never set anywhere. +const double r_Yaspect = 200.0; // Why did I make this a variable? It's never set anywhere. //========================================================================== // From 4d4f31fd83b36bc0e93abd2f06e39da7f250eaef Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 23 Apr 2016 09:41:59 +0200 Subject: [PATCH 12/12] - floatified sidedef texture info and fixed two bugs involving this data. --- src/p_saveg.cpp | 4 +- src/p_scroll.cpp | 4 +- src/p_setup.cpp | 8 ++-- src/r_defs.h | 119 ++++++++++++++--------------------------------- src/r_plane.cpp | 2 +- src/r_segs.cpp | 34 +++++++------- 6 files changed, 62 insertions(+), 109 deletions(-) diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 54215568a..6eb98ff0c 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -480,8 +480,8 @@ void extsector_t::Serialize(FArchive &arc) FArchive &operator<< (FArchive &arc, side_t::part &p) { - arc << p.xoffset << p.yoffset << p.interpolation << p.texture - << p.xscale << p.yscale;// << p.Light; + arc << p.xOffset << p.yOffset << p.interpolation << p.texture + << p.xScale << p.yScale;// << p.Light; return arc; } diff --git a/src/p_scroll.cpp b/src/p_scroll.cpp index 01fbba3c5..a7246c332 100644 --- a/src/p_scroll.cpp +++ b/src/p_scroll.cpp @@ -549,8 +549,8 @@ void P_SpawnScrollers(void) case Scroll_Texture_Offsets: // killough 3/2/98: scroll according to sidedef offsets s = int(lines[i].sidedef[0] - sides); - new DScroller (EScroll::sc_side, -sides[s].GetTextureXOffset(side_t::mid), - sides[s].GetTextureYOffset(side_t::mid), -1, s, accel, SCROLLTYPE(l->args[0])); + new DScroller (EScroll::sc_side, -sides[s].GetTextureXOffsetF(side_t::mid), + sides[s].GetTextureYOffsetF(side_t::mid), -1, s, accel, SCROLLTYPE(l->args[0])); break; case Scroll_Texture_Left: diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 718e54e9b..e1dff8762 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -2627,10 +2627,10 @@ void P_LoadSideDefs2 (MapData *map, FMissingTextureTracker &missingtex) msd->rowoffset += 102; } - sd->SetTextureXOffset(LittleShort(msd->textureoffset)<SetTextureYOffset(LittleShort(msd->rowoffset)<SetTextureXScale(FRACUNIT); - sd->SetTextureYScale(FRACUNIT); + sd->SetTextureXOffset(LittleShort(msd->textureoffset)); + sd->SetTextureYOffset(LittleShort(msd->rowoffset)); + sd->SetTextureXScale(1.); + sd->SetTextureYScale(1.); sd->linedef = NULL; sd->Flags = 0; sd->Index = i; diff --git a/src/r_defs.h b/src/r_defs.h index 4c3406ce0..a11957e3f 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -1127,10 +1127,10 @@ struct side_t }; struct part { - fixed_t xoffset; - fixed_t yoffset; - fixed_t xscale; - fixed_t yscale; + double xOffset; + double yOffset; + double xScale; + double yScale; FTextureID texture; TObjPtr interpolation; //int Light; @@ -1163,135 +1163,88 @@ struct side_t textures[which].texture = tex; } - void SetTextureXOffset(int which, fixed_t offset) - { - textures[which].xoffset = offset; - } - void SetTextureXOffset(fixed_t offset) - { - textures[top].xoffset = - textures[mid].xoffset = - textures[bottom].xoffset = offset; - } void SetTextureXOffset(int which, double offset) { - textures[which].xoffset = FLOAT2FIXED(offset); + textures[which].xOffset = offset;; } void SetTextureXOffset(double offset) { - textures[top].xoffset = - textures[mid].xoffset = - textures[bottom].xoffset = FLOAT2FIXED(offset); - } - fixed_t GetTextureXOffset(int which) const - { - return textures[which].xoffset; + textures[top].xOffset = + textures[mid].xOffset = + textures[bottom].xOffset = offset; } + fixed_t GetTextureXOffset(int which) const = delete; double GetTextureXOffsetF(int which) const { - return FIXED2DBL(textures[which].xoffset); - } - void AddTextureXOffset(int which, fixed_t delta) - { - textures[which].xoffset += delta; + return textures[which].xOffset; } + void AddTextureXOffset(int which, fixed_t delta) = delete; void AddTextureXOffset(int which, double delta) { - textures[which].xoffset += FLOAT2FIXED(delta); + textures[which].xOffset += delta; } - void SetTextureYOffset(int which, fixed_t offset) - { - textures[which].yoffset = offset; - } - void SetTextureYOffset(fixed_t offset) - { - textures[top].yoffset = - textures[mid].yoffset = - textures[bottom].yoffset = offset; - } void SetTextureYOffset(int which, double offset) { - textures[which].yoffset = FLOAT2FIXED(offset); + textures[which].yOffset = offset; } void SetTextureYOffset(double offset) { - textures[top].yoffset = - textures[mid].yoffset = - textures[bottom].yoffset = FLOAT2FIXED(offset); - } - fixed_t GetTextureYOffset(int which) const - { - return textures[which].yoffset; + textures[top].yOffset = + textures[mid].yOffset = + textures[bottom].yOffset = offset; } + fixed_t GetTextureYOffset(int which) const = delete; double GetTextureYOffsetF(int which) const { - return FIXED2DBL(textures[which].yoffset); - } - void AddTextureYOffset(int which, fixed_t delta) - { - textures[which].yoffset += delta; + return textures[which].yOffset; } + void AddTextureYOffset(int which, fixed_t delta) = delete; void AddTextureYOffset(int which, double delta) { - textures[which].yoffset += FLOAT2FIXED(delta); + textures[which].yOffset += delta; } - void SetTextureXScale(int which, fixed_t scale) - { - textures[which].xscale = scale == 0 ? FRACUNIT : scale; - } + void SetTextureXScale(int which, fixed_t scale) = delete; void SetTextureXScale(int which, double scale) { - textures[which].xscale = scale == 0 ? FRACUNIT : FLOAT2FIXED(scale); - } - void SetTextureXScale(fixed_t scale) - { - textures[top].xscale = textures[mid].xscale = textures[bottom].xscale = scale == 0 ? FRACUNIT : scale; + textures[which].xScale = scale == 0 ? 1. : scale; } + void SetTextureXScale(fixed_t scale) = delete; void SetTextureXScale(double scale) { - textures[top].xscale = textures[mid].xscale = textures[bottom].xscale = scale == 0 ? FRACUNIT : FLOAT2FIXED(scale); + textures[top].xScale = textures[mid].xScale = textures[bottom].xScale = scale == 0 ? 1. : scale; } - fixed_t GetTextureXScale(int which) const + fixed_t GetTextureXScale(int which) const = delete; + double GetTextureXScaleF(int which) const { - return textures[which].xscale; + return textures[which].xScale; } + void MultiplyTextureXScale(int which, double delta) { - textures[which].xscale = fixed_t(textures[which].xscale * delta); - } - - - void SetTextureYScale(int which, fixed_t scale) - { - textures[which].yscale = scale == 0 ? FRACUNIT : scale; + textures[which].xScale *= delta; } + void SetTextureYScale(int which, fixed_t scale) = delete; void SetTextureYScale(int which, double scale) { - textures[which].yscale = scale == 0 ? FRACUNIT : FLOAT2FIXED(scale); + textures[which].yScale = scale == 0 ? 1. : scale; } - void SetTextureYScale(fixed_t scale) - { - textures[top].yscale = textures[mid].yscale = textures[bottom].yscale = scale == 0 ? FRACUNIT : scale; - } + void SetTextureYScale(fixed_t scale) = delete; void SetTextureYScale(double scale) { - textures[top].yscale = textures[mid].yscale = textures[bottom].yscale = scale == 0 ? FRACUNIT : FLOAT2FIXED(scale); - } - fixed_t GetTextureYScale(int which) const - { - return textures[which].yscale; + textures[top].yScale = textures[mid].yScale = textures[bottom].yScale = scale == 0 ? 1. : scale; } + fixed_t GetTextureYScale(int which) const = delete; double GetTextureYScaleF(int which) const { - return FIXED2DBL(textures[which].yscale); + return textures[which].yScale; } void MultiplyTextureYScale(int which, double delta) { - textures[which].yscale = fixed_t(textures[which].yscale * delta); + textures[which].yScale *= delta; } DInterpolation *SetInterpolation(int position); diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 6cf52e2c8..1ccbcd75f 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1447,7 +1447,7 @@ void R_DrawSkyPlane (visplane_t *pl) // to allow sky rotation as well as careful positioning. // However, the offset is scaled very small, so that it // allows a long-period of sky rotation. - skyangle += s->GetTextureXOffset(pos); + skyangle += FLOAT2FIXED(s->GetTextureXOffsetF(pos)); // Vertical offset allows careful sky positioning. skymid = s->GetTextureYOffsetF(pos) - 28; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 1ef0d76b0..22cfdb68c 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -599,12 +599,12 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover) scaledside = rover->master->sidedef[0]; scaledpart = side_t::mid; } - xscale = fixed_t(rw_pic->Scale.X * scaledside->GetTextureXScale(scaledpart)); + xscale = FLOAT2FIXED(rw_pic->Scale.X * scaledside->GetTextureXScaleF(scaledpart)); yscale = rw_pic->Scale.Y * scaledside->GetTextureYScaleF(scaledpart); double rowoffset = curline->sidedef->GetTextureYOffsetF(side_t::mid) + rover->master->sidedef[0]->GetTextureYOffsetF(side_t::mid); 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 = FLOAT2FIXED(curline->sidedef->GetTextureXOffsetF(side_t::mid) + rover->master->sidedef[0]->GetTextureXOffsetF(side_t::mid)); if (rowoffset < 0) { rowoffset += rw_pic->GetHeight(); @@ -2026,10 +2026,10 @@ void R_NewWall (bool needlights) if (linedef->special != Line_Horizon) { midtexture = TexMan(sidedef->GetTexture(side_t::mid), true); - rw_offset_mid = sidedef->GetTextureXOffset(side_t::mid); + rw_offset_mid = FLOAT2FIXED(sidedef->GetTextureXOffsetF(side_t::mid)); rowoffset = sidedef->GetTextureYOffsetF(side_t::mid); - rw_midtexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::mid)); - rw_midtexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::mid)); + rw_midtexturescalex = sidedef->GetTextureXScaleF(side_t::mid); + rw_midtexturescaley = sidedef->GetTextureYScaleF(side_t::mid); yrepeat = midtexture->Scale.Y * rw_midtexturescaley; if (yrepeat >= 0) { // normal orientation @@ -2181,10 +2181,10 @@ void R_NewWall (bool needlights) { // top texture toptexture = TexMan(sidedef->GetTexture(side_t::top), true); - rw_offset_top = sidedef->GetTextureXOffset(side_t::top); + rw_offset_top = FLOAT2FIXED(sidedef->GetTextureXOffsetF(side_t::top)); rowoffset = sidedef->GetTextureYOffsetF(side_t::top); - rw_toptexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::top)); - rw_toptexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::top)); + rw_toptexturescalex =sidedef->GetTextureXScaleF(side_t::top); + rw_toptexturescaley =sidedef->GetTextureYScaleF(side_t::top); yrepeat = toptexture->Scale.Y * rw_toptexturescaley; if (yrepeat >= 0) { // normal orientation @@ -2226,10 +2226,10 @@ void R_NewWall (bool needlights) { // bottom texture bottomtexture = TexMan(sidedef->GetTexture(side_t::bottom), true); - rw_offset_bottom = sidedef->GetTextureXOffset(side_t::bottom); + rw_offset_bottom = FLOAT2FIXED(sidedef->GetTextureXOffsetF(side_t::bottom)); rowoffset = sidedef->GetTextureYOffsetF(side_t::bottom); - rw_bottomtexturescalex = FIXED2DBL(sidedef->GetTextureXScale(side_t::bottom)); - rw_bottomtexturescaley = FIXED2DBL(sidedef->GetTextureYScale(side_t::bottom)); + rw_bottomtexturescalex = sidedef->GetTextureXScaleF(side_t::bottom); + rw_bottomtexturescaley = sidedef->GetTextureYScaleF(side_t::bottom); yrepeat = bottomtexture->Scale.Y * rw_bottomtexturescaley; if (yrepeat >= 0) { // normal orientation @@ -2301,10 +2301,10 @@ void R_NewWall (bool needlights) if (needlights && (segtextured || (backsector && IsFogBoundary(frontsector, backsector)))) { lwallscale = - midtex ? (midtex->Scale.X * sidedef->GetTextureXScale(side_t::mid) / 65536.0) : - toptexture ? (toptexture->Scale.X * sidedef->GetTextureXScale(side_t::top) / 65536.0) : - bottomtexture ? (bottomtexture->Scale.X * sidedef->GetTextureXScale(side_t::bottom) / 65536.0) : - FRACUNIT; + midtex ? (midtex->Scale.X * sidedef->GetTextureXScaleF(side_t::mid)) : + toptexture ? (toptexture->Scale.X * sidedef->GetTextureXScaleF(side_t::top)) : + bottomtexture ? (bottomtexture->Scale.X * sidedef->GetTextureXScaleF(side_t::bottom)) : + 1.; PrepWall (swall, lwall, sidedef->TexelLength * lwallscale, WallC.sx1, WallC.sx2); @@ -2387,7 +2387,7 @@ void R_StoreWallRange (int start, int stop) R_NewWall (true); } - rw_offset = sidedef->GetTextureXOffset(side_t::mid); + rw_offset = FLOAT2FIXED(sidedef->GetTextureXOffsetF(side_t::mid)); rw_light = rw_lightleft + rw_lightstep * (start - WallC.sx1); ds_p->CurrentPortalUniq = CurrentPortalUniq; @@ -2517,7 +2517,7 @@ void R_StoreWallRange (int start, int stop) swal = (float *)(openings + ds_p->swall); FTexture *pic = TexMan(sidedef->GetTexture(side_t::mid), true); double yscale = pic->Scale.X * sidedef->GetTextureYScaleF(side_t::mid); - fixed_t xoffset = sidedef->GetTextureXOffset(side_t::mid); + fixed_t xoffset = FLOAT2FIXED(sidedef->GetTextureXOffsetF(side_t::mid)); if (pic->bWorldPanning) {