Skip to content

Commit

Permalink
rt_floor.c: fixed incorrect floor rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
erysdren committed Dec 10, 2023
1 parent 2740218 commit 3c71164
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions source/rt_floor.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ void DrawHLine(int xleft, int xright, int yp)
buf = floor;
hd = yp - centery;
height = (hd << 13) / (maxheight - pheight + 32);

mr_xstep = FixedScale(viewsin << 8, maxheight - pheight + 32, hd);
mr_ystep = FixedScale(viewcos << 8, maxheight - pheight + 32, hd);
}
else
{
Expand All @@ -508,16 +511,14 @@ void DrawHLine(int xleft, int xright, int yp)

hd = centery - yp;
height = (hd << 13) / pheight;

mr_xstep = FixedScale(viewsin << 8, pheight, hd);
mr_ystep = FixedScale(viewcos << 8, pheight, hd);
}
SetFCLightLevel(height >> (8 - HEIGHTFRACTION - 1));
mr_xstep = ((viewsin << 8) / (height));
mr_ystep = ((viewcos << 8) / (height));

startxfrac = ((viewx >> 1) + FixedMulShift(mr_ystep, scale, 2)) -
FixedMulShift(mr_xstep, (centerx - xleft), 2);

startyfrac = ((viewy >> 1) - FixedMulShift(mr_xstep, scale, 2)) -
FixedMulShift(mr_ystep, (centerx - xleft), 2);
startxfrac = ((viewx << 14) + mr_ystep * scale) - (mr_xstep * (centerx - xleft));
startyfrac = ((viewy << 14) - mr_xstep * scale) - (mr_ystep * (centerx - xleft));

dest = (byte *)bufferofs + ylookup[yp];

Expand All @@ -529,10 +530,6 @@ void DrawHLine(int xleft, int xright, int yp)
mr_xfrac = startxfrac;
mr_yfrac = startyfrac;

// back off the pixel increment (orig. is 4x)
mr_xstep >>= 2;
mr_ystep >>= 2;

mr_count = xright - xleft + 1;

if (mr_count)
Expand Down Expand Up @@ -596,18 +593,19 @@ void DrawPlanes(void)

void DrawRow(int count, byte *dest, byte *src)
{
unsigned frac, fracstep;
unsigned xfrac, yfrac;
int coord;

frac = (mr_yfrac << 16) + (mr_xfrac & 0xffff);
fracstep = (mr_ystep << 16) + (mr_xstep & 0xffff);
xfrac = mr_xfrac;
yfrac = mr_yfrac;

while (count--)
{
/* extract the x/y coordinates */
coord = ((frac >> (32 - 7)) | ((frac >> (32 - 23)) << 7)) & 16383;
coord = ((yfrac >> 24) & 0b00000001111111) | ((xfrac >> 17) & 0b11111110000000);

*dest++ = shadingtable[src[coord]];
frac += fracstep;
xfrac += mr_xstep;
yfrac += mr_ystep;
}
}

0 comments on commit 3c71164

Please sign in to comment.