forked from mirror/DotRecast
Compare commits
No commits in common. "0876d3adcf73ce34d7dbfcfe7f9d9b71638dfa07" and "38a8029b6e5d37c8b436cc28064f2e89ef0c1e4b" have entirely different histories.
0876d3adcf
...
38a8029b6e
|
@ -130,7 +130,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
private readonly DtObstacleAvoidanceParams[] _obstacleQueryParams;
|
private readonly DtObstacleAvoidanceParams[] _obstacleQueryParams;
|
||||||
private readonly DtObstacleAvoidanceQuery _obstacleQuery;
|
private readonly DtObstacleAvoidanceQuery _obstacleQuery;
|
||||||
|
|
||||||
private readonly DtProximityGrid _grid;
|
private DtProximityGrid _grid;
|
||||||
|
|
||||||
private int _maxPathResult;
|
private int _maxPathResult;
|
||||||
private readonly RcVec3f _agentPlacementHalfExtents;
|
private readonly RcVec3f _agentPlacementHalfExtents;
|
||||||
|
@ -175,7 +175,6 @@ namespace DotRecast.Detour.Crowd
|
||||||
_agentIdx = new RcAtomicInteger(0);
|
_agentIdx = new RcAtomicInteger(0);
|
||||||
_agents = new Dictionary<int, DtCrowdAgent>();
|
_agents = new Dictionary<int, DtCrowdAgent>();
|
||||||
_activeAgents = new List<DtCrowdAgent>();
|
_activeAgents = new List<DtCrowdAgent>();
|
||||||
_grid = new DtProximityGrid(_config.maxAgentRadius * 3);
|
|
||||||
|
|
||||||
// The navQuery is mostly used for local searches, no need for large node pool.
|
// The navQuery is mostly used for local searches, no need for large node pool.
|
||||||
SetNavMesh(nav);
|
SetNavMesh(nav);
|
||||||
|
@ -566,18 +565,14 @@ namespace DotRecast.Detour.Crowd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly RcSortedQueue<DtCrowdAgent> UpdateMoveRequest_queue = new RcSortedQueue<DtCrowdAgent>((a1, a2) => a2.targetReplanTime.CompareTo(a1.targetReplanTime));
|
|
||||||
private readonly List<long> UpdateMoveRequest_reqPath = new List<long>();
|
|
||||||
private void UpdateMoveRequest(IList<DtCrowdAgent> agents, float dt)
|
private void UpdateMoveRequest(IList<DtCrowdAgent> agents, float dt)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.UpdateMoveRequest);
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.UpdateMoveRequest);
|
||||||
|
|
||||||
RcSortedQueue<DtCrowdAgent> queue = UpdateMoveRequest_queue;
|
RcSortedQueue<DtCrowdAgent> queue = new RcSortedQueue<DtCrowdAgent>((a1, a2) => a2.targetReplanTime.CompareTo(a1.targetReplanTime));
|
||||||
queue.Clear();
|
|
||||||
|
|
||||||
// Fire off new requests.
|
// Fire off new requests.
|
||||||
List<long> reqPath = UpdateMoveRequest_reqPath;
|
List<long> reqPath = new List<long>();
|
||||||
reqPath.Clear();
|
|
||||||
for (var i = 0; i < agents.Count; i++)
|
for (var i = 0; i < agents.Count; i++)
|
||||||
{
|
{
|
||||||
var ag = agents[i];
|
var ag = agents[i];
|
||||||
|
@ -870,7 +865,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildProximityGrid);
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildProximityGrid);
|
||||||
|
|
||||||
_grid.Clear();
|
_grid = new DtProximityGrid(_config.maxAgentRadius * 3);
|
||||||
|
|
||||||
for (var i = 0; i < agents.Count; i++)
|
for (var i = 0; i < agents.Count; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using DotRecast.Core.Buffers;
|
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd
|
namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
|
@ -31,14 +30,12 @@ namespace DotRecast.Detour.Crowd
|
||||||
private readonly float _cellSize;
|
private readonly float _cellSize;
|
||||||
private readonly float _invCellSize;
|
private readonly float _invCellSize;
|
||||||
private readonly Dictionary<long, List<DtCrowdAgent>> _items;
|
private readonly Dictionary<long, List<DtCrowdAgent>> _items;
|
||||||
private readonly RcObjectPool<List<DtCrowdAgent>> _listPool;
|
|
||||||
|
|
||||||
public DtProximityGrid(float cellSize)
|
public DtProximityGrid(float cellSize)
|
||||||
{
|
{
|
||||||
_cellSize = cellSize;
|
_cellSize = cellSize;
|
||||||
_invCellSize = 1.0f / cellSize;
|
_invCellSize = 1.0f / cellSize;
|
||||||
_items = new Dictionary<long, List<DtCrowdAgent>>();
|
_items = new Dictionary<long, List<DtCrowdAgent>>();
|
||||||
_listPool = new RcObjectPool<List<DtCrowdAgent>>(() => new List<DtCrowdAgent>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
@ -60,8 +57,6 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
foreach (var pair in _items)
|
|
||||||
_listPool.Return(pair.Value);
|
|
||||||
_items.Clear();
|
_items.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +74,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
long key = CombineKey(x, y);
|
long key = CombineKey(x, y);
|
||||||
if (!_items.TryGetValue(key, out var ids))
|
if (!_items.TryGetValue(key, out var ids))
|
||||||
{
|
{
|
||||||
ids = _listPool.Get();
|
ids = new List<DtCrowdAgent>();
|
||||||
_items.Add(key, ids);
|
_items.Add(key, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1842,7 +1842,6 @@ namespace DotRecast.Detour
|
||||||
return DtStatus.DT_SUCCESS | (straightPathCount >= maxStraightPath ? DtStatus.DT_BUFFER_TOO_SMALL : DtStatus.DT_STATUS_NOTHING);
|
return DtStatus.DT_SUCCESS | (straightPathCount >= maxStraightPath ? DtStatus.DT_BUFFER_TOO_SMALL : DtStatus.DT_STATUS_NOTHING);
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Queue<DtNode> MoveAlongSurface_queue = new Queue<DtNode>();
|
|
||||||
/// @par
|
/// @par
|
||||||
///
|
///
|
||||||
/// This method is optimized for small delta movement and a small number of
|
/// This method is optimized for small delta movement and a small number of
|
||||||
|
@ -1898,8 +1897,8 @@ namespace DotRecast.Detour
|
||||||
startNode.total = 0;
|
startNode.total = 0;
|
||||||
startNode.id = startRef;
|
startNode.id = startRef;
|
||||||
startNode.flags = DtNodeFlags.DT_NODE_CLOSED;
|
startNode.flags = DtNodeFlags.DT_NODE_CLOSED;
|
||||||
MoveAlongSurface_queue.Clear();
|
LinkedList<DtNode> stack = new LinkedList<DtNode>();
|
||||||
MoveAlongSurface_queue.Enqueue(startNode);
|
stack.AddLast(startNode);
|
||||||
|
|
||||||
RcVec3f bestPos = new RcVec3f();
|
RcVec3f bestPos = new RcVec3f();
|
||||||
float bestDist = float.MaxValue;
|
float bestDist = float.MaxValue;
|
||||||
|
@ -1915,10 +1914,11 @@ namespace DotRecast.Detour
|
||||||
const int MAX_NEIS = 8;
|
const int MAX_NEIS = 8;
|
||||||
Span<long> neis = stackalloc long[MAX_NEIS];
|
Span<long> neis = stackalloc long[MAX_NEIS];
|
||||||
|
|
||||||
while (0 < MoveAlongSurface_queue.Count)
|
while (0 < stack.Count)
|
||||||
{
|
{
|
||||||
// Pop front.
|
// Pop front.
|
||||||
DtNode curNode = MoveAlongSurface_queue.Dequeue();
|
DtNode curNode = stack.First?.Value;
|
||||||
|
stack.RemoveFirst();
|
||||||
|
|
||||||
// Get poly and tile.
|
// Get poly and tile.
|
||||||
// The API input has been checked already, skip checking internal data.
|
// The API input has been checked already, skip checking internal data.
|
||||||
|
@ -2017,7 +2017,7 @@ namespace DotRecast.Detour
|
||||||
// Mark as the node as visited and push to queue.
|
// Mark as the node as visited and push to queue.
|
||||||
neighbourNode.pidx = m_tinyNodePool.GetNodeIdx(curNode);
|
neighbourNode.pidx = m_tinyNodePool.GetNodeIdx(curNode);
|
||||||
neighbourNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
|
neighbourNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
|
||||||
MoveAlongSurface_queue.Enqueue(neighbourNode);
|
stack.AddLast(neighbourNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2908,7 +2908,6 @@ namespace DotRecast.Detour
|
||||||
return DtStatus.DT_SUCCESS;
|
return DtStatus.DT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Queue<DtNode> FindLocalNeighbourhood_queue = new Queue<DtNode>();
|
|
||||||
/// @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
|
||||||
|
@ -2960,8 +2959,8 @@ namespace DotRecast.Detour
|
||||||
startNode.pidx = 0;
|
startNode.pidx = 0;
|
||||||
startNode.id = startRef;
|
startNode.id = startRef;
|
||||||
startNode.flags = DtNodeFlags.DT_NODE_CLOSED;
|
startNode.flags = DtNodeFlags.DT_NODE_CLOSED;
|
||||||
FindLocalNeighbourhood_queue.Clear();
|
LinkedList<DtNode> stack = new LinkedList<DtNode>();
|
||||||
FindLocalNeighbourhood_queue.Enqueue(startNode);
|
stack.AddLast(startNode);
|
||||||
|
|
||||||
resultRef.Add(startNode.id);
|
resultRef.Add(startNode.id);
|
||||||
resultParent.Add(0L);
|
resultParent.Add(0L);
|
||||||
|
@ -2971,11 +2970,11 @@ namespace DotRecast.Detour
|
||||||
Span<float> pa = stackalloc float[m_nav.GetMaxVertsPerPoly() * 3];
|
Span<float> pa = stackalloc float[m_nav.GetMaxVertsPerPoly() * 3];
|
||||||
Span<float> pb = stackalloc float[m_nav.GetMaxVertsPerPoly() * 3];
|
Span<float> pb = stackalloc float[m_nav.GetMaxVertsPerPoly() * 3];
|
||||||
|
|
||||||
while (0 < FindLocalNeighbourhood_queue.Count)
|
while (0 < stack.Count)
|
||||||
{
|
{
|
||||||
// Pop front.
|
// Pop front.
|
||||||
|
DtNode curNode = stack.First?.Value;
|
||||||
DtNode curNode = FindLocalNeighbourhood_queue.Dequeue();
|
stack.RemoveFirst();
|
||||||
|
|
||||||
// Get poly and tile.
|
// Get poly and tile.
|
||||||
// The API input has been checked already, skip checking internal data.
|
// The API input has been checked already, skip checking internal data.
|
||||||
|
@ -3088,7 +3087,7 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
resultRef.Add(neighbourRef);
|
resultRef.Add(neighbourRef);
|
||||||
resultParent.Add(curRef);
|
resultParent.Add(curRef);
|
||||||
FindLocalNeighbourhood_queue.Enqueue(neighbourNode);
|
stack.AddLast(neighbourNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue