From e74a28a2c143d481ea0bcf0f23adebbca9473982 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Sat, 11 Nov 2023 22:08:48 +0100 Subject: [PATCH] Fix old big room fix no idea what i was thinking but kart does use viewx and viewy for those originially, so just let me do a 64bit version of R_PointToAngleEx --- src/hardware/hw_main.c | 12 ++++++------ src/r_bsp.c | 8 ++++---- src/r_main.c | 42 ++++++++++++++++++++++++++---------------- src/r_main.h | 2 +- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 7981eef66..5e86ba885 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2815,8 +2815,8 @@ void HWR_AddLine(seg_t *line) } // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngle64(v1x, v1y); - angle2 = R_PointToAngle64(v2x, v2y); + angle1 = R_PointToAngleEx64(viewx, viewy, v1x, v1y); + angle2 = R_PointToAngleEx64(viewx, viewy, 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 @@ -3111,8 +3111,8 @@ boolean HWR_CheckBBox(fixed_t *bspcoord) if (mindist > current_bsp_culling_distance) return false; } - angle1 = R_PointToAngle64(px1, py1); - angle2 = R_PointToAngle64(px2, py2); + angle1 = R_PointToAngleEx64(viewx, viewy, px1, py1); + angle2 = R_PointToAngleEx64(viewx, viewy, px2, py2); return gld_clipper_SafeCheckRange(angle2, angle1); } @@ -5965,8 +5965,8 @@ void HWR_PortalClipping(portal_t *portal) line_t *line = &lines[portal->clipline]; - angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); - angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); + angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y); // clip things that are not inside the portal window from our viewpoint gld_clipper_SafeAddClipRange(angle2, angle1); diff --git a/src/r_bsp.c b/src/r_bsp.c index 2de30d2ab..f0dcbd80e 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_PointToAngle64(line->v1->x, line->v1->y); - angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx64(viewx, viewy, 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_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; - angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + angle1 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngleEx64(viewx, viewy, 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 d2907b2aa..6bf1bd2ad 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -395,22 +395,6 @@ angle_t R_PointToAngle(fixed_t x, fixed_t y) 0; } -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) ? @@ -505,6 +489,32 @@ 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 167d96625..036401ef9 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);