From 83da4196e4bf27561f7969dcbaa1732354ae702b Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 10 Jun 2023 22:34:53 +0900 Subject: [PATCH] remove FindRandomPointResult 3st --- src/DotRecast.Detour/DtNavMeshQuery.cs | 38 ++++++++++--------- src/DotRecast.Detour/DtNodePool.cs | 1 - .../Tools/TestNavmeshTool.cs | 10 ++--- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 0a9bb31..3215eeb 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -202,11 +202,7 @@ namespace DotRecast.Detour public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius, IDtQueryFilter filter, FRand frand, out long randomRef, out RcVec3f randomPt) { - var result = FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, NoOpPolygonByCircleConstraint.Noop); - randomRef = result.result.GetRandomRef(); - randomPt = result.result.GetRandomPt(); - - return result.status; + return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, NoOpPolygonByCircleConstraint.Noop, out randomRef, out randomPt); } /** @@ -227,28 +223,27 @@ namespace DotRecast.Detour public DtStatus FindRandomPointWithinCircle(long startRef, RcVec3f centerPos, float maxRadius, IDtQueryFilter filter, FRand frand, out long randomRef, out RcVec3f randomPt) { - var result = FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, StrictPolygonByCircleConstraint.Strict); - randomRef = result.result.GetRandomRef(); - randomPt = result.result.GetRandomPt(); - - return result.status; + return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, StrictPolygonByCircleConstraint.Strict, out randomRef, out randomPt); } - public Result FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius, - IDtQueryFilter filter, FRand frand, - IPolygonByCircleConstraint constraint) + public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius, + IDtQueryFilter filter, FRand frand, IPolygonByCircleConstraint constraint, + out long randomRef, out RcVec3f randomPt) { + randomRef = startRef; + randomPt = centerPos; + // Validate input if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || maxRadius < 0 || !float.IsFinite(maxRadius) || null == filter || null == frand) { - return Results.InvalidParam(); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } m_nav.GetTileAndPolyByRefUnsafe(startRef, out var startTile, out var startPoly); if (!filter.PassFilter(startRef, startTile, startPoly)) { - return Results.InvalidParam("Invalid start ref"); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } m_nodePool.Clear(); @@ -263,6 +258,8 @@ namespace DotRecast.Detour startNode.flags = DT_NODE_OPEN; m_openList.Push(startNode); + DtStatus status = DtStatus.DT_SUCCSESS; + float radiusSqr = maxRadius * maxRadius; float areaSum = 0.0f; @@ -360,6 +357,11 @@ namespace DotRecast.Detour } DtNode neighbourNode = m_nodePool.GetNode(neighbourRef); + if (null == neighbourNode) + { + status |= DtStatus.DT_OUT_OF_NODES; + continue; + } if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0) { @@ -399,7 +401,7 @@ namespace DotRecast.Detour if (randomPoly == null) { - return Results.Failure(); + return DtStatus.DT_FAILURE; } // Randomly pick point on polygon. @@ -409,7 +411,9 @@ namespace DotRecast.Detour float[] areas = new float[randomPolyVerts.Length / 3]; RcVec3f pt = DetourCommon.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t); ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _); - return Results.Success(new FindRandomPointResult(randomPolyRef, closest)); + Results.Success(new FindRandomPointResult(randomPolyRef, closest)); + + return status; } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/DotRecast.Detour/DtNodePool.cs b/src/DotRecast.Detour/DtNodePool.cs index 50d16b7..525451d 100644 --- a/src/DotRecast.Detour/DtNodePool.cs +++ b/src/DotRecast.Detour/DtNodePool.cs @@ -64,7 +64,6 @@ namespace DotRecast.Detour public DtNode GetNode(long id, int state) { var hasNode = m_map.TryGetValue(id, out var nodes); - ; if (nodes != null) { foreach (DtNode node in nodes) diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index a99c7c0..c0e0d08 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -491,14 +491,14 @@ public class TestNavmeshTool : ITool IPolygonByCircleConstraint constraint = constrainByCircle ? StrictPolygonByCircleConstraint.Strict : NoOpPolygonByCircleConstraint.Noop; - + for (int i = 0; i < 200; i++) { - Result result = m_navQuery.FindRandomPointAroundCircle(m_startRef, m_spos, dist, - m_filter, new FRand(), constraint); - if (result.Succeeded()) + var status = m_navQuery.FindRandomPointAroundCircle(m_startRef, m_spos, dist, m_filter, new FRand(), constraint, + out var randomRef, out var randomPt); + if (status.Succeeded()) { - randomPoints.Add(result.result.GetRandomPt()); + randomPoints.Add(randomPt); } } }