From 3c71164406ec9cdcd1e2f7d11a686cd509b5d837 Mon Sep 17 00:00:00 2001 From: Jaycie Ewald Date: Sun, 10 Dec 2023 15:32:35 -0600 Subject: [PATCH] rt_floor.c: fixed incorrect floor rendering from rottexpr #48: https://github.com/LTCHIPS/rottexpr/pull/48/ --- source/rt_floor.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/source/rt_floor.c b/source/rt_floor.c index 9203f4b..831d744 100644 --- a/source/rt_floor.c +++ b/source/rt_floor.c @@ -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 { @@ -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]; @@ -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) @@ -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; } }