From be3a57c8abb11a114d03e5925524307914304c6f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 08:59:04 +0100 Subject: [PATCH] proper big room fix no idea what i was doing here, pointtoangle64 does all we need, no need for a hacky 64bit pointtoangleex --- src/hardware/hw_main.c | 8 ++++---- src/r_bsp.c | 8 ++++---- src/r_main.c | 43 +++++++++++++++++------------------------- src/r_main.h | 2 +- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 8ecc6975f..b2a4bdde8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2891,8 +2891,8 @@ void HWR_AddLine(seg_t *line) } // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngleEx64(viewx, viewy, v1x, v1y); - angle2 = R_PointToAngleEx64(viewx, viewy, v2x, v2y); + angle1 = R_PointToAngle64(v1x, v1y); + angle2 = R_PointToAngle64(v2x, v2y); // do an extra culling check when rendering portals // check if any line vertex is on the viewable side of the portal target line @@ -3085,8 +3085,8 @@ boolean HWR_CheckBBox(fixed_t *bspcoord) if (mindist > current_bsp_culling_distance) return false; } - angle1 = R_PointToAngleEx64(viewx, viewy, px1, py1); - angle2 = R_PointToAngleEx64(viewx, viewy, px2, py2); + angle1 = R_PointToAngle64(px1, py1); + angle2 = R_PointToAngle64(px2, py2); return gld_clipper_SafeCheckRange(angle2, angle1); } diff --git a/src/r_bsp.c b/src/r_bsp.c index 795ef459c..8750c2ee3 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -410,8 +410,8 @@ static void R_AddLine(seg_t *line) return; // big room fix - angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y); - angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y); + angle1 = R_PointToAngle64(line->v1->x, line->v1->y); + angle2 = R_PointToAngle64(line->v2->x, line->v2->y); curline = line; // Clip to view edges. @@ -613,8 +613,8 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) check = checkcoord[boxpos]; // big room fix - angle1 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle; - angle2 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; if ((signed)angle1 < (signed)angle2) { diff --git a/src/r_main.c b/src/r_main.c index 08bd34cb6..f067558e4 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -395,6 +395,23 @@ angle_t R_PointToAngle(fixed_t x, fixed_t y) 0; } +// This version uses 64-bit variables to avoid overflows with large values. +angle_t R_PointToAngle64(INT64 x, INT64 y) +{ + return (y -= viewy, (x -= viewx) || y) ? + x >= 0 ? + y >= 0 ? + (x > y) ? tantoangle[SlopeDivEx(y,x)] : // octant 0 + ANGLE_90-tantoangle[SlopeDivEx(x,y)] : // octant 1 + x > (y = -y) ? 0-tantoangle[SlopeDivEx(y,x)] : // octant 8 + ANGLE_270+tantoangle[SlopeDivEx(x,y)] : // octant 7 + y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDivEx(y,x)] : // octant 3 + ANGLE_90 + tantoangle[SlopeDivEx(x,y)] : // octant 2 + (x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDivEx(y,x)] : // octant 4 + ANGLE_270-tantoangle[SlopeDivEx(x,y)] : // octant 5 + 0; +} + angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) { return (y -= pviewy, (x -= pviewx) || y) ? @@ -489,32 +506,6 @@ angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1) 0; } -angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1) -{ - INT64 dx = x1 - x2; - INT64 dy = y1 - y2; - - // Check for potential overflow or underflow - if (dx < INT64_MIN || dx > INT64_MAX || dy < INT64_MIN || dy > INT64_MAX) - { - x1 = (INT64)(dx / 2 + x2); - y1 = (INT64)(dy / 2 + y2); - } - - return (y1 -= y2, (x1 -= x2) || y1) ? - x1 >= 0 ? - y1 >= 0 ? - (x1 > y1) ? tantoangle[SlopeDivEx(y1, x1)] : // octant 0 - ANGLE_90 - tantoangle[SlopeDivEx(x1, y1)] : // octant 1 - x1 > (y1 = -y1) ? 0 - tantoangle[SlopeDivEx(y1, x1)] : // octant 8 - ANGLE_270 + tantoangle[SlopeDivEx(x1, y1)] : // octant 7 - y1 >= 0 ? (x1 = -x1) > y1 ? ANGLE_180 - tantoangle[SlopeDivEx(y1, x1)] : // octant 3 - ANGLE_90 + tantoangle[SlopeDivEx(x1, y1)] : // octant 2 - (x1 = -x1) > (y1 = -y1) ? ANGLE_180 + tantoangle[SlopeDivEx(y1, x1)] : // octant 4 - ANGLE_270 - tantoangle[SlopeDivEx(x1, y1)] : // octant 5 - 0; -} - // // R_ScaleFromGlobalAngle // Returns the texture mapping scale for the current line (horizontal span) diff --git a/src/r_main.h b/src/r_main.h index 6a7ea7da6..dadb1c9cf 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -68,9 +68,9 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node); INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line); angle_t R_PointToAngle(fixed_t x, fixed_t y); +angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1); -angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1); fixed_t R_PointToDist(fixed_t x, fixed_t y); fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PlayerSliptideAngle(player_t *player);