diff --git a/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs b/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs index bccfde2..f4a25dc 100644 --- a/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs +++ b/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs @@ -104,17 +104,20 @@ namespace DotRecast.Detour.Crowd var status = navquery.FindLocalNeighbourhood(startRef, pos, collisionQueryRange, filter, ref m_polys, ref m_parents); if (status.Succeeded()) { - m_segs.Clear(); // Secondly, store all polygon edges. + m_segs.Clear(); + + var segmentVerts = new List(); + var segmentRefs = new List(); + for (int j = 0; j < m_polys.Count; ++j) { - Result result = navquery.GetPolyWallSegments(m_polys[j], false, filter); + var result = navquery.GetPolyWallSegments(m_polys[j], false, filter, ref segmentVerts, ref segmentRefs); if (result.Succeeded()) { - GetPolyWallSegmentsResult gpws = result.result; - for (int k = 0; k < gpws.CountSegmentRefs(); ++k) + for (int k = 0; k < segmentRefs.Count; ++k) { - SegmentVert s = gpws.GetSegmentVert(k); + SegmentVert s = segmentVerts[k]; var s0 = RcVec3f.Of(s[0], s[1], s[2]); var s3 = RcVec3f.Of(s[3], s[4], s[5]); diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index fb1d0c4..0cbda03 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -2984,23 +2984,24 @@ namespace DotRecast.Detour /// @param[out] segmentCount The number of segments returned. /// @param[in] maxSegments The maximum number of segments the result arrays can hold. /// @returns The status flags for the query. - public Result GetPolyWallSegments(long refs, bool storePortals, IDtQueryFilter filter) + public DtStatus GetPolyWallSegments(long refs, bool storePortals, IDtQueryFilter filter, + ref List segmentVerts, ref List segmentRefs) { + segmentVerts.Clear(); + segmentRefs.Clear(); + var status = m_nav.GetTileAndPolyByRef(refs, out var tile, out var poly); if (status.Failed()) { - return Results.Of(status, ""); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } if (null == filter) { - return Results.InvalidParam(); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } - List segmentRefs = new List(); - List segmentVerts = new List(); List ints = new List(16); - for (int i = 0, j = poly.vertCount - 1; i < poly.vertCount; j = i++) { // Skip non-solid edges. @@ -3093,7 +3094,7 @@ namespace DotRecast.Detour } } - return Results.Success(new GetPolyWallSegmentsResult(segmentVerts, segmentRefs)); + return DtStatus.DT_SUCCSESS; } /// @par diff --git a/src/DotRecast.Detour/QueryResults/GetPolyWallSegmentsResult.cs b/src/DotRecast.Detour/QueryResults/GetPolyWallSegmentsResult.cs deleted file mode 100644 index a1db720..0000000 --- a/src/DotRecast.Detour/QueryResults/GetPolyWallSegmentsResult.cs +++ /dev/null @@ -1,58 +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; -using DotRecast.Core; - -namespace DotRecast.Detour.QueryResults -{ - public class GetPolyWallSegmentsResult - { - private readonly List _segmentVerts; - private readonly List _segmentRefs; - - public GetPolyWallSegmentsResult(List segmentVerts, List segmentRefs) - { - _segmentVerts = segmentVerts; - _segmentRefs = segmentRefs; - } - - public int CountSegmentVerts() - { - return _segmentVerts.Count; - } - - public int CountSegmentRefs() - { - return _segmentRefs.Count; - } - - - public SegmentVert GetSegmentVert(int idx) - { - return _segmentVerts[idx]; - } - - public long GetSegmentRef(int idx) - { - return _segmentRefs[idx]; - } - } -} \ 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 5533369..24e7e3f 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -816,6 +816,9 @@ public class TestNavmeshTool : IRcTool { if (m_polys != null) { + var segmentVerts = new List(); + var segmentRefs = new List(); + for (int i = 0; i < m_polys.Count; i++) { dd.DebugDrawNavMeshPoly(m_navMesh, m_polys[i], pathCol); @@ -833,15 +836,16 @@ public class TestNavmeshTool : IRcTool dd.DepthMask(true); if (_impl.GetSample().GetNavMeshQuery() != null) { - Result result = _impl.GetSample().GetNavMeshQuery() - .GetPolyWallSegments(m_polys[i], false, m_filter); + var result = _impl.GetSample() + .GetNavMeshQuery() + .GetPolyWallSegments(m_polys[i], false, m_filter, ref segmentVerts, ref segmentRefs); + if (result.Succeeded()) { dd.Begin(LINES, 2.0f); - GetPolyWallSegmentsResult wallSegments = result.result; - for (int j = 0; j < wallSegments.CountSegmentVerts(); ++j) + for (int j = 0; j < segmentVerts.Count; ++j) { - SegmentVert s = wallSegments.GetSegmentVert(j); + SegmentVert s = segmentVerts[j]; var v0 = RcVec3f.Of(s[0], s[1], s[2]); var s3 = RcVec3f.Of(s[3], s[4], s[5]); // Skip too distant segments. @@ -857,7 +861,7 @@ public class TestNavmeshTool : IRcTool norm.Normalize(); RcVec3f p1 = RcVec3f.Mad(p0, norm, agentRadius * 0.5f); // Skip backfacing segments. - if (wallSegments.GetSegmentRef(j) != 0) + if (segmentRefs[j] != 0) { int col = DuRGBA(255, 255, 255, 32); dd.Vertex(s[0], s[1] + agentClimb, s[2], col); diff --git a/test/DotRecast.Detour.Test/GetPolyWallSegmentsTest.cs b/test/DotRecast.Detour.Test/GetPolyWallSegmentsTest.cs index 85bab14..a7b2004 100644 --- a/test/DotRecast.Detour.Test/GetPolyWallSegmentsTest.cs +++ b/test/DotRecast.Detour.Test/GetPolyWallSegmentsTest.cs @@ -16,7 +16,8 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -using DotRecast.Detour.QueryResults; +using System.Collections.Generic; +using DotRecast.Core; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -77,24 +78,26 @@ public class GetPolyWallSegmentsTest : AbstractDetourTest [Test] public void TestFindDistanceToWall() { + var segmentVerts = new List(); + var segmentRefs = new List(); + IDtQueryFilter filter = new DtQueryDefaultFilter(); for (int i = 0; i < startRefs.Length; i++) { - Result result = query.GetPolyWallSegments(startRefs[i], true, filter); - GetPolyWallSegmentsResult segments = result.result; - Assert.That(segments.CountSegmentVerts(), Is.EqualTo(VERTICES[i].Length / 6)); - Assert.That(segments.CountSegmentRefs(), Is.EqualTo(REFS[i].Length)); + var result = query.GetPolyWallSegments(startRefs[i], true, filter, ref segmentVerts, ref segmentRefs); + Assert.That(segmentVerts.Count, Is.EqualTo(VERTICES[i].Length / 6)); + Assert.That(segmentRefs.Count, Is.EqualTo(REFS[i].Length)); for (int v = 0; v < VERTICES[i].Length / 6; v++) { for (int n = 0; n < 6; n++) { - Assert.That(segments.GetSegmentVert(v)[n], Is.EqualTo(VERTICES[i][v * 6 + n]).Within(0.001f)); + Assert.That(segmentVerts[v][n], Is.EqualTo(VERTICES[i][v * 6 + n]).Within(0.001f)); } } for (int v = 0; v < REFS[i].Length; v++) { - Assert.That(segments.GetSegmentRef(v), Is.EqualTo(REFS[i][v])); + Assert.That(segmentRefs[v], Is.EqualTo(REFS[i][v])); } } }