remove GetPolyWallSegmentsResult

This commit is contained in:
ikpil 2023-06-19 23:10:48 +09:00
parent d146a57d62
commit 00713fa2b1
5 changed files with 36 additions and 83 deletions

View File

@ -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<SegmentVert>();
var segmentRefs = new List<long>();
for (int j = 0; j < m_polys.Count; ++j)
{
Result<GetPolyWallSegmentsResult> 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]);

View File

@ -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<GetPolyWallSegmentsResult> GetPolyWallSegments(long refs, bool storePortals, IDtQueryFilter filter)
public DtStatus GetPolyWallSegments(long refs, bool storePortals, IDtQueryFilter filter,
ref List<SegmentVert> segmentVerts, ref List<long> segmentRefs)
{
segmentVerts.Clear();
segmentRefs.Clear();
var status = m_nav.GetTileAndPolyByRef(refs, out var tile, out var poly);
if (status.Failed())
{
return Results.Of<GetPolyWallSegmentsResult>(status, "");
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
}
if (null == filter)
{
return Results.InvalidParam<GetPolyWallSegmentsResult>();
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
}
List<long> segmentRefs = new List<long>();
List<SegmentVert> segmentVerts = new List<SegmentVert>();
List<DtSegInterval> ints = new List<DtSegInterval>(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

View File

@ -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<SegmentVert> _segmentVerts;
private readonly List<long> _segmentRefs;
public GetPolyWallSegmentsResult(List<SegmentVert> segmentVerts, List<long> 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];
}
}
}

View File

@ -816,6 +816,9 @@ public class TestNavmeshTool : IRcTool
{
if (m_polys != null)
{
var segmentVerts = new List<SegmentVert>();
var segmentRefs = new List<long>();
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<GetPolyWallSegmentsResult> 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);

View File

@ -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<SegmentVert>();
var segmentRefs = new List<long>();
IDtQueryFilter filter = new DtQueryDefaultFilter();
for (int i = 0; i < startRefs.Length; i++)
{
Result<GetPolyWallSegmentsResult> 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]));
}
}
}