reuse list

This commit is contained in:
ikpil 2023-06-28 23:36:58 +09:00
parent d2661a4318
commit 9bb037849c
3 changed files with 17 additions and 8 deletions

View File

@ -2621,12 +2621,12 @@ namespace DotRecast.Detour
/// @param[in] maxResult The maximum number of polygons the result arrays can hold. /// @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 DtStatus FindPolysAroundShape(long startRef, float[] verts, IDtQueryFilter filter, public DtStatus FindPolysAroundShape(long startRef, float[] verts, IDtQueryFilter filter,
out List<long> resultRef, out List<long> resultParent, out List<float> resultCost) ref List<long> resultRef, ref List<long> resultParent, ref List<float> resultCost)
{ {
resultRef = new List<long>(); resultRef.Clear();
resultParent = new List<long>(); resultParent.Clear();
resultCost = new List<float>(); resultCost.Clear();
// Validate input // Validate input
int nverts = verts.Length / 3; int nverts = verts.Length / 3;
if (!m_nav.IsValidPolyRef(startRef) || null == verts || nverts < 3 || null == filter) if (!m_nav.IsValidPolyRef(startRef) || null == verts || nverts < 3 || null == filter)

View File

@ -453,7 +453,11 @@ public class TestNavmeshTool : IRcTool
m_queryPoly[10] = m_epos.y + agentHeight / 2; m_queryPoly[10] = m_epos.y + agentHeight / 2;
m_queryPoly[11] = m_epos.z + nz; m_queryPoly[11] = m_epos.z + nz;
var status = m_navQuery.FindPolysAroundShape(m_startRef, m_queryPoly, m_filter, out var refs, out var parentRefs, out var costs); var refs = new List<long>();
var parentRefs = new List<long>();
var costs = new List<float>();
var status = m_navQuery.FindPolysAroundShape(m_startRef, m_queryPoly, m_filter, ref refs, ref parentRefs, ref costs);
if (status.Succeeded()) if (status.Succeeded())
{ {
m_polys = refs; m_polys = refs;

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 NUnit.Framework; using NUnit.Framework;
namespace DotRecast.Detour.Test; namespace DotRecast.Detour.Test;
@ -129,11 +129,16 @@ public class FindPolysAroundShapeTest : AbstractDetourTest
public void TestFindPolysAroundShape() public void TestFindPolysAroundShape()
{ {
IDtQueryFilter filter = new DtQueryDefaultFilter(); IDtQueryFilter filter = new DtQueryDefaultFilter();
var refs = new List<long>();
var parentRefs = new List<long>();
var costs = new List<float>();
for (int i = 0; i < startRefs.Length; i++) for (int i = 0; i < startRefs.Length; i++)
{ {
long startRef = startRefs[i]; long startRef = startRefs[i];
RcVec3f startPos = startPoss[i]; RcVec3f startPos = startPoss[i];
query.FindPolysAroundShape(startRef, GetQueryPoly(startPos, endPoss[i]), filter, out var refs, out var parentRefs, out var costs); query.FindPolysAroundShape(startRef, GetQueryPoly(startPos, endPoss[i]), filter, ref refs, ref parentRefs, ref costs);
Assert.That(refs.Count, Is.EqualTo(REFS[i].Length)); 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++)
{ {