Commence renderer floatification

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

View file

@ -21,8 +21,8 @@ F3DFloor *fakeFloor;
fixed_t fakeHeight;
fixed_t 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;

View file

@ -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;

View file

@ -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,26 +917,26 @@ 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);
}
@ -950,7 +945,7 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static
{
if (rx1 > ry1) return false; // left edge is off the right side
if (ry1 == 0) return false;
sx1 = (centerxfrac + Scale (rx1, centerxfrac, ry1)) >> FRACBITS;
sx1 = xs_ToInt(CenterX + rx1 * CenterX / ry1);
if (rx1 >= 0) sx1 = MIN<int>(viewwidth, sx1+1); // fix for signed divide
}
else
@ -964,7 +959,7 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static
{
if (rx2 < -ry2) return false; // right edge is off the left side
if (ry2 == 0) return false;
sx2 = (centerxfrac + Scale (rx2, centerxfrac, ry2)) >> FRACBITS;
sx2 = xs_ToInt(CenterX + rx2 * CenterX / ry2);
if (rx2 >= 0) sx2 = MIN<int>(viewwidth, sx2+1); // fix for signed divide
}
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]);

View file

@ -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;

View file

@ -326,9 +326,9 @@ public:
}
// Returns the value of z at (0,0) This is used by the 3D floor code which does not handle slopes
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
{

View file

@ -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)

View file

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

View file

@ -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();

View file

@ -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<size_t> interestingStack;
static TArray<ptrdiff_t> drawsegStack;
static TArray<ptrdiff_t> visspriteStack;
static TArray<fixed_t> viewxStack, viewyStack, viewzStack;
static TArray<DVector3> viewposStack;
static TArray<visplane_t *> 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;

View file

@ -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;

View file

@ -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 = (z<s1)+((z<s2)<<1)+((z>s3)<<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 = (z1<s1)+((z2<s2)<<1)+((z1>s3)<<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<int>(clipper->x1, x1);

View file

@ -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);

View file

@ -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,7 +358,7 @@ static inline void R_CollectPortals()
}
}
static inline bool R_ClipSpriteColumnWithPortals(fixed_t x, fixed_t y, vissprite_t* spr)
static inline bool R_ClipSpriteColumnWithPortals(vissprite_t* spr)
{
// [ZZ] 10.01.2016: don't clip sprites from the root of a skybox.
if (CurrentPortalInSkybox)
@ -371,10 +372,8 @@ static inline bool R_ClipSpriteColumnWithPortals(fixed_t x, fixed_t y, vissprite
// (all checks that are already done in R_CollectPortals have been removed for performance reasons.)
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)<<FRACBITS);
tx -= tex->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<short>(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<short>(h, viewheight);
@ -2206,7 +2194,7 @@ void R_DrawSprite (vissprite_t *spr)
r1 = MAX<int> (ds->x1, x1);
r2 = MIN<int> (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<int> (WindowLeft, (centerxfrac + MulScale12 (tx-psize, xscale)) >> FRACBITS);
x2 = MIN<int> (WindowRight, (centerxfrac + MulScale12 (tx+psize, xscale)) >> FRACBITS);
x1 = MAX<int>(WindowLeft, centerx + xs_RoundToInt((tx - psize) * xscale));
x2 = MIN<int>(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);

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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 ();