Merge branch 'port-pointonside-zdoom' into 'next'

Port R_PointOnSide calculation from GZDoom

See merge request STJr/SRB2!2528
This commit is contained in:
Hanicef 2025-03-21 17:33:59 +00:00
commit 2f92ad42c9
4 changed files with 40 additions and 6 deletions

View file

@ -2046,7 +2046,10 @@ 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);
else
newsubsec = thing->subsector;
ceilingline = blockingline = NULL;
// The base floor / ceiling is from the subsector

View file

@ -588,7 +588,7 @@ static pslope_t *MakeViaMapthings(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flag
vx[i].y = mt->y << FRACBITS;
vx[i].z = mt->z << FRACBITS;
if (!mt->args[0])
vx[i].z += R_PointInSubsector(vx[i].x, vx[i].y)->sector->floorheight;
vx[i].z += R_OldPointInSubsector(vx[i].x, vx[i].y)->sector->floorheight;
}
ReconfigureViaVertexes(ret, vx[0], vx[1], vx[2]);

View file

@ -254,7 +254,7 @@ static void FlipCam2_OnChange(void)
//
// killough 5/2/98: reformatted
//
INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *restrict node)
INT32 R_OldPointOnSide(fixed_t x, fixed_t y, node_t *restrict node)
{
if (!node->dx)
return x <= node->x ? node->dy > 0 : node->dy < 0;
@ -273,7 +273,7 @@ INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *restrict node)
}
// killough 5/2/98: reformatted
INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line)
INT32 R_OldPointOnSegSide(fixed_t x, fixed_t y, seg_t *line)
{
fixed_t lx = line->v1->x;
fixed_t ly = line->v1->y;
@ -1036,6 +1036,16 @@ boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y)
return passes % 2;
}
subsector_t *R_OldPointInSubsector(fixed_t x, fixed_t y)
{
size_t nodenum = numnodes-1;
while (!(nodenum & NF_SUBSECTOR))
nodenum = nodes[nodenum].children[R_OldPointOnSide(x, y, nodes+nodenum)];
return &subsectors[nodenum & ~NF_SUBSECTOR];
}
//
// R_PointInSubsector
//

View file

@ -71,9 +71,29 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
// There a 0-31, i.e. 32 LUT in the COLORMAP lump.
#define NUMCOLORMAPS 32
INT32 R_OldPointOnSide(fixed_t x, fixed_t y, node_t *node);
INT32 R_OldPointOnSegSide(fixed_t x, fixed_t y, seg_t *line);
// 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)
{
// use cross product to determine side quickly
INT64 v = ((INT64)y - node->y) * node->dx - ((INT64)x - node->x) * node->dy;
return v >= 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;
// use cross product to determine side quickly
INT64 v = ((INT64)y - ly) * ldx - ((INT64)x - lx) * ldy;
return v >= 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);
@ -81,6 +101,7 @@ 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);
boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y);
subsector_t *R_OldPointInSubsector(fixed_t x, fixed_t y);
subsector_t *R_PointInSubsector(fixed_t x, fixed_t y);
subsector_t *R_PointInSubsectorOrNull(fixed_t x, fixed_t y);