From ace37833e507054efee12a3489f1539ab7766772 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 10 Sep 2023 13:53:31 +0900 Subject: [PATCH] refactor: PATHFIND_FOLLOW --- .../Tools/TestNavmeshSampleTool.cs | 21 ++----------------- .../Tools/RcTestNavMeshTool.cs | 19 ++++++++++++++--- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs index b8a103b..b73a92f 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs @@ -659,25 +659,8 @@ public class TestNavmeshSampleTool : ISampleTool if (_mode == RcTestNavmeshToolMode.PATHFIND_FOLLOW) { - if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0) - { - var polys = new List(); - var smoothPath = new List(); - - var status = _tool.FindFollowPath(navMesh, navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, _enableRaycast, - ref polys, ref smoothPath); - - if (status.Succeeded()) - { - m_polys = polys; - m_smoothPath = smoothPath; - } - } - else - { - m_polys = null; - m_smoothPath = null; - } + _tool.FindFollowPath(navMesh, navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, _enableRaycast, + ref m_polys, ref m_smoothPath); } else if (_mode == RcTestNavmeshToolMode.PATHFIND_STRAIGHT) { diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index 9cdd62d..bc0b136 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -23,9 +23,22 @@ namespace DotRecast.Recast.Toolset.Tools public DtStatus FindFollowPath(DtNavMesh navMesh, DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPt, RcVec3f endPt, IDtQueryFilter filter, bool enableRaycast, ref List polys, ref List smoothPath) { - navQuery.FindPath(startRef, endRef, startPt, endPt, filter, ref polys, - new DtFindPathOption(enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue)); + if (startRef == 0 || endRef == 0) + { + polys?.Clear(); + smoothPath?.Clear(); + return DtStatus.DT_FAILURE; + } + + polys ??= new List(); + smoothPath ??= new List(); + + polys.Clear(); + smoothPath.Clear(); + + var opt = new DtFindPathOption(enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue); + navQuery.FindPath(startRef, endRef, startPt, endPt, filter, ref polys, opt); if (0 >= polys.Count) return DtStatus.DT_FAILURE; @@ -229,7 +242,7 @@ namespace DotRecast.Recast.Toolset.Tools { return status; } - + // results ... polys = rayHit.path;