mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-01-19 21:22:35 +00:00
Check previously considered best waypoint when pathfinding to solve overlapping waypoints
Previously could skip the waypoint that was actually closer and assume the further is the best.
This commit is contained in:
parent
4993d2ce39
commit
b672ffa8ba
1 changed files with 40 additions and 18 deletions
|
|
@ -253,6 +253,40 @@ waypoint_t *K_GetClosestWaypointToMobj(mobj_t *const mobj)
|
|||
return closestwaypoint;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
static void K_CompareOverlappingWaypoint
|
||||
( waypoint_t *const checkwaypoint,
|
||||
waypoint_t **const bestwaypoint,
|
||||
fixed_t *const bestfindist)
|
||||
|
||||
Solves touching overlapping waypoint radiuses by sorting by distance to
|
||||
finish line.
|
||||
--------------------------------------------------*/
|
||||
static void K_CompareOverlappingWaypoint
|
||||
( waypoint_t *const checkwaypoint,
|
||||
waypoint_t **const bestwaypoint,
|
||||
fixed_t *const bestfindist)
|
||||
{
|
||||
const boolean useshortcuts = false;
|
||||
const boolean huntbackwards = false;
|
||||
boolean pathfindsuccess = false;
|
||||
path_t pathtofinish = {};
|
||||
|
||||
pathfindsuccess =
|
||||
K_PathfindToWaypoint(checkwaypoint, finishline, &pathtofinish, useshortcuts, huntbackwards);
|
||||
|
||||
if (pathfindsuccess == true)
|
||||
{
|
||||
if ((INT32)(pathtofinish.totaldist) < *bestfindist)
|
||||
{
|
||||
*bestwaypoint = checkwaypoint;
|
||||
*bestfindist = pathtofinish.totaldist;
|
||||
}
|
||||
|
||||
Z_Free(pathtofinish.array);
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj)
|
||||
|
||||
|
|
@ -292,30 +326,18 @@ waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj)
|
|||
|
||||
rad = (checkwaypoint->mobj->radius / FRACUNIT);
|
||||
|
||||
if (closestdist < rad && checkdist < rad && finishline != NULL)
|
||||
// remember: huge radius
|
||||
if (closestdist <= rad && checkdist <= rad && finishline != NULL)
|
||||
{
|
||||
const boolean useshortcuts = false;
|
||||
const boolean huntbackwards = false;
|
||||
boolean pathfindsuccess = false;
|
||||
path_t pathtofinish = {};
|
||||
|
||||
// If the mobj is touching multiple waypoints at once,
|
||||
// then solve ties by taking the one closest to the finish line.
|
||||
// Prevents position from flickering wildly when taking turns.
|
||||
|
||||
pathfindsuccess =
|
||||
K_PathfindToWaypoint(checkwaypoint, finishline, &pathtofinish, useshortcuts, huntbackwards);
|
||||
// For the first couple overlapping, check the previous best too.
|
||||
if (bestfindist == INT32_MAX)
|
||||
K_CompareOverlappingWaypoint(bestwaypoint, &bestwaypoint, &bestfindist);
|
||||
|
||||
if (pathfindsuccess == true)
|
||||
{
|
||||
if ((INT32)(pathtofinish.totaldist) < bestfindist)
|
||||
{
|
||||
bestwaypoint = checkwaypoint;
|
||||
bestfindist = pathtofinish.totaldist;
|
||||
}
|
||||
|
||||
Z_Free(pathtofinish.array);
|
||||
}
|
||||
K_CompareOverlappingWaypoint(checkwaypoint, &bestwaypoint, &bestfindist);
|
||||
}
|
||||
else if (checkdist < closestdist && bestfindist == INT32_MAX)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue