Port R_PointOnSide calculation from GZDoom

This commit is contained in:
Gustaf Alhäll 2024-10-07 18:19:54 +02:00
parent b44b9a81c6
commit 8ac3cb45cc
3 changed files with 20 additions and 53 deletions

View file

@ -2021,7 +2021,7 @@ static boolean PIT_CheckLine(line_t *ld)
boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
{
INT32 xl, xh, yl, yh, bx, by;
subsector_t *newsubsec;
subsector_t *newsubsec = thing->subsector;
boolean blockval = true;
ps_checkposition_calls.value.i++;
@ -2043,7 +2043,8 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
tmbbox[BOXRIGHT] = x + tmthing->radius;
tmbbox[BOXLEFT] = x - tmthing->radius;
newsubsec = R_PointInSubsector(x, y);
if (thing->x != x || thing->y != y)
newsubsec = R_PointInSubsector(x, y);
ceilingline = blockingline = NULL;
// The base floor / ceiling is from the subsector

View file

@ -246,55 +246,6 @@ static void FlipCam2_OnChange(void)
SendWeaponPref2();
}
//
// R_PointOnSide
// Traverse BSP (sub) tree,
// check point against partition plane.
// Returns side 0 (front) or 1 (back).
//
// killough 5/2/98: reformatted
//
INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *restrict node)
{
if (!node->dx)
return x <= node->x ? node->dy > 0 : node->dy < 0;
if (!node->dy)
return y <= node->y ? node->dx < 0 : node->dx > 0;
fixed_t dx = (x >> 1) - (node->x >> 1);
fixed_t dy = (y >> 1) - (node->y >> 1);
// Try to quickly decide by looking at sign bits.
// also use a mask to avoid branch prediction
INT32 mask = (node->dy ^ node->dx ^ dx ^ dy) >> 31;
return (mask & ((node->dy ^ dx) < 0)) | // (left is negative)
(~mask & (FixedMul(dy, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, dx)));
}
// killough 5/2/98: reformatted
INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line)
{
fixed_t lx = line->v1->x;
fixed_t ly = line->v1->y;
fixed_t ldx = line->v2->x - lx;
fixed_t ldy = line->v2->y - ly;
if (!ldx)
return x <= lx ? ldy > 0 : ldy < 0;
if (!ldy)
return y <= ly ? ldx < 0 : ldx > 0;
fixed_t dx = (x >> 1) - (lx >> 1);
fixed_t dy = (y >> 1) - (ly >> 1);
// Try to quickly decide by looking at sign bits.
if ((ldy ^ ldx ^ dx ^ dy) < 0)
return (ldy ^ dx) < 0; // (left is negative)
return FixedMul(dy, ldx>>FRACBITS) >= FixedMul(ldy>>FRACBITS, dx);
}
//
// R_PointToAngle
// To get a global angle from cartesian coordinates,

View file

@ -72,8 +72,23 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
#define NUMCOLORMAPS 32
// Utility functions.
INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node);
INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line);
static inline INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node)
{
// heavily optimized version of R_PointOnSide, stolen from GZDoom.
return (INT64)(y - node->y) * node->dx + (INT64)(node->x - x) * node->dy > 0;
}
static inline INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line)
{
fixed_t lx = line->v1->x;
fixed_t ly = line->v1->y;
fixed_t ldx = line->v2->x - lx;
fixed_t ldy = line->v2->y - ly;
// heavily optimized version of R_PointOnSide, stolen from GZDoom.
return (INT64)(y - ly) * ldx + (INT64)(lx - x) * ldy > 0;
}
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);