From b49fa1deb2fad6027a666dc97079260cd504ef68 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 18 Jun 2023 17:57:00 +0900 Subject: [PATCH] remove FindLocalNeighbourhoodResult --- src/DotRecast.Detour.Crowd/DtLocalBoundary.cs | 19 ++++--- src/DotRecast.Detour/DtNavMeshQuery.cs | 53 +++++++++---------- .../FindLocalNeighbourhoodResult.cs | 47 ---------------- .../Tools/TestNavmeshTool.cs | 8 +-- .../FindLocalNeighbourhoodTest.cs | 10 ++-- 5 files changed, 42 insertions(+), 95 deletions(-) delete mode 100644 src/DotRecast.Detour/QueryResults/FindLocalNeighbourhoodResult.cs diff --git a/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs b/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs index ed1b2a6..bccfde2 100644 --- a/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs +++ b/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs @@ -31,10 +31,10 @@ namespace DotRecast.Detour.Crowd { public const int MAX_LOCAL_SEGS = 8; - - RcVec3f m_center = new RcVec3f(); - List m_segs = new List(); - List m_polys = new List(); + private RcVec3f m_center = new RcVec3f(); + private List m_segs = new List(); + private List m_polys = new List(); + private List m_parents = new List(); public DtLocalBoundary() { @@ -90,21 +90,20 @@ namespace DotRecast.Detour.Crowd } } - public void Update(long refs, RcVec3f pos, float collisionQueryRange, DtNavMeshQuery navquery, IDtQueryFilter filter) + public void Update(long startRef, RcVec3f pos, float collisionQueryRange, DtNavMeshQuery navquery, IDtQueryFilter filter) { - if (refs == 0) + if (startRef == 0) { Reset(); return; } m_center = pos; + // First query non-overlapping polygons. - Result res = navquery.FindLocalNeighbourhood(refs, pos, collisionQueryRange, - filter); - if (res.Succeeded()) + var status = navquery.FindLocalNeighbourhood(startRef, pos, collisionQueryRange, filter, ref m_polys, ref m_parents); + if (status.Succeeded()) { - m_polys = res.result.GetRefs(); m_segs.Clear(); // Secondly, store all polygon edges. for (int j = 0; j < m_polys.Count; ++j) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 04b9bb4..fb1d0c4 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -2761,49 +2761,48 @@ namespace DotRecast.Detour /// @par /// - /// This method is optimized for a small search radius and small number of result + /// This method is optimized for a small search radius and small number of result /// polygons. /// - /// Candidate polygons are found by searching the navigation graph beginning at + /// Candidate polygons are found by searching the navigation graph beginning at /// the start polygon. /// - /// The same intersection test restrictions that apply to the findPolysAroundCircle + /// The same intersection test restrictions that apply to the findPolysAroundCircle /// mehtod applies to this method. /// - /// The value of the center point is used as the start point for cost calculations. - /// It is not projected onto the surface of the mesh, so its y-value will effect + /// The value of the center point is used as the start point for cost calculations. + /// It is not projected onto the surface of the mesh, so its y-value will effect /// the costs. - /// - /// Intersection tests occur in 2D. All polygons and the search circle are - /// projected onto the xz-plane. So the y-value of the center point does not + /// + /// Intersection tests occur in 2D. All polygons and the search circle are + /// projected onto the xz-plane. So the y-value of the center point does not /// effect intersection tests. - /// - /// If the result arrays are is too small to hold the entire result set, they will + /// + /// If the result arrays are is too small to hold the entire result set, they will /// be filled to capacity. - /// + /// /// Finds the non-overlapping navigation polygons in the local neighbourhood around the center position. - /// @param[in] startRef The reference id of the polygon where the search starts. - /// @param[in] centerPos The center of the query circle. [(x, y, z)] - /// @param[in] radius The radius of the query circle. - /// @param[in] filter The polygon filter to apply to the query. - /// @param[out] resultRef The reference ids of the polygons touched by the circle. - /// @param[out] resultParent The reference ids of the parent polygons for each result. - /// Zero if a result polygon has no parent. [opt] - /// @param[out] resultCount The number of polygons found. - /// @param[in] maxResult The maximum number of polygons the result arrays can hold. + /// @param[in] startRef The reference id of the polygon where the search starts. + /// @param[in] centerPos The center of the query circle. [(x, y, z)] + /// @param[in] radius The radius of the query circle. + /// @param[in] filter The polygon filter to apply to the query. + /// @param[out] resultRef The reference ids of the polygons touched by the circle. + /// @param[out] resultParent The reference ids of the parent polygons for each result. /// @returns The status flags for the query. - public Result FindLocalNeighbourhood(long startRef, RcVec3f centerPos, float radius, - IDtQueryFilter filter) + public DtStatus FindLocalNeighbourhood(long startRef, RcVec3f centerPos, float radius, + IDtQueryFilter filter, + ref List resultRef, ref List resultParent) { + // Validate input if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || radius < 0 || !float.IsFinite(radius) || null == filter) { - return Results.InvalidParam(); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } - List resultRef = new List(); - List resultParent = new List(); + resultRef.Clear(); + resultParent.Clear(); DtNodePool tinyNodePool = new DtNodePool(); @@ -2943,7 +2942,7 @@ namespace DotRecast.Detour } } - return Results.Success(new FindLocalNeighbourhoodResult(resultRef, resultParent)); + return DtStatus.DT_SUCCSESS; } @@ -3124,7 +3123,7 @@ namespace DotRecast.Detour hitDist = 0; hitPos = RcVec3f.Zero; hitNormal = RcVec3f.Zero; - + // Validate input if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || maxRadius < 0 || !float.IsFinite(maxRadius) || null == filter) diff --git a/src/DotRecast.Detour/QueryResults/FindLocalNeighbourhoodResult.cs b/src/DotRecast.Detour/QueryResults/FindLocalNeighbourhoodResult.cs deleted file mode 100644 index 8a426b2..0000000 --- a/src/DotRecast.Detour/QueryResults/FindLocalNeighbourhoodResult.cs +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright (c) 2009-2010 Mikko Mononen memon@inside.org -recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org -DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -using System.Collections.Generic; - -namespace DotRecast.Detour.QueryResults -{ -//TODO: (PP) Add comments - public class FindLocalNeighbourhoodResult - { - private readonly List refs; - private readonly List parentRefs; - - public FindLocalNeighbourhoodResult(List refs, List parentRefs) - { - this.@refs = refs; - this.parentRefs = parentRefs; - } - - public List GetRefs() - { - return refs; - } - - public List GetParentRefs() - { - return parentRefs; - } - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 5690f59..5533369 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -472,13 +472,7 @@ public class TestNavmeshTool : IRcTool if (m_sposSet && m_startRef != 0) { m_neighbourhoodRadius = _impl.GetSample().GetSettings().agentRadius * 20.0f; - Result result = m_navQuery.FindLocalNeighbourhood(m_startRef, m_spos, - m_neighbourhoodRadius, m_filter); - if (result.Succeeded()) - { - m_polys = result.result.GetRefs(); - m_parent = result.result.GetParentRefs(); - } + m_navQuery.FindLocalNeighbourhood(m_startRef, m_spos, m_neighbourhoodRadius, m_filter, ref m_polys, ref m_parent); } } else if (m_toolMode == TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE) diff --git a/test/DotRecast.Detour.Test/FindLocalNeighbourhoodTest.cs b/test/DotRecast.Detour.Test/FindLocalNeighbourhoodTest.cs index 32d08a2..4af574d 100644 --- a/test/DotRecast.Detour.Test/FindLocalNeighbourhoodTest.cs +++ b/test/DotRecast.Detour.Test/FindLocalNeighbourhoodTest.cs @@ -16,8 +16,8 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ +using System.Collections.Generic; using DotRecast.Core; -using DotRecast.Detour.QueryResults; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -58,11 +58,13 @@ public class FindLocalNeighbourhoodTest : AbstractDetourTest for (int i = 0; i < startRefs.Length; i++) { RcVec3f startPos = startPoss[i]; - Result poly = query.FindLocalNeighbourhood(startRefs[i], startPos, 3.5f, filter); - Assert.That(poly.result.GetRefs().Count, Is.EqualTo(REFS[i].Length)); + var refs = new List(); + var parentRefs = new List(); + var status = query.FindLocalNeighbourhood(startRefs[i], startPos, 3.5f, filter, ref refs, ref parentRefs); + Assert.That(refs.Count, Is.EqualTo(REFS[i].Length)); for (int v = 0; v < REFS[i].Length; v++) { - Assert.That(poly.result.GetRefs()[v], Is.EqualTo(REFS[i][v])); + Assert.That(refs[v], Is.EqualTo(REFS[i][v])); } } }