forked from bit/DotRecastNetSim
reuse collection
This commit is contained in:
parent
5f41636043
commit
bb047c5a1d
|
@ -303,7 +303,8 @@ namespace DotRecast.Detour.Crowd
|
|||
public bool MovePosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter)
|
||||
{
|
||||
// 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())
|
||||
{
|
||||
m_path = PathUtils.MergeCorridorStartMoved(m_path, visited);
|
||||
|
@ -342,7 +343,8 @@ namespace DotRecast.Detour.Crowd
|
|||
public bool MoveTargetPosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter)
|
||||
{
|
||||
// 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())
|
||||
{
|
||||
m_path = PathUtils.MergeCorridorEndMoved(m_path, visited);
|
||||
|
|
|
@ -1798,10 +1798,12 @@ namespace DotRecast.Detour
|
|||
/// @returns The status flags for the query.
|
||||
public DtStatus MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos,
|
||||
IDtQueryFilter filter,
|
||||
out RcVec3f resultPos, out List<long> visited)
|
||||
out RcVec3f resultPos, ref List<long> visited)
|
||||
{
|
||||
resultPos = RcVec3f.Zero;
|
||||
visited = new List<long>();
|
||||
|
||||
if (null != visited)
|
||||
visited.Clear();
|
||||
|
||||
// Validate input
|
||||
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.
|
||||
/// @returns The status flags for the query.
|
||||
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
|
||||
resultRef = new List<long>();
|
||||
resultParent = new List<long>();
|
||||
resultCost = new List<float>();
|
||||
if (null != resultRef)
|
||||
{
|
||||
resultRef.Clear();
|
||||
resultParent.Clear();
|
||||
resultCost.Clear();
|
||||
}
|
||||
|
||||
// Validate input
|
||||
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || radius < 0
|
||||
|
|
|
@ -281,7 +281,12 @@ public class TestNavmeshTool : IRcTool
|
|||
float dx = m_epos.x - m_spos.x;
|
||||
float dz = m_epos.z - m_spos.z;
|
||||
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())
|
||||
{
|
||||
m_polys = refs;
|
||||
|
|
|
@ -18,6 +18,7 @@ freely, subject to the following restrictions:
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Detour;
|
||||
using DotRecast.Recast.DemoTool.Geom;
|
||||
|
@ -90,7 +91,38 @@ namespace DotRecast.Recast.DemoTool
|
|||
_recastResults = recastResults;
|
||||
_navMesh = navMesh;
|
||||
SetQuery(navMesh);
|
||||
|
||||
_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})");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -60,6 +60,7 @@ namespace DotRecast.Recast.DemoTool.Tools
|
|||
|
||||
smoothPath.Clear();
|
||||
smoothPath.Add(iterPos);
|
||||
var visited = new List<long>();
|
||||
|
||||
// Move towards target a small advancement at a time until target reached or
|
||||
// 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);
|
||||
|
||||
// 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;
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ freely, subject to the following restrictions:
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace DotRecast.Detour.Test;
|
||||
|
@ -102,11 +102,14 @@ public class FindPolysAroundCircleTest : AbstractDetourTest
|
|||
public void TestFindPolysAroundCircle()
|
||||
{
|
||||
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++)
|
||||
{
|
||||
long startRef = startRefs[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(refs.Count, Is.EqualTo(REFS[i].Length));
|
||||
|
|
|
@ -16,6 +16,7 @@ freely, subject to the following restrictions:
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
@ -69,12 +70,13 @@ public class MoveAlongSurfaceTest : AbstractDetourTest
|
|||
public void TestMoveAlongSurface()
|
||||
{
|
||||
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
||||
var visited = new List<long>();
|
||||
for (int i = 0; i < startRefs.Length; i++)
|
||||
{
|
||||
long startRef = startRefs[i];
|
||||
RcVec3f startPos = startPoss[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);
|
||||
|
||||
for (int v = 0; v < 3; v++)
|
||||
|
|
Loading…
Reference in New Issue