Consolidate wall texturing vars into two structs

- All transformation and clipping values go into FWallCoords.
- All texture mapping values go into FWallTMapVals.
This commit is contained in:
Randy Heit 2014-07-31 20:11:59 -05:00
parent bbc3b69a7c
commit bc450808b2
3 changed files with 226 additions and 241 deletions

View file

@ -92,18 +92,8 @@ drawseg_t* ds_p;
size_t FirstInterestingDrawseg;
TArray<size_t> InterestingDrawsegs;
fixed_t WallTX1, WallTX2; // x coords at left, right of wall in view space
fixed_t WallTY1, WallTY2; // y coords at left, right of wall in view space
fixed_t WallCX1, WallCX2; // x coords at left, right of wall in camera space
fixed_t WallCY1, WallCY2; // y coords at left, right of wall in camera space
int WallSX1, WallSX2; // x coords at left, right of wall in screen space
fixed_t WallSZ1, WallSZ2; // depth at left, right of wall in screen space
float WallDepthOrg, WallDepthScale;
float WallUoverZorg, WallUoverZstep;
float WallInvZorg, WallInvZstep;
FWallCoords WallC;
FWallTmapVals WallT;
static BYTE FakeSide;
@ -419,7 +409,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
rw_frontcz2 <= s->floorplane.ZatPoint (curline->v2->x, curline->v2->y))
{
// Check that the window is actually visible
for (int z = WallSX1; z < WallSX2; ++z)
for (int z = WallC.SX1; z < WallC.SX2; ++z)
{
if (floorclip[z] > ceilingclip[z])
{
@ -549,66 +539,66 @@ void R_AddLine (seg_t *line)
if (DMulScale32 (ty1, tx1-tx2, tx1, ty2-ty1) >= 0)
return;
WallTX1 = DMulScale20 (tx1, viewsin, -ty1, viewcos);
WallTX2 = DMulScale20 (tx2, viewsin, -ty2, viewcos);
WallC.TX1 = DMulScale20 (tx1, viewsin, -ty1, viewcos);
WallC.TX2 = DMulScale20 (tx2, viewsin, -ty2, viewcos);
WallTY1 = DMulScale20 (tx1, viewtancos, ty1, viewtansin);
WallTY2 = DMulScale20 (tx2, viewtancos, ty2, viewtansin);
WallC.TY1 = DMulScale20 (tx1, viewtancos, ty1, viewtansin);
WallC.TY2 = DMulScale20 (tx2, viewtancos, ty2, viewtansin);
if (MirrorFlags & RF_XFLIP)
{
int t = 256-WallTX1;
WallTX1 = 256-WallTX2;
WallTX2 = t;
swapvalues (WallTY1, WallTY2);
int t = 256-WallC.TX1;
WallC.TX1 = 256-WallC.TX2;
WallC.TX2 = t;
swapvalues (WallC.TY1, WallC.TY2);
}
if (WallTX1 >= -WallTY1)
if (WallC.TX1 >= -WallC.TY1)
{
if (WallTX1 > WallTY1) return; // left edge is off the right side
if (WallTY1 == 0) return;
WallSX1 = (centerxfrac + Scale (WallTX1, centerxfrac, WallTY1)) >> FRACBITS;
if (WallTX1 >= 0) WallSX1 = MIN (viewwidth, WallSX1+1); // fix for signed divide
WallSZ1 = WallTY1;
if (WallC.TX1 > WallC.TY1) return; // left edge is off the right side
if (WallC.TY1 == 0) return;
WallC.SX1 = (centerxfrac + Scale (WallC.TX1, centerxfrac, WallC.TY1)) >> FRACBITS;
if (WallC.TX1 >= 0) WallC.SX1 = MIN (viewwidth, WallC.SX1+1); // fix for signed divide
WallC.SZ1 = WallC.TY1;
}
else
{
if (WallTX2 < -WallTY2) return; // wall is off the left side
fixed_t den = WallTX1 - WallTX2 - WallTY2 + WallTY1;
if (WallC.TX2 < -WallC.TY2) return; // wall is off the left side
fixed_t den = WallC.TX1 - WallC.TX2 - WallC.TY2 + WallC.TY1;
if (den == 0) return;
WallSX1 = 0;
WallSZ1 = WallTY1 + Scale (WallTY2 - WallTY1, WallTX1 + WallTY1, den);
WallC.SX1 = 0;
WallC.SZ1 = WallC.TY1 + Scale (WallC.TY2 - WallC.TY1, WallC.TX1 + WallC.TY1, den);
}
if (WallSZ1 < 32)
if (WallC.SZ1 < 32)
return;
if (WallTX2 <= WallTY2)
if (WallC.TX2 <= WallC.TY2)
{
if (WallTX2 < -WallTY2) return; // right edge is off the left side
if (WallTY2 == 0) return;
WallSX2 = (centerxfrac + Scale (WallTX2, centerxfrac, WallTY2)) >> FRACBITS;
if (WallTX2 >= 0) WallSX2 = MIN (viewwidth, WallSX2+1); // fix for signed divide
WallSZ2 = WallTY2;
if (WallC.TX2 < -WallC.TY2) return; // right edge is off the left side
if (WallC.TY2 == 0) return;
WallC.SX2 = (centerxfrac + Scale (WallC.TX2, centerxfrac, WallC.TY2)) >> FRACBITS;
if (WallC.TX2 >= 0) WallC.SX2 = MIN (viewwidth, WallC.SX2+1); // fix for signed divide
WallC.SZ2 = WallC.TY2;
}
else
{
if (WallTX1 > WallTY1) return; // wall is off the right side
fixed_t den = WallTY2 - WallTY1 - WallTX2 + WallTX1;
if (WallC.TX1 > WallC.TY1) return; // wall is off the right side
fixed_t den = WallC.TY2 - WallC.TY1 - WallC.TX2 + WallC.TX1;
if (den == 0) return;
WallSX2 = viewwidth;
WallSZ2 = WallTY1 + Scale (WallTY2 - WallTY1, WallTX1 - WallTY1, den);
WallC.SX2 = viewwidth;
WallC.SZ2 = WallC.TY1 + Scale (WallC.TY2 - WallC.TY1, WallC.TX1 - WallC.TY1, den);
}
if (WallSZ2 < 32 || WallSX2 <= WallSX1)
if (WallC.SZ2 < 32 || WallC.SX2 <= WallC.SX1)
return;
if (WallSX1 > WindowRight || WallSX2 < WindowLeft)
if (WallC.SX1 > WindowRight || WallC.SX2 < WindowLeft)
return;
if (line->linedef == NULL)
{
if (R_CheckClipWallSegment (WallSX1, WallSX2))
if (R_CheckClipWallSegment (WallC.SX1, WallC.SX2))
{
InSubsector->flags |= SSECF_DRAWN;
}
@ -624,17 +614,17 @@ void R_AddLine (seg_t *line)
{ // The seg is the entire wall.
if (MirrorFlags & RF_XFLIP)
{
WallUoverZorg = (float)WallTX2 * WallTMapScale;
WallUoverZstep = (float)(-WallTY2) * 32.f;
WallInvZorg = (float)(WallTX2 - WallTX1) * WallTMapScale;
WallInvZstep = (float)(WallTY1 - WallTY2) * 32.f;
WallT.UoverZorg = (float)WallC.TX2 * WallTMapScale;
WallT.UoverZstep = (float)(-WallC.TY2) * 32.f;
WallT.InvZorg = (float)(WallC.TX2 - WallC.TX1) * WallTMapScale;
WallT.InvZstep = (float)(WallC.TY1 - WallC.TY2) * 32.f;
}
else
{
WallUoverZorg = (float)WallTX1 * WallTMapScale;
WallUoverZstep = (float)(-WallTY1) * 32.f;
WallInvZorg = (float)(WallTX1 - WallTX2) * WallTMapScale;
WallInvZstep = (float)(WallTY2 - WallTY1) * 32.f;
WallT.UoverZorg = (float)WallC.TX1 * WallTMapScale;
WallT.UoverZstep = (float)(-WallC.TY1) * 32.f;
WallT.InvZorg = (float)(WallC.TX1 - WallC.TX2) * WallTMapScale;
WallT.InvZstep = (float)(WallC.TY2 - WallC.TY1) * 32.f;
}
}
else
@ -659,13 +649,13 @@ void R_AddLine (seg_t *line)
fullx2 = -fullx2;
}
WallUoverZorg = (float)fullx1 * WallTMapScale;
WallUoverZstep = (float)(-fully1) * 32.f;
WallInvZorg = (float)(fullx1 - fullx2) * WallTMapScale;
WallInvZstep = (float)(fully2 - fully1) * 32.f;
WallT.UoverZorg = (float)fullx1 * WallTMapScale;
WallT.UoverZstep = (float)(-fully1) * 32.f;
WallT.InvZorg = (float)(fullx1 - fullx2) * WallTMapScale;
WallT.InvZstep = (float)(fully2 - fully1) * 32.f;
}
WallDepthScale = WallInvZstep * WallTMapScale2;
WallDepthOrg = -WallUoverZstep * WallTMapScale2;
WallT.DepthScale = WallT.InvZstep * WallTMapScale2;
WallT.DepthOrg = -WallT.UoverZstep * WallTMapScale2;
if (!(fake3D & FAKE3D_FAKEBACK))
{
@ -791,7 +781,7 @@ void R_AddLine (seg_t *line)
// mark their subsectors as visible for automap texturing.
if (hasglnodes && !(InSubsector->flags & SSECF_DRAWN))
{
if (R_CheckClipWallSegment(WallSX1, WallSX2))
if (R_CheckClipWallSegment(WallC.SX1, WallC.SX2))
{
InSubsector->flags |= SSECF_DRAWN;
}
@ -805,8 +795,8 @@ void R_AddLine (seg_t *line)
if (line->linedef->special == Line_Horizon)
{
// Be aware: Line_Horizon does not work properly with sloped planes
clearbufshort (walltop+WallSX1, WallSX2 - WallSX1, centery);
clearbufshort (wallbottom+WallSX1, WallSX2 - WallSX1, centery);
clearbufshort (walltop+WallC.SX1, WallC.SX2 - WallC.SX1, centery);
clearbufshort (wallbottom+WallC.SX1, WallC.SX2 - WallC.SX1, centery);
}
else
{
@ -831,7 +821,7 @@ void R_AddLine (seg_t *line)
#endif
}
if (R_ClipWallSegment (WallSX1, WallSX2, solid))
if (R_ClipWallSegment (WallC.SX1, WallC.SX2, solid))
{
InSubsector->flags |= SSECF_DRAWN;
}

View file

@ -26,6 +26,25 @@
#include "tarray.h"
#include <stddef.h>
struct FWallCoords
{
fixed_t TX1, TX2; // x coords at left, right of wall in view space
fixed_t TY1, TY2; // y coords at left, right of wall in view space
fixed_t CX1, CX2; // x coords at left, right of wall in camera space
fixed_t CY1, CY2; // y coords at left, right of wall in camera space
int SX1, SX2; // x coords at left, right of wall in screen space
fixed_t SZ1, SZ2; // depth at left, right of wall in screen space
};
struct FWallTmapVals
{
float DepthOrg, DepthScale;
float UoverZorg, UoverZstep;
float InvZorg, InvZstep;
};
enum
{
FAKED_Center,
@ -33,7 +52,6 @@ enum
FAKED_AboveCeiling
};
struct drawseg_t
{
seg_t* curline;
@ -58,7 +76,7 @@ struct drawseg_t
int fake; // ident fake drawseg, don't draw and clip sprites
// backups
ptrdiff_t bkup; // sprtopclip backup, for mid and fake textures
float WallUoverZorg, WallUoverZstep, WallInvZorg, WallInvZstep, WallDepthScale, WallDepthOrg;
FWallTmapVals tmapvals;
};

View file

@ -90,9 +90,8 @@ int OWallMost (short *mostbuf, fixed_t z);
int WallMost (short *mostbuf, const secplane_t &plane);
void PrepWall (fixed_t *swall, fixed_t *lwall, fixed_t walxrepeat);
void PrepLWall (fixed_t *lwall, fixed_t walxrepeat);
extern fixed_t WallSZ1, WallSZ2, WallTX1, WallTX2, WallTY1, WallTY2, WallCX1, WallCX2, WallCY1, WallCY2;
extern int WallSX1, WallSX2;
extern float WallUoverZorg, WallUoverZstep, WallInvZorg, WallInvZstep, WallDepthScale, WallDepthOrg;
extern FWallCoords WallC;
extern FWallTmapVals WallT;
int wallshade;
@ -389,10 +388,10 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
goto clearfog;
}
WallSZ1 = ds->sz1;
WallSZ2 = ds->sz2;
WallSX1 = ds->sx1;
WallSX2 = ds->sx2;
WallC.SZ1 = ds->sz1;
WallC.SZ2 = ds->sz2;
WallC.SX1 = ds->sx1;
WallC.SX2 = ds->sx2;
if (fake3D & FAKE3D_CLIPTOP)
{
@ -480,10 +479,10 @@ void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2)
}
else
{ // Texture does wrap vertically.
WallSZ1 = ds->sz1;
WallSZ2 = ds->sz2;
WallSX1 = ds->sx1;
WallSX2 = ds->sx2;
WallC.SZ1 = ds->sz1;
WallC.SZ2 = ds->sz2;
WallC.SX1 = ds->sx1;
WallC.SX2 = ds->sx2;
if (CurrentSkybox)
{ // Midtex clipping doesn't work properly with skyboxes, since you're normally below the floor
@ -600,20 +599,15 @@ void R_RenderFakeWall(drawseg_t *ds, int x1, int x2, F3DFloor *rover)
else if (fixedcolormap != NULL)
dc_colormap = fixedcolormap;
WallSZ1 = ds->sz1;
WallSZ2 = ds->sz2;
WallSX1 = ds->sx1;
WallSX2 = ds->sx2;
WallTX1 = ds->cx;
WallTY1 = ds->cy;
WallTX2 = WallTX1 + ds->cdx;
WallTY2 = WallTY1 + ds->cdy;
WallDepthScale = ds->WallDepthScale;
WallDepthOrg = ds->WallDepthOrg;
WallUoverZorg = ds->WallUoverZorg;
WallUoverZstep = ds->WallUoverZstep;
WallInvZorg = ds->WallInvZorg;
WallInvZstep = ds->WallInvZstep;
WallC.SZ1 = ds->sz1;
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;
WallT = ds->tmapvals;
OWallMost(wallupper, sclipTop - viewz);
OWallMost(walllower, sclipBottom - viewz);
@ -1227,8 +1221,8 @@ void wallscan_striped (int x1, int x2, short *uwal, short *dwal, fixed_t *swal,
up = uwal;
down = most1;
assert(WallSX1 <= x1);
assert(WallSX2 > x2);
assert(WallC.SX1 <= x1);
assert(WallC.SX2 > x2);
// kg3D - fake floors instead of zdoom light list
for (unsigned int i = 0; i < frontsector->e->XFloor.lightlist.Size(); i++)
@ -2048,7 +2042,7 @@ void R_NewWall (bool needlights)
{
if (rw_havehigh)
{ // front ceiling is above back ceiling
memcpy (&walltop[WallSX1], &wallupper[WallSX1], (WallSX2 - WallSX1)*sizeof(walltop[0]));
memcpy (&walltop[WallC.SX1], &wallupper[WallC.SX1], (WallC.SX2 - WallC.SX1)*sizeof(walltop[0]));
rw_havehigh = false;
}
else if (rw_havelow && frontsector->ceilingplane != backsector->ceilingplane)
@ -2280,8 +2274,8 @@ void R_NewWall (bool needlights)
wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, frontsector->lightlevel)
+ r_actualextralight);
GlobVis = r_WallVisibility;
rw_lightleft = SafeDivScale12 (GlobVis, WallSZ1);
rw_lightstep = (SafeDivScale12 (GlobVis, WallSZ2) - rw_lightleft) / (WallSX2 - WallSX1);
rw_lightleft = SafeDivScale12 (GlobVis, WallC.SZ1);
rw_lightstep = (SafeDivScale12 (GlobVis, WallC.SZ2) - rw_lightleft) / (WallC.SX2 - WallC.SX1);
}
else
{
@ -2355,24 +2349,19 @@ void R_StoreWallRange (int start, int stop)
}
rw_offset = sidedef->GetTextureXOffset(side_t::mid);
rw_light = rw_lightleft + rw_lightstep * (start - WallSX1);
rw_light = rw_lightleft + rw_lightstep * (start - WallC.SX1);
ds_p->sx1 = WallSX1;
ds_p->sx2 = WallSX2;
ds_p->sz1 = WallSZ1;
ds_p->sz2 = WallSZ2;
ds_p->cx = WallTX1;
ds_p->cy = WallTY1;
ds_p->cdx = WallTX2 - WallTX1;
ds_p->cdy = WallTY2 - WallTY1;
ds_p->WallDepthScale = WallDepthScale;
ds_p->WallDepthOrg = WallDepthOrg;
ds_p->WallUoverZorg = WallUoverZorg;
ds_p->WallUoverZstep = WallUoverZstep;
ds_p->WallInvZorg = WallInvZorg;
ds_p->WallInvZstep = WallInvZstep;
ds_p->siz1 = (DWORD)DivScale32 (1, WallSZ1) >> 1;
ds_p->siz2 = (DWORD)DivScale32 (1, WallSZ2) >> 1;
ds_p->sx1 = WallC.SX1;
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->tmapvals = WallT;
ds_p->siz1 = (DWORD)DivScale32 (1, WallC.SZ1) >> 1;
ds_p->siz2 = (DWORD)DivScale32 (1, WallC.SZ2) >> 1;
ds_p->x1 = rw_x = start;
ds_p->x2 = stop-1;
ds_p->curline = curline;
@ -2465,7 +2454,7 @@ void R_StoreWallRange (int start, int stop)
if ((TexMan(sidedef->GetTexture(side_t::mid), true)->UseType != FTexture::TEX_Null || ds_p->bFakeBoundary || IsFogBoundary (frontsector, backsector)) &&
(rw_ceilstat != 12 || !sidedef->GetTexture(side_t::top).isValid()) &&
(rw_floorstat != 3 || !sidedef->GetTexture(side_t::bottom).isValid()) &&
(WallSZ1 >= TOO_CLOSE_Z && WallSZ2 >= TOO_CLOSE_Z))
(WallC.SZ1 >= TOO_CLOSE_Z && WallC.SZ2 >= TOO_CLOSE_Z))
{
fixed_t *swal;
fixed_t *lwal;
@ -2613,59 +2602,59 @@ int OWallMost (short *mostbuf, fixed_t z)
fixed_t s1, s2, s3, s4;
z = -(z >> 4);
s1 = MulScale16 (globaluclip, WallSZ1); s2 = MulScale16 (globaluclip, WallSZ2);
s3 = MulScale16 (globaldclip, WallSZ1); s4 = MulScale16 (globaldclip, WallSZ2);
s1 = MulScale16 (globaluclip, WallC.SZ1); s2 = MulScale16 (globaluclip, WallC.SZ2);
s3 = MulScale16 (globaldclip, WallC.SZ1); s4 = MulScale16 (globaldclip, WallC.SZ2);
bad = (z<s1)+((z<s2)<<1)+((z>s3)<<2)+((z>s4)<<3);
#if 1
if ((bad&3) == 3)
{
memset (&mostbuf[WallSX1], 0, (WallSX2 - WallSX1)*sizeof(mostbuf[0]));
memset (&mostbuf[WallC.SX1], 0, (WallC.SX2 - WallC.SX1)*sizeof(mostbuf[0]));
return bad;
}
if ((bad&12) == 12)
{
clearbufshort (&mostbuf[WallSX1], WallSX2 - WallSX1, viewheight);
clearbufshort (&mostbuf[WallC.SX1], WallC.SX2 - WallC.SX1, viewheight);
return bad;
}
#endif
ix1 = WallSX1; iy1 = WallSZ1;
ix2 = WallSX2; iy2 = WallSZ2;
ix1 = WallC.SX1; iy1 = WallC.SZ1;
ix2 = WallC.SX2; iy2 = WallC.SZ2;
#if 1
if (bad & 3)
{
int t = DivScale30 (z-s1, s2-s1);
int inty = WallSZ1 + MulScale30 (WallSZ2 - WallSZ1, t);
int xcross = WallSX1 + Scale (MulScale30 (WallSZ2, t), WallSX2 - WallSX1, inty);
int inty = WallC.SZ1 + MulScale30 (WallC.SZ2 - WallC.SZ1, t);
int xcross = WallC.SX1 + Scale (MulScale30 (WallC.SZ2, t), WallC.SX2 - WallC.SX1, inty);
if ((bad & 3) == 2)
{
if (WallSX1 <= xcross) { iy2 = inty; ix2 = xcross; }
if (WallSX2 > xcross) memset (&mostbuf[xcross], 0, (WallSX2-xcross)*sizeof(mostbuf[0]));
if (WallC.SX1 <= xcross) { iy2 = inty; ix2 = xcross; }
if (WallC.SX2 > xcross) memset (&mostbuf[xcross], 0, (WallC.SX2-xcross)*sizeof(mostbuf[0]));
}
else
{
if (xcross <= WallSX2) { iy1 = inty; ix1 = xcross; }
if (xcross > WallSX1) memset (&mostbuf[WallSX1], 0, (xcross-WallSX1)*sizeof(mostbuf[0]));
if (xcross <= WallC.SX2) { iy1 = inty; ix1 = xcross; }
if (xcross > WallC.SX1) memset (&mostbuf[WallC.SX1], 0, (xcross-WallC.SX1)*sizeof(mostbuf[0]));
}
}
if (bad & 12)
{
int t = DivScale30 (z-s3, s4-s3);
int inty = WallSZ1 + MulScale30 (WallSZ2 - WallSZ1, t);
int xcross = WallSX1 + Scale (MulScale30 (WallSZ2, t), WallSX2 - WallSX1, inty);
int inty = WallC.SZ1 + MulScale30 (WallC.SZ2 - WallC.SZ1, t);
int xcross = WallC.SX1 + Scale (MulScale30 (WallC.SZ2, t), WallC.SX2 - WallC.SX1, inty);
if ((bad & 12) == 8)
{
if (WallSX1 <= xcross) { iy2 = inty; ix2 = xcross; }
if (WallSX2 > xcross) clearbufshort (&mostbuf[xcross], WallSX2 - xcross, viewheight);
if (WallC.SX1 <= xcross) { iy2 = inty; ix2 = xcross; }
if (WallC.SX2 > xcross) clearbufshort (&mostbuf[xcross], WallC.SX2 - xcross, viewheight);
}
else
{
if (xcross <= WallSX2) { iy1 = inty; ix1 = xcross; }
if (xcross > WallSX1) clearbufshort (&mostbuf[WallSX1], xcross - WallSX1, viewheight);
if (xcross <= WallC.SX2) { iy1 = inty; ix1 = xcross; }
if (xcross > WallC.SX1) clearbufshort (&mostbuf[WallC.SX1], xcross - WallC.SX1, viewheight);
}
}
@ -2683,12 +2672,12 @@ int OWallMost (short *mostbuf, fixed_t z)
double max = viewheight;
double zz = z / 65536.0;
#if 0
double z1 = zz * InvZtoScale / WallSZ1;
double z2 = zz * InvZtoScale / WallSZ2 - z1;
z2 /= (WallSX2 - WallSX1);
double z1 = zz * InvZtoScale / WallC.SZ1;
double z2 = zz * InvZtoScale / WallC.SZ2 - z1;
z2 /= (WallC.SX2 - WallC.SX1);
z1 += centeryfrac / 65536.0;
for (int x = WallSX1; x < WallSX2; ++x)
for (int x = WallC.SX1; x < WallC.SX2; ++x)
{
mostbuf[x] = xs_RoundToInt(clamp(z1, 0.0, max));
z1 += z2;
@ -2696,18 +2685,18 @@ int OWallMost (short *mostbuf, fixed_t z)
#else
double top, bot, i;
i = WallSX1 - centerx;
top = WallUoverZorg + WallUoverZstep * i;
bot = WallInvZorg + WallInvZstep * i;
i = WallC.SX1 - centerx;
top = WallT.UoverZorg + WallT.UoverZstep * i;
bot = WallT.InvZorg + WallT.InvZstep * i;
double cy = centeryfrac / 65536.0;
for (int x = WallSX1; x < WallSX2; x++)
for (int x = WallC.SX1; x < WallC.SX2; x++)
{
double frac = top / bot;
double scale = frac * WallDepthScale + WallDepthOrg;
double scale = frac * WallT.DepthScale + WallT.DepthOrg;
mostbuf[x] = xs_RoundToInt(clamp(zz / scale + cy, 0.0, max));
top += WallUoverZstep;
bot += WallInvZstep;
top += WallT.UoverZstep;
bot += WallT.InvZstep;
}
#endif
#endif
@ -2734,21 +2723,21 @@ int WallMost (short *mostbuf, const secplane_t &plane)
{
x = curline->v2->x;
y = curline->v2->y;
if (WallSX1 == 0 && 0 != (den = WallTX1 - WallTX2 + WallTY1 - WallTY2))
if (WallC.SX1 == 0 && 0 != (den = WallC.TX1 - WallC.TX2 + WallC.TY1 - WallC.TY2))
{
int frac = SafeDivScale30 (WallTY1 + WallTX1, den);
int frac = SafeDivScale30 (WallC.TY1 + WallC.TX1, den);
x -= MulScale30 (frac, x - curline->v1->x);
y -= MulScale30 (frac, y - curline->v1->y);
}
z1 = viewz - plane.ZatPoint (x, y);
if (WallSX2 > WallSX1 + 1)
if (WallC.SX2 > WallC.SX1 + 1)
{
x = curline->v1->x;
y = curline->v1->y;
if (WallSX2 == viewwidth && 0 != (den = WallTX1 - WallTX2 - WallTY1 + WallTY2))
if (WallC.SX2 == viewwidth && 0 != (den = WallC.TX1 - WallC.TX2 - WallC.TY1 + WallC.TY2))
{
int frac = SafeDivScale30 (WallTY2 - WallTX2, den);
int frac = SafeDivScale30 (WallC.TY2 - WallC.TX2, den);
x += MulScale30 (frac, curline->v2->x - x);
y += MulScale30 (frac, curline->v2->y - y);
}
@ -2763,21 +2752,21 @@ int WallMost (short *mostbuf, const secplane_t &plane)
{
x = curline->v1->x;
y = curline->v1->y;
if (WallSX1 == 0 && 0 != (den = WallTX1 - WallTX2 + WallTY1 - WallTY2))
if (WallC.SX1 == 0 && 0 != (den = WallC.TX1 - WallC.TX2 + WallC.TY1 - WallC.TY2))
{
int frac = SafeDivScale30 (WallTY1 + WallTX1, den);
int frac = SafeDivScale30 (WallC.TY1 + WallC.TX1, den);
x += MulScale30 (frac, curline->v2->x - x);
y += MulScale30 (frac, curline->v2->y - y);
}
z1 = viewz - plane.ZatPoint (x, y);
if (WallSX2 > WallSX1 + 1)
if (WallC.SX2 > WallC.SX1 + 1)
{
x = curline->v2->x;
y = curline->v2->y;
if (WallSX2 == viewwidth && 0 != (den = WallTX1 - WallTX2 - WallTY1 + WallTY2))
if (WallC.SX2 == viewwidth && 0 != (den = WallC.TX1 - WallC.TX2 - WallC.TY1 + WallC.TY2))
{
int frac = SafeDivScale30 (WallTY2 - WallTX2, den);
int frac = SafeDivScale30 (WallC.TY2 - WallC.TX2, den);
x -= MulScale30 (frac, x - curline->v1->x);
y -= MulScale30 (frac, y - curline->v1->y);
}
@ -2789,12 +2778,12 @@ int WallMost (short *mostbuf, const secplane_t &plane)
}
}
s1 = MulScale12 (globaluclip, WallSZ1); s2 = MulScale12 (globaluclip, WallSZ2);
s3 = MulScale12 (globaldclip, WallSZ1); s4 = MulScale12 (globaldclip, WallSZ2);
s1 = MulScale12 (globaluclip, WallC.SZ1); s2 = MulScale12 (globaluclip, WallC.SZ2);
s3 = MulScale12 (globaldclip, WallC.SZ1); s4 = MulScale12 (globaldclip, WallC.SZ2);
bad = (z1<s1)+((z2<s2)<<1)+((z1>s3)<<2)+((z2>s4)<<3);
ix1 = WallSX1; ix2 = WallSX2;
iy1 = WallSZ1; iy2 = WallSZ2;
ix1 = WallC.SX1; ix2 = WallC.SX2;
iy1 = WallC.SZ1; iy2 = WallC.SZ2;
oz1 = z1; oz2 = z2;
if ((bad&3) == 3)
@ -2814,9 +2803,9 @@ int WallMost (short *mostbuf, const secplane_t &plane)
{
//inty = intz / (globaluclip>>16)
int t = SafeDivScale30 (oz1-s1, s2-s1+oz1-oz2);
int inty = WallSZ1 + MulScale30 (WallSZ2-WallSZ1,t);
int inty = WallC.SZ1 + MulScale30 (WallC.SZ2-WallC.SZ1,t);
int intz = oz1 + MulScale30 (oz2-oz1,t);
int xcross = WallSX1 + Scale (MulScale30 (WallSZ2, t), WallSX2-WallSX1, inty);
int xcross = WallC.SX1 + Scale (MulScale30 (WallC.SZ2, t), 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);
@ -2824,13 +2813,13 @@ int WallMost (short *mostbuf, const secplane_t &plane)
if ((bad&3) == 2)
{
if (WallSX1 <= xcross) { z2 = intz; iy2 = inty; ix2 = xcross; }
memset (&mostbuf[xcross], 0, (WallSX2-xcross)*sizeof(mostbuf[0]));
if (WallC.SX1 <= xcross) { z2 = intz; iy2 = inty; ix2 = xcross; }
memset (&mostbuf[xcross], 0, (WallC.SX2-xcross)*sizeof(mostbuf[0]));
}
else
{
if (xcross <= WallSX2) { z1 = intz; iy1 = inty; ix1 = xcross; }
memset (&mostbuf[WallSX1], 0, (xcross-WallSX1)*sizeof(mostbuf[0]));
if (xcross <= WallC.SX2) { z1 = intz; iy1 = inty; ix1 = xcross; }
memset (&mostbuf[WallC.SX1], 0, (xcross-WallC.SX1)*sizeof(mostbuf[0]));
}
}
@ -2838,9 +2827,9 @@ int WallMost (short *mostbuf, const secplane_t &plane)
{
//inty = intz / (globaldclip>>16)
int t = SafeDivScale30 (oz1-s3, s4-s3+oz1-oz2);
int inty = WallSZ1 + MulScale30 (WallSZ2-WallSZ1,t);
int inty = WallC.SZ1 + MulScale30 (WallC.SZ2-WallC.SZ1,t);
int intz = oz1 + MulScale30 (oz2-oz1,t);
int xcross = WallSX1 + Scale (MulScale30 (WallSZ2, t), WallSX2-WallSX1,inty);
int xcross = WallC.SX1 + Scale (MulScale30 (WallC.SZ2, t), 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);
@ -2848,13 +2837,13 @@ int WallMost (short *mostbuf, const secplane_t &plane)
if ((bad&12) == 8)
{
if (WallSX1 <= xcross) { z2 = intz; iy2 = inty; ix2 = xcross; }
if (WallSX2 > xcross) clearbufshort (&mostbuf[xcross], WallSX2-xcross, viewheight);
if (WallC.SX1 <= xcross) { z2 = intz; iy2 = inty; ix2 = xcross; }
if (WallC.SX2 > xcross) clearbufshort (&mostbuf[xcross], WallC.SX2-xcross, viewheight);
}
else
{
if (xcross <= WallSX2) { z1 = intz; iy1 = inty; ix1 = xcross; }
if (xcross > WallSX1) clearbufshort (&mostbuf[WallSX1], xcross-WallSX1, viewheight);
if (xcross <= WallC.SX2) { z1 = intz; iy1 = inty; ix1 = xcross; }
if (xcross > WallC.SX1) clearbufshort (&mostbuf[WallC.SX1], xcross-WallC.SX1, viewheight);
}
}
@ -2884,9 +2873,9 @@ static void PrepWallRoundFix(fixed_t *lwall, fixed_t walxrepeat)
fixed_t fix = (MirrorFlags & RF_XFLIP) ? walxrepeat-1 : 0;
int x;
if (WallSX1 > 0)
if (WallC.SX1 > 0)
{
for (x = WallSX1; x < WallSX2; x++)
for (x = WallC.SX1; x < WallC.SX2; x++)
{
if ((unsigned)lwall[x] >= (unsigned)walxrepeat)
{
@ -2899,7 +2888,7 @@ static void PrepWallRoundFix(fixed_t *lwall, fixed_t walxrepeat)
}
}
fix = walxrepeat - 1 - fix;
for (x = WallSX2-1; x >= WallSX1; x--)
for (x = WallC.SX2-1; x >= WallC.SX1; x--)
{
if ((unsigned)lwall[x] >= (unsigned)walxrepeat)
{
@ -2917,11 +2906,11 @@ void PrepWall (fixed_t *swall, fixed_t *lwall, fixed_t walxrepeat)
double top, bot, i;
double xrepeat = fabs((double)walxrepeat);
i = WallSX1 - centerx;
top = WallUoverZorg + WallUoverZstep * i;
bot = WallInvZorg + WallInvZstep * i;
i = WallC.SX1 - centerx;
top = WallT.UoverZorg + WallT.UoverZstep * i;
bot = WallT.InvZorg + WallT.InvZstep * i;
for (int x = WallSX1; x < WallSX2; x++)
for (int x = WallC.SX1; x < WallC.SX2; x++)
{
double frac = top / bot;
if (walxrepeat < 0)
@ -2932,9 +2921,9 @@ void PrepWall (fixed_t *swall, fixed_t *lwall, fixed_t walxrepeat)
{
lwall[x] = xs_RoundToInt(frac * xrepeat);
}
swall[x] = xs_RoundToInt(frac * WallDepthScale + WallDepthOrg);
top += WallUoverZstep;
bot += WallInvZstep;
swall[x] = xs_RoundToInt(frac * WallT.DepthScale + WallT.DepthOrg);
top += WallT.UoverZstep;
bot += WallT.InvZstep;
}
PrepWallRoundFix(lwall, walxrepeat);
}
@ -2945,14 +2934,14 @@ void PrepLWall (fixed_t *lwall, fixed_t walxrepeat)
double xrepeat = fabs((double)walxrepeat);
double topstep;
i = WallSX1 - centerx;
top = WallUoverZorg + WallUoverZstep * i;
bot = WallInvZorg + WallInvZstep * i;
i = WallC.SX1 - centerx;
top = WallT.UoverZorg + WallT.UoverZstep * i;
bot = WallT.InvZorg + WallT.InvZstep * i;
top *= xrepeat;
topstep = WallUoverZstep * xrepeat;
topstep = WallT.UoverZstep * xrepeat;
for (int x = WallSX1; x < WallSX2; x++)
for (int x = WallC.SX1; x < WallC.SX2; x++)
{
if (walxrepeat < 0)
{
@ -2963,7 +2952,7 @@ void PrepLWall (fixed_t *lwall, fixed_t walxrepeat)
lwall[x] = xs_RoundToInt(top / bot);
}
top += topstep;
bot += WallInvZstep;
bot += WallT.InvZstep;
}
PrepWallRoundFix(lwall, walxrepeat);
}
@ -3044,14 +3033,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper,
// to a wall, we use the wall's angle instead of the decal's. This is
// pretty much the same as what R_AddLine() does.
fixed_t savetx1, savetx2, savety1, savety2, savesz1, savesz2;
savetx1 = WallTX1;
savetx2 = WallTX2;
savety1 = WallTY1;
savety2 = WallTY2;
savesz1 = WallSZ1;
savesz2 = WallSZ2;
FWallCoords savecoord = WallC;
x2 = WallSpriteTile->GetWidth();
x1 = WallSpriteTile->LeftOffset;
@ -3068,76 +3050,76 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper,
ly = decaly - FixedMul (x1, finesine[ang]) - viewy;
ly2 = decaly + FixedMul (x2, finesine[ang]) - viewy;
WallTX1 = DMulScale20 (lx, viewsin, -ly, viewcos);
WallTX2 = DMulScale20 (lx2, viewsin, -ly2, viewcos);
WallC.TX1 = DMulScale20 (lx, viewsin, -ly, viewcos);
WallC.TX2 = DMulScale20 (lx2, viewsin, -ly2, viewcos);
WallTY1 = DMulScale20 (lx, viewtancos, ly, viewtansin);
WallTY2 = DMulScale20 (lx2, viewtancos, ly2, viewtansin);
WallC.TY1 = DMulScale20 (lx, viewtancos, ly, viewtansin);
WallC.TY2 = DMulScale20 (lx2, viewtancos, ly2, viewtansin);
if (MirrorFlags & RF_XFLIP)
{
int t = 256-WallTX1;
WallTX1 = 256-WallTX2;
WallTX2 = t;
swapvalues (WallTY1, WallTY2);
int t = 256-WallC.TX1;
WallC.TX1 = 256-WallC.TX2;
WallC.TX2 = t;
swapvalues (WallC.TY1, WallC.TY2);
}
if (WallTX1 >= -WallTY1)
if (WallC.TX1 >= -WallC.TY1)
{
if (WallTX1 > WallTY1) goto done; // left edge is off the right side
if (WallTY1 == 0) goto done;
x1 = (centerxfrac + Scale (WallTX1, centerxfrac, WallTY1)) >> FRACBITS;
if (WallTX1 >= 0) x1 = MIN (viewwidth, x1+1); // fix for signed divide
WallSZ1 = WallTY1;
if (WallC.TX1 > WallC.TY1) goto done; // left edge is off the right side
if (WallC.TY1 == 0) goto done;
x1 = (centerxfrac + Scale (WallC.TX1, centerxfrac, WallC.TY1)) >> FRACBITS;
if (WallC.TX1 >= 0) x1 = MIN (viewwidth, x1+1); // fix for signed divide
WallC.SZ1 = WallC.TY1;
}
else
{
if (WallTX2 < -WallTY2) goto done; // wall is off the left side
fixed_t den = WallTX1 - WallTX2 - WallTY2 + WallTY1;
if (WallC.TX2 < -WallC.TY2) goto done; // wall is off the left side
fixed_t den = WallC.TX1 - WallC.TX2 - WallC.TY2 + WallC.TY1;
if (den == 0) goto done;
x1 = 0;
WallSZ1 = WallTY1 + Scale (WallTY2 - WallTY1, WallTX1 + WallTY1, den);
WallC.SZ1 = WallC.TY1 + Scale (WallC.TY2 - WallC.TY1, WallC.TX1 + WallC.TY1, den);
}
if (WallSZ1 < TOO_CLOSE_Z)
if (WallC.SZ1 < TOO_CLOSE_Z)
goto done;
if (WallTX2 <= WallTY2)
if (WallC.TX2 <= WallC.TY2)
{
if (WallTX2 < -WallTY2) goto done; // right edge is off the left side
if (WallTY2 == 0) goto done;
x2 = (centerxfrac + Scale (WallTX2, centerxfrac, WallTY2)) >> FRACBITS;
if (WallTX2 >= 0) x2 = MIN (viewwidth, x2+1); // fix for signed divide
WallSZ2 = WallTY2;
if (WallC.TX2 < -WallC.TY2) goto done; // right edge is off the left side
if (WallC.TY2 == 0) goto done;
x2 = (centerxfrac + Scale (WallC.TX2, centerxfrac, WallC.TY2)) >> FRACBITS;
if (WallC.TX2 >= 0) x2 = MIN (viewwidth, x2+1); // fix for signed divide
WallC.SZ2 = WallC.TY2;
}
else
{
if (WallTX1 > WallTY1) goto done; // wall is off the right side
fixed_t den = WallTY2 - WallTY1 - WallTX2 + WallTX1;
if (WallC.TX1 > WallC.TY1) goto done; // wall is off the right side
fixed_t den = WallC.TY2 - WallC.TY1 - WallC.TX2 + WallC.TX1;
if (den == 0) goto done;
x2 = viewwidth;
WallSZ2 = WallTY1 + Scale (WallTY2 - WallTY1, WallTX1 - WallTY1, den);
WallC.SZ2 = WallC.TY1 + Scale (WallC.TY2 - WallC.TY1, WallC.TX1 - WallC.TY1, den);
}
if (x1 >= x2 || x1 > clipper->x2 || x2 <= clipper->x1 || WallSZ2 < TOO_CLOSE_Z)
if (x1 >= x2 || x1 > clipper->x2 || x2 <= clipper->x1 || WallC.SZ2 < TOO_CLOSE_Z)
goto done;
if (MirrorFlags & RF_XFLIP)
{
WallUoverZorg = (float)WallTX2 * WallTMapScale;
WallUoverZstep = (float)(-WallTY2) * 32.f;
WallInvZorg = (float)(WallTX2 - WallTX1) * WallTMapScale;
WallInvZstep = (float)(WallTY1 - WallTY2) * 32.f;
WallT.UoverZorg = (float)WallC.TX2 * WallTMapScale;
WallT.UoverZstep = (float)(-WallC.TY2) * 32.f;
WallT.InvZorg = (float)(WallC.TX2 - WallC.TX1) * WallTMapScale;
WallT.InvZstep = (float)(WallC.TY1 - WallC.TY2) * 32.f;
}
else
{
WallUoverZorg = (float)WallTX1 * WallTMapScale;
WallUoverZstep = (float)(-WallTY1) * 32.f;
WallInvZorg = (float)(WallTX1 - WallTX2) * WallTMapScale;
WallInvZstep = (float)(WallTY2 - WallTY1) * 32.f;
WallT.UoverZorg = (float)WallC.TX1 * WallTMapScale;
WallT.UoverZstep = (float)(-WallC.TY1) * 32.f;
WallT.InvZorg = (float)(WallC.TX1 - WallC.TX2) * WallTMapScale;
WallT.InvZstep = (float)(WallC.TY2 - WallC.TY1) * 32.f;
}
WallDepthScale = WallInvZstep * WallTMapScale2;
WallDepthOrg = -WallUoverZstep * WallTMapScale2;
WallT.DepthScale = WallT.InvZstep * WallTMapScale2;
WallT.DepthOrg = -WallT.UoverZstep * WallTMapScale2;
// Get the top and bottom clipping arrays
switch (decal->RenderFlags & RF_CLIPMASK)
@ -3210,11 +3192,11 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper,
goto done;
}
swapvalues (x1, WallSX1);
swapvalues (x2, WallSX2);
swapvalues (x1, WallC.SX1);
swapvalues (x2, WallC.SX2);
PrepWall (swall, lwall, WallSpriteTile->GetWidth() << FRACBITS);
swapvalues (x1, WallSX1);
swapvalues (x2, WallSX2);
swapvalues (x1, WallC.SX1);
swapvalues (x2, WallC.SX2);
if (flipx)
{
@ -3239,7 +3221,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper,
rereadcolormap = false;
}
rw_light = rw_lightleft + (x1 - WallSX1) * rw_lightstep;
rw_light = rw_lightleft + (x1 - WallC.SX1) * rw_lightstep;
if (fixedlightlev >= 0)
dc_colormap = usecolormap->Maps + fixedlightlev;
else if (fixedcolormap != NULL)
@ -3346,12 +3328,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper,
R_FinishSetPatchStyle ();
done:
WallTX1 = savetx1;
WallTX2 = savetx2;
WallTY1 = savety1;
WallTY2 = savety2;
WallSZ1 = savesz1;
WallSZ2 = savesz2;
WallC = savecoord;
}
static void WallSpriteColumn (void (*drawfunc)(const BYTE *column, const FTexture::Span *spans))