diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 2c2117e..0df7c70 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -575,7 +575,7 @@ namespace DotRecast.Detour nearestRef = 0; nearestPt = center; isOverPoly = false; - + // Get nearby polygons from proximity grid. DtFindNearestPolyQuery query = new DtFindNearestPolyQuery(this, center); DtStatus status = QueryPolygons(center, halfExtents, filter, query); @@ -2416,35 +2416,36 @@ namespace DotRecast.Detour /// If the result arrays are to small to hold the entire result set, they will be /// filled to capacity. /// - /// @} + ///@} /// @name Dijkstra Search Functions - /// @{ + /// @{ /// Finds the polygons along the navigation graph that touch the specified circle. - /// @param[in] startRef The reference id of the polygon where the search starts. - /// @param[in] centerPos The center of the search circle. [(x, y, z)] - /// @param[in] radius The radius of the search 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. [opt] - /// @param[out] resultParent The reference ids of the parent polygons for each result. - /// Zero if a result polygon has no parent. [opt] - /// @param[out] resultCost The search cost from @p centerPos to the polygon. [opt] - /// @param[out] resultCount The number of polygons found. [opt] - /// @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 search circle. [(x, y, z)] + /// @param[in] radius The radius of the search 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. [opt] + /// @param[out] resultParent The reference ids of the parent polygons for each result. + /// Zero if a result polygon has no parent. [opt] + /// @param[out] resultCost The search cost from @p centerPos to the polygon. [opt] + /// @param[out] resultCount The number of polygons found. [opt] + /// @param[in] maxResult The maximum number of polygons the result arrays can hold. /// @returns The status flags for the query. - public Result FindPolysAroundCircle(long startRef, RcVec3f centerPos, float radius, IDtQueryFilter filter) + public DtStatus FindPolysAroundCircle(long startRef, RcVec3f centerPos, float radius, IDtQueryFilter filter, + out List resultRef, out List resultParent, out List resultCost) { - // Validate input + // TODO : check performance + resultRef = new List(); + resultParent = new List(); + resultCost = new List(); + // 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(); - List resultCost = new List(); - m_nodePool.Clear(); m_openList.Clear(); @@ -2564,57 +2565,58 @@ namespace DotRecast.Detour } } - return Results.Success(new FindPolysAroundResult(resultRef, resultParent, resultCost)); + return DtStatus.DT_SUCCSESS; } /// @par /// /// The order of the result set is from least to highest cost. - /// + /// /// At least one result array must be provided. /// - /// A common use case for this method is to perform Dijkstra searches. - /// Candidate polygons are found by searching the graph beginning at the start + /// A common use case for this method is to perform Dijkstra searches. + /// Candidate polygons are found by searching the graph beginning at the start /// polygon. - /// - /// The same intersection test restrictions that apply to FindPolysAroundCircle() + /// + /// The same intersection test restrictions that apply to findPolysAroundCircle() /// method apply to this method. - /// - /// The 3D centroid of the search polygon is used as the start position for cost + /// + /// The 3D centroid of the search polygon is used as the start position for cost /// calculations. - /// - /// Intersection tests occur in 2D. All polygons are projected onto the + /// + /// Intersection tests occur in 2D. All polygons are projected onto the /// xz-plane. So the y-values of the vertices do 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 polygons along the naviation graph that touch the specified convex polygon. - /// @param[in] startRef The reference id of the polygon where the search starts. - /// @param[in] verts The vertices describing the convex polygon. (CCW) - /// [(x, y, z) * @p nverts] - /// @param[in] nverts The number of vertices in the polygon. - /// @param[in] filter The polygon filter to apply to the query. - /// @param[out] resultRef The reference ids of the polygons touched by the search polygon. [opt] - /// @param[out] resultParent The reference ids of the parent polygons for each result. Zero if a - /// result polygon has no parent. [opt] - /// @param[out] resultCost The search cost from the centroid point to the polygon. [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] verts The vertices describing the convex polygon. (CCW) + /// [(x, y, z) * @p nverts] + /// @param[in] nverts The number of vertices in the polygon. + /// @param[in] filter The polygon filter to apply to the query. + /// @param[out] resultRef The reference ids of the polygons touched by the search polygon. [opt] + /// @param[out] resultParent The reference ids of the parent polygons for each result. Zero if a + /// result polygon has no parent. [opt] + /// @param[out] resultCost The search cost from the centroid point to the polygon. [opt] + /// @param[out] resultCount The number of polygons found. + /// @param[in] maxResult The maximum number of polygons the result arrays can hold. /// @returns The status flags for the query. - public Result FindPolysAroundShape(long startRef, float[] verts, IDtQueryFilter filter) + public DtStatus FindPolysAroundShape(long startRef, float[] verts, IDtQueryFilter filter, + out List resultRef, out List resultParent, out List resultCost) { + resultRef = new List(); + resultParent = new List(); + resultCost = new List(); + // Validate input int nverts = verts.Length / 3; if (!m_nav.IsValidPolyRef(startRef) || null == verts || nverts < 3 || null == filter) { - return Results.InvalidParam(); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } - List resultRef = new List(); - List resultParent = new List(); - List resultCost = new List(); - m_nodePool.Clear(); m_openList.Clear(); @@ -2751,7 +2753,7 @@ namespace DotRecast.Detour } } - return Results.Success(new FindPolysAroundResult(resultRef, resultParent, resultCost)); + return DtStatus.DT_SUCCSESS; } /// @par diff --git a/src/DotRecast.Detour/QueryResults/FindPolysAroundResult.cs b/src/DotRecast.Detour/QueryResults/FindPolysAroundResult.cs deleted file mode 100644 index c93b29c..0000000 --- a/src/DotRecast.Detour/QueryResults/FindPolysAroundResult.cs +++ /dev/null @@ -1,54 +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 FindPolysAroundResult - { - private readonly List refs; - private readonly List parentRefs; - private readonly List costs; - - public FindPolysAroundResult(List refs, List parentRefs, List costs) - { - this.@refs = refs; - this.parentRefs = parentRefs; - this.costs = costs; - } - - public List GetRefs() - { - return refs; - } - - public List GetParentRefs() - { - return parentRefs; - } - - public List GetCosts() - { - return costs; - } - } -} \ 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 432f077..e0a9448 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -425,12 +425,11 @@ public class TestNavmeshTool : ITool float dx = m_epos.x - m_spos.x; float dz = m_epos.z - m_spos.z; float dist = (float)Math.Sqrt(dx * dx + dz * dz); - Result result = m_navQuery.FindPolysAroundCircle(m_startRef, m_spos, dist, - m_filter); - if (result.Succeeded()) + var status = m_navQuery.FindPolysAroundCircle(m_startRef, m_spos, dist, m_filter, out var refs, out var parentRefs, out var costs); + if (status.Succeeded()) { - m_polys = result.result.GetRefs(); - m_parent = result.result.GetParentRefs(); + m_polys = refs; + m_parent = parentRefs; } } } @@ -458,11 +457,11 @@ public class TestNavmeshTool : ITool m_queryPoly[10] = m_epos.y + agentHeight / 2; m_queryPoly[11] = m_epos.z + nz; - Result result = m_navQuery.FindPolysAroundShape(m_startRef, m_queryPoly, m_filter); - if (result.Succeeded()) + var status = m_navQuery.FindPolysAroundShape(m_startRef, m_queryPoly, m_filter, out var refs, out var parentRefs, out var costs); + if (status.Succeeded()) { - m_polys = result.result.GetRefs(); - m_parent = result.result.GetParentRefs(); + m_polys = refs; + m_parent = parentRefs; } } } diff --git a/test/DotRecast.Detour.Test/FindPolysAroundCircleTest.cs b/test/DotRecast.Detour.Test/FindPolysAroundCircleTest.cs index 3a8f931..abf03bb 100644 --- a/test/DotRecast.Detour.Test/FindPolysAroundCircleTest.cs +++ b/test/DotRecast.Detour.Test/FindPolysAroundCircleTest.cs @@ -106,19 +106,19 @@ public class FindPolysAroundCircleTest : AbstractDetourTest { long startRef = startRefs[i]; RcVec3f startPos = startPoss[i]; - Result result = query.FindPolysAroundCircle(startRef, startPos, 7.5f, filter); - Assert.That(result.Succeeded(), Is.True); - FindPolysAroundResult polys = result.result; - Assert.That(polys.GetRefs().Count, Is.EqualTo(REFS[i].Length)); + var status = query.FindPolysAroundCircle(startRef, startPos, 7.5f, filter, out var refs, out var parentRefs, out var costs); + Assert.That(status.Succeeded(), Is.True); + + Assert.That(refs.Count, Is.EqualTo(REFS[i].Length)); for (int v = 0; v < REFS[i].Length; v++) { bool found = false; for (int w = 0; w < REFS[i].Length; w++) { - if (REFS[i][v] == polys.GetRefs()[w]) + if (REFS[i][v] == refs[w]) { - Assert.That(polys.GetParentRefs()[w], Is.EqualTo(PARENT_REFS[i][v])); - Assert.That(polys.GetCosts()[w], Is.EqualTo(COSTS[i][v]).Within(0.01f)); + Assert.That(parentRefs[w], Is.EqualTo(PARENT_REFS[i][v])); + Assert.That(costs[w], Is.EqualTo(COSTS[i][v]).Within(0.01f)); found = true; } } diff --git a/test/DotRecast.Detour.Test/FindPolysAroundShapeTest.cs b/test/DotRecast.Detour.Test/FindPolysAroundShapeTest.cs index d45b2f3..27d5bf4 100644 --- a/test/DotRecast.Detour.Test/FindPolysAroundShapeTest.cs +++ b/test/DotRecast.Detour.Test/FindPolysAroundShapeTest.cs @@ -133,17 +133,17 @@ public class FindPolysAroundShapeTest : AbstractDetourTest { long startRef = startRefs[i]; RcVec3f startPos = startPoss[i]; - Result polys = query.FindPolysAroundShape(startRef, GetQueryPoly(startPos, endPoss[i]), filter); - Assert.That(polys.result.GetRefs().Count, Is.EqualTo(REFS[i].Length)); + query.FindPolysAroundShape(startRef, GetQueryPoly(startPos, endPoss[i]), filter, out var refs, out var parentRefs, out var costs); + Assert.That(refs.Count, Is.EqualTo(REFS[i].Length)); for (int v = 0; v < REFS[i].Length; v++) { bool found = false; for (int w = 0; w < REFS[i].Length; w++) { - if (REFS[i][v] == polys.result.GetRefs()[w]) + if (REFS[i][v] == refs[w]) { - Assert.That(polys.result.GetParentRefs()[w], Is.EqualTo(PARENT_REFS[i][v])); - Assert.That(polys.result.GetCosts()[w], Is.EqualTo(COSTS[i][v]).Within(0.01f)); + Assert.That(parentRefs[w], Is.EqualTo(PARENT_REFS[i][v])); + Assert.That(costs[w], Is.EqualTo(COSTS[i][v]).Within(0.01f)); found = true; } } @@ -177,4 +177,4 @@ public class FindPolysAroundShapeTest : AbstractDetourTest m_queryPoly[11] = m_epos.z + nz; return m_queryPoly; } -} +} \ No newline at end of file