remove FindLocalNeighbourhoodResult

This commit is contained in:
ikpil 2023-06-18 17:57:00 +09:00
parent 2392b446f7
commit b49fa1deb2
5 changed files with 42 additions and 95 deletions

View File

@ -31,10 +31,10 @@ namespace DotRecast.Detour.Crowd
{ {
public const int MAX_LOCAL_SEGS = 8; public const int MAX_LOCAL_SEGS = 8;
private RcVec3f m_center = new RcVec3f();
RcVec3f m_center = new RcVec3f(); private List<DtSegment> m_segs = new List<DtSegment>();
List<DtSegment> m_segs = new List<DtSegment>(); private List<long> m_polys = new List<long>();
List<long> m_polys = new List<long>(); private List<long> m_parents = new List<long>();
public DtLocalBoundary() 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(); Reset();
return; return;
} }
m_center = pos; m_center = pos;
// First query non-overlapping polygons. // First query non-overlapping polygons.
Result<FindLocalNeighbourhoodResult> res = navquery.FindLocalNeighbourhood(refs, pos, collisionQueryRange, var status = navquery.FindLocalNeighbourhood(startRef, pos, collisionQueryRange, filter, ref m_polys, ref m_parents);
filter); if (status.Succeeded())
if (res.Succeeded())
{ {
m_polys = res.result.GetRefs();
m_segs.Clear(); m_segs.Clear();
// Secondly, store all polygon edges. // Secondly, store all polygon edges.
for (int j = 0; j < m_polys.Count; ++j) for (int j = 0; j < m_polys.Count; ++j)

View File

@ -2761,49 +2761,48 @@ namespace DotRecast.Detour
/// @par /// @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. /// 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 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. /// mehtod applies to this method.
/// ///
/// The value of the center point is used as the start point for cost calculations. /// 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 /// It is not projected onto the surface of the mesh, so its y-value will effect
/// the costs. /// the costs.
/// ///
/// Intersection tests occur in 2D. All polygons and the search circle are /// 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 /// projected onto the xz-plane. So the y-value of the center point does not
/// effect intersection tests. /// 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. /// be filled to capacity.
/// ///
/// Finds the non-overlapping navigation polygons in the local neighbourhood around the center position. /// 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] 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] centerPos The center of the query circle. [(x, y, z)]
/// @param[in] radius The radius of the query circle. /// @param[in] radius The radius of the query circle.
/// @param[in] filter The polygon filter to apply to the query. /// @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] resultRef The reference ids of the polygons touched by the circle.
/// @param[out] resultParent The reference ids of the parent polygons for each result. /// @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.
/// @returns The status flags for the query. /// @returns The status flags for the query.
public Result<FindLocalNeighbourhoodResult> FindLocalNeighbourhood(long startRef, RcVec3f centerPos, float radius, public DtStatus FindLocalNeighbourhood(long startRef, RcVec3f centerPos, float radius,
IDtQueryFilter filter) IDtQueryFilter filter,
ref List<long> resultRef, ref List<long> resultParent)
{ {
// Validate input // Validate input
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || radius < 0 if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || radius < 0
|| !float.IsFinite(radius) || null == filter) || !float.IsFinite(radius) || null == filter)
{ {
return Results.InvalidParam<FindLocalNeighbourhoodResult>(); return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
} }
List<long> resultRef = new List<long>(); resultRef.Clear();
List<long> resultParent = new List<long>(); resultParent.Clear();
DtNodePool tinyNodePool = new DtNodePool(); 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; hitDist = 0;
hitPos = RcVec3f.Zero; hitPos = RcVec3f.Zero;
hitNormal = RcVec3f.Zero; hitNormal = RcVec3f.Zero;
// Validate input // Validate input
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || maxRadius < 0 if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || maxRadius < 0
|| !float.IsFinite(maxRadius) || null == filter) || !float.IsFinite(maxRadius) || null == filter)

View File

@ -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<long> refs;
private readonly List<long> parentRefs;
public FindLocalNeighbourhoodResult(List<long> refs, List<long> parentRefs)
{
this.@refs = refs;
this.parentRefs = parentRefs;
}
public List<long> GetRefs()
{
return refs;
}
public List<long> GetParentRefs()
{
return parentRefs;
}
}
}

View File

@ -472,13 +472,7 @@ public class TestNavmeshTool : IRcTool
if (m_sposSet && m_startRef != 0) if (m_sposSet && m_startRef != 0)
{ {
m_neighbourhoodRadius = _impl.GetSample().GetSettings().agentRadius * 20.0f; m_neighbourhoodRadius = _impl.GetSample().GetSettings().agentRadius * 20.0f;
Result<FindLocalNeighbourhoodResult> result = m_navQuery.FindLocalNeighbourhood(m_startRef, m_spos, m_navQuery.FindLocalNeighbourhood(m_startRef, m_spos, m_neighbourhoodRadius, m_filter, ref m_polys, ref m_parent);
m_neighbourhoodRadius, m_filter);
if (result.Succeeded())
{
m_polys = result.result.GetRefs();
m_parent = result.result.GetParentRefs();
}
} }
} }
else if (m_toolMode == TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE) else if (m_toolMode == TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE)

View File

@ -16,8 +16,8 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
using System.Collections.Generic;
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Detour.QueryResults;
using NUnit.Framework; using NUnit.Framework;
namespace DotRecast.Detour.Test; namespace DotRecast.Detour.Test;
@ -58,11 +58,13 @@ public class FindLocalNeighbourhoodTest : AbstractDetourTest
for (int i = 0; i < startRefs.Length; i++) for (int i = 0; i < startRefs.Length; i++)
{ {
RcVec3f startPos = startPoss[i]; RcVec3f startPos = startPoss[i];
Result<FindLocalNeighbourhoodResult> poly = query.FindLocalNeighbourhood(startRefs[i], startPos, 3.5f, filter); var refs = new List<long>();
Assert.That(poly.result.GetRefs().Count, Is.EqualTo(REFS[i].Length)); var parentRefs = new List<long>();
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++) 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]));
} }
} }
} }