Reuse grid instead of creating new

This commit is contained in:
wrenge 2024-11-13 13:14:32 +03:00
parent 418a39a576
commit 5c0ba9dba1
1 changed files with 3 additions and 2 deletions

View File

@ -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 DtProximityGrid _grid; private readonly DtProximityGrid _grid;
private int _maxPathResult; private int _maxPathResult;
private readonly RcVec3f _agentPlacementHalfExtents; private readonly RcVec3f _agentPlacementHalfExtents;
@ -174,6 +174,7 @@ 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);
@ -864,7 +865,7 @@ namespace DotRecast.Detour.Crowd
{ {
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildProximityGrid); using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildProximityGrid);
_grid = new DtProximityGrid(_config.maxAgentRadius * 3); _grid.Clear();
for (var i = 0; i < agents.Count; i++) for (var i = 0; i < agents.Count; i++)
{ {