From 82fa8755027ff3a6485740909b207ecb5c2fe5c7 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sat, 12 Jun 2021 00:56:55 -0400 Subject: [PATCH] Refactor R_PointToAnglePlayer --- src/r_main.c | 58 ++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 97d946876..dfc11ab4a 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -318,18 +318,7 @@ INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line) angle_t R_PointToAngle(fixed_t x, fixed_t y) { - return (y -= viewy, (x -= viewx) || y) ? - x >= 0 ? - y >= 0 ? - (x > y) ? tantoangle[SlopeDiv(y,x)] : // octant 0 - ANGLE_90-tantoangle[SlopeDiv(x,y)] : // octant 1 - x > (y = -y) ? 0-tantoangle[SlopeDiv(y,x)] : // octant 8 - ANGLE_270+tantoangle[SlopeDiv(x,y)] : // octant 7 - y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDiv(y,x)] : // octant 3 - ANGLE_90 + tantoangle[SlopeDiv(x,y)] : // octant 2 - (x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDiv(y,x)] : // octant 4 - ANGLE_270-tantoangle[SlopeDiv(x,y)] : // octant 5 - 0; + return R_PointToAngle2(viewx, viewy, x, y); } // Similar to R_PointToAngle, but requires an additional player_t argument. @@ -338,33 +327,26 @@ angle_t R_PointToAngle(fixed_t x, fixed_t y) angle_t R_PointToAnglePlayer(player_t *player, fixed_t x, fixed_t y) { fixed_t refx = viewx, refy = viewy; - camera_t *cam = &camera[0]; - - // Check for splitscreen players and get their cam if possible. - if (player == &players[displayplayers[1]]) - cam = &camera[1]; - else if (player == &players[displayplayers[2]]) - cam = &camera[2]; - else if (player == &players[displayplayers[3]]) - cam = &camera[3]; - + camera_t *cam = NULL; + UINT8 i; + + for (i = 0; i < r_splitscreen; i++) + { + if (player == &players[displayplayers[i]]) + { + cam = &camera[i]; + break; + } + } + // use whatever cam we found's coordinates. - refx = cam->x; - refy = cam->y; - - // Now do whatever tehe fuck is this hellish maths from R_PointToAngle while swapping viewx/viewy for our refx/refy - return (y -= refy, (x -= refx) || y) ? - x >= 0 ? - y >= 0 ? - (x > y) ? tantoangle[SlopeDiv(y,x)] : // octant 0 - ANGLE_90-tantoangle[SlopeDiv(x,y)] : // octant 1 - x > (y = -y) ? 0-tantoangle[SlopeDiv(y,x)] : // octant 8 - ANGLE_270+tantoangle[SlopeDiv(x,y)] : // octant 7 - y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDiv(y,x)] : // octant 3 - ANGLE_90 + tantoangle[SlopeDiv(x,y)] : // octant 2 - (x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDiv(y,x)] : // octant 4 - ANGLE_270-tantoangle[SlopeDiv(x,y)] : // octant 5 - 0; + if (cam != NULL) + { + refx = cam->x; + refy = cam->y; + } + + return R_PointToAngle2(refx, refy, x, y); } // This version uses 64-bit variables to avoid overflows with large values.