Skip to content

Commit

Permalink
Reuse grid instead of creating new
Browse files Browse the repository at this point in the history
  • Loading branch information
wrenge authored and ikpil committed Dec 15, 2024
1 parent 156e0f4 commit a05eaba
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/DotRecast.Detour.Crowd/DtCrowd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class DtCrowd
private readonly DtObstacleAvoidanceParams[] _obstacleQueryParams;
private readonly DtObstacleAvoidanceQuery _obstacleQuery;

private DtProximityGrid _grid;
private readonly DtProximityGrid _grid;

private int _maxPathResult;
private readonly RcVec3f _agentPlacementHalfExtents;
Expand Down Expand Up @@ -174,6 +174,7 @@ public DtCrowd(DtCrowdConfig config, DtNavMesh nav, Func<int, IDtQueryFilter> qu
_agentIdx = new RcAtomicInteger(0);
_agents = new Dictionary<int, 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.
SetNavMesh(nav);
Expand Down Expand Up @@ -864,7 +865,7 @@ private void BuildProximityGrid(IList<DtCrowdAgent> agents)
{
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildProximityGrid);

_grid = new DtProximityGrid(_config.maxAgentRadius * 3);
_grid.Clear();

for (var i = 0; i < agents.Count; i++)
{
Expand Down

0 comments on commit a05eaba

Please sign in to comment.