From 5fd07d1e07476ae4737e9d142c2826d577498c64 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 10 Sep 2023 13:30:02 +0900 Subject: [PATCH] refactor: RANDOM_POINTS_IN_CIRCLE --- .../Tools/TestNavmeshSampleTool.cs | 12 +++--------- .../Tools/RcTestNavMeshTool.cs | 9 ++++++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs index 0ecddd9..91d9498 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs @@ -63,7 +63,7 @@ public class TestNavmeshSampleTool : ISampleTool private RcVec3f[] m_queryPoly = new RcVec3f[4]; private List m_smoothPath; private DtStatus m_pathFindStatus = DtStatus.DT_FAILURE; - private readonly List randomPoints = new(); + private List _randomPoints = new(); public TestNavmeshSampleTool() { @@ -552,7 +552,7 @@ public class TestNavmeshSampleTool : ISampleTool dd.DepthMask(false); dd.Begin(POINTS, 4.0f); int col = DuRGBA(64, 16, 0, 220); - foreach (RcVec3f point in randomPoints) + foreach (RcVec3f point in _randomPoints) { dd.Vertex(point.x, point.y + 0.1f, point.z, col); } @@ -766,13 +766,7 @@ public class TestNavmeshSampleTool : ISampleTool } else if (_mode == RcTestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE) { - randomPoints.Clear(); - if (m_sposSet && m_startRef != 0 && m_eposSet) - { - var points = new List(); - _tool.FindRandomPointAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, _constrainByCircle, _randomPointCount, ref points); - randomPoints.AddRange(points); - } + _tool.FindRandomPointAroundCircle(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, _constrainByCircle, _randomPointCount, ref _randomPoints); } } diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index 3e1a938..4c65be1 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -325,8 +325,14 @@ namespace DotRecast.Recast.Toolset.Tools return status; } - public DtStatus FindRandomPointAroundCircle(DtNavMeshQuery navQuery, long startRef, RcVec3f spos, RcVec3f epos, IDtQueryFilter filter, bool constrainByCircle, int count, ref List points) + public DtStatus FindRandomPointAroundCircle(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f spos, RcVec3f epos, IDtQueryFilter filter, bool constrainByCircle, int count, + ref List points) { + if (startRef == 0 || endRef == 0) + { + return DtStatus.DT_FAILURE; + } + float dx = epos.x - spos.x; float dz = epos.z - spos.z; float dist = (float)Math.Sqrt(dx * dx + dz * dz); @@ -338,6 +344,7 @@ namespace DotRecast.Recast.Toolset.Tools var frand = new FRand(); int prevCnt = points.Count; + points = new List(); while (0 < count && points.Count < prevCnt + count) { var status = navQuery.FindRandomPointAroundCircle(startRef, spos, dist, filter, frand, constraint,