Refactor R_PointToAnglePlayer

This commit is contained in:
Sally Coolatta 2021-06-12 00:56:55 -04:00
parent b3cee8b8fc
commit 82fa875502

View file

@ -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.