reuse collection

This commit is contained in:
ikpil 2023-07-05 00:03:37 +09:00
parent 5f41636043
commit bb047c5a1d
7 changed files with 67 additions and 18 deletions

View File

@ -303,7 +303,8 @@ namespace DotRecast.Detour.Crowd
public bool MovePosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter) public bool MovePosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter)
{ {
// Move along navmesh and update new position. // Move along navmesh and update new position.
var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, out var visited); var visited = new List<long>();
var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, ref visited);
if (status.Succeeded()) if (status.Succeeded())
{ {
m_path = PathUtils.MergeCorridorStartMoved(m_path, visited); m_path = PathUtils.MergeCorridorStartMoved(m_path, visited);
@ -342,7 +343,8 @@ namespace DotRecast.Detour.Crowd
public bool MoveTargetPosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter) public bool MoveTargetPosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter)
{ {
// Move along navmesh and update new position. // Move along navmesh and update new position.
var status = navquery.MoveAlongSurface(m_path[m_path.Count - 1], m_target, npos, filter, out var result, out var visited); var visited = new List<long>();
var status = navquery.MoveAlongSurface(m_path[m_path.Count - 1], m_target, npos, filter, out var result, ref visited);
if (status.Succeeded()) if (status.Succeeded())
{ {
m_path = PathUtils.MergeCorridorEndMoved(m_path, visited); m_path = PathUtils.MergeCorridorEndMoved(m_path, visited);

View File

@ -1798,10 +1798,12 @@ namespace DotRecast.Detour
/// @returns The status flags for the query. /// @returns The status flags for the query.
public DtStatus MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos, public DtStatus MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos,
IDtQueryFilter filter, IDtQueryFilter filter,
out RcVec3f resultPos, out List<long> visited) out RcVec3f resultPos, ref List<long> visited)
{ {
resultPos = RcVec3f.Zero; resultPos = RcVec3f.Zero;
visited = new List<long>();
if (null != visited)
visited.Clear();
// Validate input // Validate input
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(startPos) if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(startPos)
@ -2452,12 +2454,14 @@ 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 FindPolysAroundCircle(long startRef, RcVec3f centerPos, float radius, IDtQueryFilter filter, public DtStatus FindPolysAroundCircle(long startRef, RcVec3f centerPos, float radius, 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)
{ {
// TODO : check performance if (null != resultRef)
resultRef = new List<long>(); {
resultParent = new List<long>(); resultRef.Clear();
resultCost = new List<float>(); resultParent.Clear();
resultCost.Clear();
}
// Validate input // Validate input
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || radius < 0 if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || radius < 0

View File

@ -24,15 +24,15 @@ public class TestNavmeshTool : IRcTool
private RcVec3f m_epos; private RcVec3f m_epos;
private long m_startRef; private long m_startRef;
private long m_endRef; private long m_endRef;
private readonly DtQueryDefaultFilter m_filter; private readonly DtQueryDefaultFilter m_filter;
private readonly RcVec3f m_polyPickExt = RcVec3f.Of(2, 4, 2); private readonly RcVec3f m_polyPickExt = RcVec3f.Of(2, 4, 2);
// for hit // for hit
private RcVec3f m_hitPos; private RcVec3f m_hitPos;
private RcVec3f m_hitNormal; private RcVec3f m_hitNormal;
private bool m_hitResult; private bool m_hitResult;
private float m_distanceToWall; private float m_distanceToWall;
private List<StraightPathItem> m_straightPath; private List<StraightPathItem> m_straightPath;
private List<long> m_polys; private List<long> m_polys;
@ -281,7 +281,12 @@ public class TestNavmeshTool : IRcTool
float dx = m_epos.x - m_spos.x; float dx = m_epos.x - m_spos.x;
float dz = m_epos.z - m_spos.z; float dz = m_epos.z - m_spos.z;
float dist = (float)Math.Sqrt(dx * dx + dz * dz); float dist = (float)Math.Sqrt(dx * dx + dz * dz);
var status = m_navQuery.FindPolysAroundCircle(m_startRef, m_spos, dist, m_filter, out var refs, out var parentRefs, out var costs);
List<long> refs = new();
List<long> parentRefs = new();
List<float> costs = new();
var status = m_navQuery.FindPolysAroundCircle(m_startRef, m_spos, dist, m_filter, ref refs, ref parentRefs, ref costs);
if (status.Succeeded()) if (status.Succeeded())
{ {
m_polys = refs; m_polys = refs;

View File

@ -18,6 +18,7 @@ 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;
using System.Collections.Generic; using System.Collections.Generic;
using DotRecast.Detour; using DotRecast.Detour;
using DotRecast.Recast.DemoTool.Geom; using DotRecast.Recast.DemoTool.Geom;
@ -90,7 +91,38 @@ namespace DotRecast.Recast.DemoTool
_recastResults = recastResults; _recastResults = recastResults;
_navMesh = navMesh; _navMesh = navMesh;
SetQuery(navMesh); SetQuery(navMesh);
_changed = true; _changed = true;
// // by update
// _inputGeom.ClearConvexVolumes();
// _inputGeom.RemoveOffMeshConnections(x => true);
//
// if (null != _navMesh && 0 < _navMesh.GetTileCount())
// {
// for (int ti = 0; ti < _navMesh.GetTileCount(); ++ti)
// {
// var tile = _navMesh.GetTile(ti);
// for (int pi = 0; pi < tile.data.polys.Length; ++pi)
// {
// var polyType = tile.data.polys[pi].GetPolyType();
// var polyArea= tile.data.polys[pi].GetArea();
//
// if (0 != polyType)
// {
// int a = 3;
// }
//
// if (0 != polyArea)
// {
// int b = 3;
// }
//
// Console.WriteLine($"tileIdx({ti}) polyIdx({pi}) polyType({polyType} polyArea({polyArea})");
// }
//
// }
// }
} }
} }
} }

View File

@ -60,6 +60,7 @@ namespace DotRecast.Recast.DemoTool.Tools
smoothPath.Clear(); smoothPath.Clear();
smoothPath.Add(iterPos); smoothPath.Add(iterPos);
var visited = new List<long>();
// Move towards target a small advancement at a time until target reached or // Move towards target a small advancement at a time until target reached or
// when ran out of memory to store the path. // when ran out of memory to store the path.
@ -96,7 +97,7 @@ namespace DotRecast.Recast.DemoTool.Tools
RcVec3f moveTgt = RcVec3f.Mad(iterPos, delta, len); RcVec3f moveTgt = RcVec3f.Mad(iterPos, delta, len);
// Move // Move
navQuery.MoveAlongSurface(polys[0], iterPos, moveTgt, filter, out var result, out var visited); navQuery.MoveAlongSurface(polys[0], iterPos, moveTgt, filter, out var result, ref visited);
iterPos = result; iterPos = result;

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;
@ -102,13 +102,16 @@ public class FindPolysAroundCircleTest : AbstractDetourTest
public void TestFindPolysAroundCircle() public void TestFindPolysAroundCircle()
{ {
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];
var status = query.FindPolysAroundCircle(startRef, startPos, 7.5f, filter, out var refs, out var parentRefs, out var costs); var status = query.FindPolysAroundCircle(startRef, startPos, 7.5f, filter, ref refs, ref parentRefs, ref costs);
Assert.That(status.Succeeded(), Is.True); Assert.That(status.Succeeded(), Is.True);
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++)
{ {

View File

@ -16,6 +16,7 @@ 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;
@ -69,12 +70,13 @@ public class MoveAlongSurfaceTest : AbstractDetourTest
public void TestMoveAlongSurface() public void TestMoveAlongSurface()
{ {
IDtQueryFilter filter = new DtQueryDefaultFilter(); IDtQueryFilter filter = new DtQueryDefaultFilter();
var visited = new List<long>();
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];
RcVec3f endPos = endPoss[i]; RcVec3f endPos = endPoss[i];
var status = query.MoveAlongSurface(startRef, startPos, endPos, filter, out var result, out var visited); var status = query.MoveAlongSurface(startRef, startPos, endPos, filter, out var result, ref visited);
Assert.That(status.Succeeded(), Is.True); Assert.That(status.Succeeded(), Is.True);
for (int v = 0; v < 3; v++) for (int v = 0; v < 3; v++)