forked from bit/DotRecastNetSim
add DtfindPathOption
This commit is contained in:
parent
828ada3ea4
commit
33399c0348
|
@ -0,0 +1,23 @@
|
||||||
|
namespace DotRecast.Detour
|
||||||
|
{
|
||||||
|
public readonly struct DtFindPathOption
|
||||||
|
{
|
||||||
|
public static readonly DtFindPathOption Zero = new DtFindPathOption(DefaultQueryHeuristic.Default, 0, 0);
|
||||||
|
|
||||||
|
public readonly IQueryHeuristic heuristic;
|
||||||
|
public readonly int options;
|
||||||
|
public readonly float raycastLimit;
|
||||||
|
|
||||||
|
public DtFindPathOption(IQueryHeuristic heuristic, int options, float raycastLimit)
|
||||||
|
{
|
||||||
|
this.heuristic = heuristic;
|
||||||
|
this.options = options;
|
||||||
|
this.raycastLimit = raycastLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DtFindPathOption(int options, float raycastLimit)
|
||||||
|
: this(DefaultQueryHeuristic.Default, options, raycastLimit)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -764,19 +764,7 @@ namespace DotRecast.Detour
|
||||||
* The polygon filter to apply to the query.
|
* The polygon filter to apply to the query.
|
||||||
* @return Found path
|
* @return Found path
|
||||||
*/
|
*/
|
||||||
public virtual Result<List<long>> FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter)
|
public Result<List<long>> FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, DtFindPathOption fpo)
|
||||||
{
|
|
||||||
return FindPath(startRef, endRef, startPos, endPos, filter, DefaultQueryHeuristic.Default, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual Result<List<long>> FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter,
|
|
||||||
int options, float raycastLimit)
|
|
||||||
{
|
|
||||||
return FindPath(startRef, endRef, startPos, endPos, filter, DefaultQueryHeuristic.Default, options, raycastLimit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Result<List<long>> FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter,
|
|
||||||
IQueryHeuristic heuristic, int options, float raycastLimit)
|
|
||||||
{
|
{
|
||||||
// Validate input
|
// Validate input
|
||||||
if (!m_nav.IsValidPolyRef(startRef) || !m_nav.IsValidPolyRef(endRef) || !RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) || null == filter)
|
if (!m_nav.IsValidPolyRef(startRef) || !m_nav.IsValidPolyRef(endRef) || !RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) || null == filter)
|
||||||
|
@ -784,6 +772,10 @@ namespace DotRecast.Detour
|
||||||
return Results.InvalidParam<List<long>>();
|
return Results.InvalidParam<List<long>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var heuristic = fpo.heuristic;
|
||||||
|
var raycastLimit = fpo.raycastLimit;
|
||||||
|
var options = fpo.options;
|
||||||
|
|
||||||
float raycastLimitSqr = Sqr(raycastLimit);
|
float raycastLimitSqr = Sqr(raycastLimit);
|
||||||
|
|
||||||
// trade quality with performance?
|
// trade quality with performance?
|
||||||
|
|
|
@ -197,7 +197,7 @@ public class TestNavmeshTool : IRcTool
|
||||||
if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0)
|
if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0)
|
||||||
{
|
{
|
||||||
m_polys = m_navQuery.FindPath(m_startRef, m_endRef, m_spos, m_epos, m_filter,
|
m_polys = m_navQuery.FindPath(m_startRef, m_endRef, m_spos, m_epos, m_filter,
|
||||||
enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue).result;
|
new(enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue)).result;
|
||||||
if (0 < m_polys.Count)
|
if (0 < m_polys.Count)
|
||||||
{
|
{
|
||||||
List<long> polys = new(m_polys);
|
List<long> polys = new(m_polys);
|
||||||
|
@ -331,7 +331,7 @@ public class TestNavmeshTool : IRcTool
|
||||||
if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0)
|
if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0)
|
||||||
{
|
{
|
||||||
m_polys = m_navQuery.FindPath(m_startRef, m_endRef, m_spos, m_epos, m_filter,
|
m_polys = m_navQuery.FindPath(m_startRef, m_endRef, m_spos, m_epos, m_filter,
|
||||||
enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue).result;
|
new(enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue)).result;
|
||||||
if (0 < m_polys.Count)
|
if (0 < m_polys.Count)
|
||||||
{
|
{
|
||||||
// In case of partial path, make sure the end point is clamped to the last polygon.
|
// In case of partial path, make sure the end point is clamped to the last polygon.
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class DynamicNavMeshTest
|
||||||
query.FindNearestPoly(START_POS, EXTENT, filter, out var startRef, out var startPt, out var _);
|
query.FindNearestPoly(START_POS, EXTENT, filter, out var startRef, out var startPt, out var _);
|
||||||
query.FindNearestPoly(END_POS, EXTENT, filter, out var endRef, out var endPt, out var _);
|
query.FindNearestPoly(END_POS, EXTENT, filter, out var endRef, out var endPt, out var _);
|
||||||
|
|
||||||
List<long> path = query.FindPath(startRef, endRef, startPt, endPt, filter, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue).result;
|
List<long> path = query.FindPath(startRef, endRef, startPt, endPt, filter, new(DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue)).result;
|
||||||
// check path length without any obstacles
|
// check path length without any obstacles
|
||||||
Assert.That(path.Count, Is.EqualTo(16));
|
Assert.That(path.Count, Is.EqualTo(16));
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ public class DynamicNavMeshTest
|
||||||
// find path again
|
// find path again
|
||||||
query.FindNearestPoly(START_POS, EXTENT, filter, out startRef, out startPt, out var _);
|
query.FindNearestPoly(START_POS, EXTENT, filter, out startRef, out startPt, out var _);
|
||||||
query.FindNearestPoly(END_POS, EXTENT, filter, out endRef, out endPt, out var _);
|
query.FindNearestPoly(END_POS, EXTENT, filter, out endRef, out endPt, out var _);
|
||||||
path = query.FindPath(startRef, endRef, startPt, endPt, filter, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue).result;
|
path = query.FindPath(startRef, endRef, startPt, endPt, filter, new(DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue)).result;
|
||||||
|
|
||||||
// check path length with obstacles
|
// check path length with obstacles
|
||||||
Assert.That(path.Count, Is.EqualTo(19));
|
Assert.That(path.Count, Is.EqualTo(19));
|
||||||
// remove obstacle
|
// remove obstacle
|
||||||
|
@ -73,12 +73,12 @@ public class DynamicNavMeshTest
|
||||||
_ = future.Result;
|
_ = future.Result;
|
||||||
// create new query
|
// create new query
|
||||||
query = new DtNavMeshQuery(mesh.NavMesh());
|
query = new DtNavMeshQuery(mesh.NavMesh());
|
||||||
|
|
||||||
// find path one more time
|
// find path one more time
|
||||||
query.FindNearestPoly(START_POS, EXTENT, filter, out startRef, out startPt, out var _);
|
query.FindNearestPoly(START_POS, EXTENT, filter, out startRef, out startPt, out var _);
|
||||||
query.FindNearestPoly(END_POS, EXTENT, filter, out endRef, out endPt, out var _);
|
query.FindNearestPoly(END_POS, EXTENT, filter, out endRef, out endPt, out var _);
|
||||||
path = query.FindPath(startRef, endRef, startPt, endPt, filter, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue).result;
|
path = query.FindPath(startRef, endRef, startPt, endPt, filter, new(DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue)).result;
|
||||||
|
|
||||||
// path length should be back to the initial value
|
// path length should be back to the initial value
|
||||||
Assert.That(path.Count, Is.EqualTo(16));
|
Assert.That(path.Count, Is.EqualTo(16));
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class UnityAStarPathfindingImporterTest
|
||||||
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
||||||
|
|
||||||
var polys = GetNearestPolys(mesh, startPos, endPos);
|
var polys = GetNearestPolys(mesh, startPos, endPos);
|
||||||
return query.FindPath(polys[0].refs, polys[1].refs, startPos, endPos, filter);
|
return query.FindPath(polys[0].refs, polys[1].refs, startPos, endPos, filter, DtFindPathOption.Zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DtPolyPoint[] GetNearestPolys(DtNavMesh mesh, params RcVec3f[] positions)
|
private DtPolyPoint[] GetNearestPolys(DtNavMesh mesh, params RcVec3f[] positions)
|
||||||
|
|
|
@ -138,7 +138,7 @@ public class FindPathTest : AbstractDetourTest
|
||||||
long endRef = endRefs[i];
|
long endRef = endRefs[i];
|
||||||
RcVec3f startPos = startPoss[i];
|
RcVec3f startPos = startPoss[i];
|
||||||
RcVec3f endPos = endPoss[i];
|
RcVec3f endPos = endPoss[i];
|
||||||
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter);
|
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero);
|
||||||
Assert.That(path.status, Is.EqualTo(STATUSES[i]));
|
Assert.That(path.status, Is.EqualTo(STATUSES[i]));
|
||||||
Assert.That(path.result.Count, Is.EqualTo(RESULTS[i].Length));
|
Assert.That(path.result.Count, Is.EqualTo(RESULTS[i].Length));
|
||||||
for (int j = 0; j < RESULTS[i].Length; j++)
|
for (int j = 0; j < RESULTS[i].Length; j++)
|
||||||
|
@ -186,7 +186,7 @@ public class FindPathTest : AbstractDetourTest
|
||||||
long endRef = endRefs[i];
|
long endRef = endRefs[i];
|
||||||
var startPos = startPoss[i];
|
var startPos = startPoss[i];
|
||||||
var endPos = endPoss[i];
|
var endPos = endPoss[i];
|
||||||
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter);
|
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero);
|
||||||
var straightPath = new List<StraightPathItem>();
|
var straightPath = new List<StraightPathItem>();
|
||||||
query.FindStraightPath(startPos, endPos, path.result, ref straightPath, int.MaxValue, 0);
|
query.FindStraightPath(startPos, endPos, path.result, ref straightPath, int.MaxValue, 0);
|
||||||
Assert.That(straightPath.Count, Is.EqualTo(STRAIGHT_PATHS[i].Length));
|
Assert.That(straightPath.Count, Is.EqualTo(STRAIGHT_PATHS[i].Length));
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class TiledFindPathTest
|
||||||
long endRef = END_REFS[i];
|
long endRef = END_REFS[i];
|
||||||
RcVec3f startPos = START_POS[i];
|
RcVec3f startPos = START_POS[i];
|
||||||
RcVec3f endPos = END_POS[i];
|
RcVec3f endPos = END_POS[i];
|
||||||
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter);
|
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero);
|
||||||
Assert.That(path.status, Is.EqualTo(STATUSES[i]));
|
Assert.That(path.status, Is.EqualTo(STATUSES[i]));
|
||||||
Assert.That(path.result.Count, Is.EqualTo(RESULTS[i].Length));
|
Assert.That(path.result.Count, Is.EqualTo(RESULTS[i].Length));
|
||||||
for (int j = 0; j < RESULTS[i].Length; j++)
|
for (int j = 0; j < RESULTS[i].Length; j++)
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class TileCacheFindPathTest : AbstractTileCacheTest
|
||||||
query.FindNearestPoly(start, extents, filter, out var startRef, out var startPos, out var _);
|
query.FindNearestPoly(start, extents, filter, out var startRef, out var startPos, out var _);
|
||||||
query.FindNearestPoly(end, extents, filter, out var endRef, out var endPos, out var _);
|
query.FindNearestPoly(end, extents, filter, out var endRef, out var endPos, out var _);
|
||||||
|
|
||||||
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter);
|
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero);
|
||||||
int maxStraightPath = 256;
|
int maxStraightPath = 256;
|
||||||
int options = 0;
|
int options = 0;
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class TileCacheNavigationTest : AbstractTileCacheTest
|
||||||
long endRef = endRefs[i];
|
long endRef = endRefs[i];
|
||||||
RcVec3f startPos = startPoss[i];
|
RcVec3f startPos = startPoss[i];
|
||||||
RcVec3f endPos = endPoss[i];
|
RcVec3f endPos = endPoss[i];
|
||||||
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter);
|
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero);
|
||||||
Assert.That(path.status, Is.EqualTo(statuses[i]));
|
Assert.That(path.status, Is.EqualTo(statuses[i]));
|
||||||
Assert.That(path.result.Count, Is.EqualTo(results[i].Length));
|
Assert.That(path.result.Count, Is.EqualTo(results[i].Length));
|
||||||
for (int j = 0; j < results[i].Length; j++)
|
for (int j = 0; j < results[i].Length; j++)
|
||||||
|
@ -110,8 +110,8 @@ public class TileCacheNavigationTest : AbstractTileCacheTest
|
||||||
long endRef = endRefs[i];
|
long endRef = endRefs[i];
|
||||||
RcVec3f startPos = startPoss[i];
|
RcVec3f startPos = startPoss[i];
|
||||||
RcVec3f endPos = endPoss[i];
|
RcVec3f endPos = endPoss[i];
|
||||||
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter, new DefaultQueryHeuristic(0.0f),
|
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter, new(new DefaultQueryHeuristic(0.0f),
|
||||||
0, 0);
|
0, 0));
|
||||||
Assert.That(path.status, Is.EqualTo(statuses[i]));
|
Assert.That(path.status, Is.EqualTo(statuses[i]));
|
||||||
Assert.That(path.result.Count, Is.EqualTo(results[i].Length));
|
Assert.That(path.result.Count, Is.EqualTo(results[i].Length));
|
||||||
for (int j = 0; j < results[i].Length; j++)
|
for (int j = 0; j < results[i].Length; j++)
|
||||||
|
|
Loading…
Reference in New Issue