forked from mirror/DotRecast
Compare commits
No commits in common. "592ecebe1e99f6770113429bbc4ddfa6f571db40" and "418a39a576737373fbf463c1c2146ec8012404ee" have entirely different histories.
592ecebe1e
...
418a39a576
|
@ -1,30 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace DotRecast.Core.Buffers
|
|
||||||
{
|
|
||||||
// This implementation is thread unsafe
|
|
||||||
public class RcObjectPool<T> where T : class
|
|
||||||
{
|
|
||||||
private readonly Queue<T> _items = new Queue<T>();
|
|
||||||
private readonly Func<T> _createFunc;
|
|
||||||
|
|
||||||
public RcObjectPool(Func<T> createFunc)
|
|
||||||
{
|
|
||||||
_createFunc = createFunc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Get()
|
|
||||||
{
|
|
||||||
if (_items.TryDequeue(out var result))
|
|
||||||
return result;
|
|
||||||
|
|
||||||
return _createFunc();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Return(T obj)
|
|
||||||
{
|
|
||||||
_items.Enqueue(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -129,7 +129,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;
|
||||||
|
@ -174,7 +174,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);
|
||||||
|
@ -865,7 +864,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue