Rewrite PrepWall and PrepLWall, plus make them aware of pixel centers

This commit is contained in:
Magnus Norddahl 2016-11-27 00:43:32 +01:00
parent 547973c8ba
commit 6417c1a7a3
1 changed files with 49 additions and 71 deletions

View File

@ -2628,98 +2628,76 @@ int WallMost(short *mostbuf, const secplane_t &plane, const FWallCoords *wallc)
} }
} }
static void PrepWallRoundFix(fixed_t *lwall, fixed_t walxrepeat, int x1, int x2) void PrepWall(float *vstep, fixed_t *upos, double walxrepeat, int x1, int x2)
{ {
// fix for rounding errors float uOverZ = WallT.UoverZorg + WallT.UoverZstep * (float)(x1 + 0.5 - CenterX);
walxrepeat = abs(walxrepeat); float invZ = WallT.InvZorg + WallT.InvZstep * (float)(x1 + 0.5 - CenterX);
fixed_t fix = (MirrorFlags & RF_XFLIP) ? walxrepeat-1 : 0; float uGradient = WallT.UoverZstep;
int x; float zGradient = WallT.InvZstep;
float xrepeat = (float)walxrepeat;
float depthScale = (float)(WallT.InvZstep * WallTMapScale2);
float depthOrg = (float)(-WallT.UoverZstep * WallTMapScale2);
if (x1 > 0) if (xrepeat < 0.0f)
{ {
for (x = x1; x < x2; x++) for (int x = x1; x < x2; x++)
{ {
if ((unsigned)lwall[x] >= (unsigned)walxrepeat) float u = uOverZ / invZ;
{
lwall[x] = fix; upos[x] = (fixed_t)((xrepeat - u * xrepeat) * FRACUNIT);
vstep[x] = depthOrg + u * depthScale;
uOverZ += uGradient;
invZ += zGradient;
}
} }
else else
{ {
break; for (int x = x1; x < x2; x++)
}
}
}
fix = walxrepeat - 1 - fix;
for (x = x2-1; x >= x1; x--)
{ {
if ((unsigned)lwall[x] >= (unsigned)walxrepeat) float u = uOverZ / invZ;
{
lwall[x] = fix; upos[x] = (fixed_t)(u * xrepeat * FRACUNIT);
} vstep[x] = depthOrg + u * depthScale;
else
{ uOverZ += uGradient;
break; invZ += zGradient;
} }
} }
} }
void PrepWall (float *swall, fixed_t *lwall, double walxrepeat, int x1, int x2) void PrepLWall(fixed_t *upos, double walxrepeat, int x1, int x2)
{ // swall = scale, lwall = texturecolumn {
double top, bot, i; float uOverZ = WallT.UoverZorg + WallT.UoverZstep * (float)(x1 + 0.5 - CenterX);
double xrepeat = fabs(walxrepeat * 65536); float invZ = WallT.InvZorg + WallT.InvZstep * (float)(x1 + 0.5 - CenterX);
double depth_scale = WallT.InvZstep * WallTMapScale2; float uGradient = WallT.UoverZstep;
double depth_org = -WallT.UoverZstep * WallTMapScale2; float zGradient = WallT.InvZstep;
float xrepeat = (float)walxrepeat;
i = x1 - centerx;
top = WallT.UoverZorg + WallT.UoverZstep * i;
bot = WallT.InvZorg + WallT.InvZstep * i;
if (xrepeat < 0.0f)
{
for (int x = x1; x < x2; x++) for (int x = x1; x < x2; x++)
{ {
double frac = top / bot; float u = uOverZ / invZ * xrepeat - xrepeat;
if (walxrepeat < 0)
{ upos[x] = (fixed_t)(u * FRACUNIT);
lwall[x] = xs_RoundToInt(xrepeat - frac * xrepeat);
uOverZ += uGradient;
invZ += zGradient;
}
} }
else else
{ {
lwall[x] = xs_RoundToInt(frac * xrepeat);
}
swall[x] = float(frac * depth_scale + depth_org);
top += WallT.UoverZstep;
bot += WallT.InvZstep;
}
PrepWallRoundFix(lwall, FLOAT2FIXED(walxrepeat), x1, x2);
}
void PrepLWall (fixed_t *lwall, double walxrepeat, int x1, int x2)
{ // lwall = texturecolumn
double top, bot, i;
double xrepeat = fabs(walxrepeat * 65536);
double topstep, botstep;
i = x1 - centerx;
top = WallT.UoverZorg + WallT.UoverZstep * i;
bot = WallT.InvZorg + WallT.InvZstep * i;
top *= xrepeat;
topstep = WallT.UoverZstep * xrepeat;
botstep = WallT.InvZstep;
for (int x = x1; x < x2; x++) for (int x = x1; x < x2; x++)
{ {
if (walxrepeat < 0) float u = uOverZ / invZ * xrepeat;
{
lwall[x] = xs_RoundToInt(xrepeat - top / bot); upos[x] = (fixed_t)(u * FRACUNIT);
uOverZ += uGradient;
invZ += zGradient;
} }
else
{
lwall[x] = xs_RoundToInt(top / bot);
} }
top += topstep;
bot += botstep;
}
PrepWallRoundFix(lwall, FLOAT2FIXED(walxrepeat), x1, x2);
} }
// pass = 0: when seg is first drawn // pass = 0: when seg is first drawn