Merge branch 'optimize-slope-z-positioning' into 'next'

Optimize Z position functions on sloped sectors

See merge request STJr/SRB2!2214
This commit is contained in:
Logan Aerl Arias 2023-12-26 00:00:11 +00:00
commit cae7161b2e
3 changed files with 33 additions and 4 deletions

View file

@ -1123,7 +1123,7 @@ fixed_t P_MobjFloorZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t
testy += y;
// If the highest point is in the sector, then we have it easy! Just get the Z at that point
if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector))
if (R_IsPointInSector(boundsec ? boundsec : sector, testx, testy))
return P_GetSlopeZAt(slope, testx, testy);
// If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point
@ -1200,7 +1200,7 @@ fixed_t P_MobjCeilingZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed
testy += y;
// If the highest point is in the sector, then we have it easy! Just get the Z at that point
if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector))
if (R_IsPointInSector(boundsec ? boundsec : sector, testx, testy))
return P_GetSlopeZAt(slope, testx, testy);
// If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point
@ -1278,7 +1278,7 @@ fixed_t P_CameraFloorZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, fix
testy += y;
// If the highest point is in the sector, then we have it easy! Just get the Z at that point
if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector))
if (R_IsPointInSector(boundsec ? boundsec : sector, testx, testy))
return P_GetSlopeZAt(slope, testx, testy);
// If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point
@ -1355,7 +1355,7 @@ fixed_t P_CameraCeilingZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, f
testy += y;
// If the highest point is in the sector, then we have it easy! Just get the Z at that point
if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector))
if (R_IsPointInSector(boundsec ? boundsec : sector, testx, testy))
return P_GetSlopeZAt(slope, testx, testy);
// If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point

View file

@ -1027,6 +1027,34 @@ void R_Init(void)
framecount = 0;
}
//
// R_IsPointInSector
//
boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y)
{
size_t i;
line_t *closest = NULL;
fixed_t closestdist = INT32_MAX;
for (i = 0; i < sector->linecount; i++)
{
vertex_t v;
fixed_t dist;
// find the line closest to the point we're looking for.
P_ClosestPointOnLine(x, y, sector->lines[i], &v);
dist = R_PointToDist2(0, 0, v.x - x, v.y - y);
if (dist < closestdist)
{
closest = sector->lines[i];
closestdist = dist;
}
}
// if the side of the closest line is in this sector, we're inside of it.
return P_PointOnLineSide(x, y, closest) == 0 ? closest->frontsector == sector : closest->backsector == sector;
}
//
// R_PointInSubsector
//

View file

@ -79,6 +79,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);
fixed_t R_ScaleFromGlobalAngle(angle_t visangle);
boolean R_IsPointInSector(sector_t *sector, 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);