From 5c0ba9dba1adadbc4984e5721c71933312370544 Mon Sep 17 00:00:00 2001 From: wrenge Date: Wed, 13 Nov 2024 13:14:32 +0300 Subject: [PATCH] Reuse grid instead of creating new --- src/DotRecast.Detour.Crowd/DtCrowd.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/DotRecast.Detour.Crowd/DtCrowd.cs b/src/DotRecast.Detour.Crowd/DtCrowd.cs index d90f4ec..c005424 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowd.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowd.cs @@ -129,7 +129,7 @@ namespace DotRecast.Detour.Crowd private readonly DtObstacleAvoidanceParams[] _obstacleQueryParams; private readonly DtObstacleAvoidanceQuery _obstacleQuery; - private DtProximityGrid _grid; + private readonly DtProximityGrid _grid; private int _maxPathResult; private readonly RcVec3f _agentPlacementHalfExtents; @@ -174,6 +174,7 @@ namespace DotRecast.Detour.Crowd _agentIdx = new RcAtomicInteger(0); _agents = new Dictionary(); _activeAgents = new List(); + _grid = new DtProximityGrid(_config.maxAgentRadius * 3); // The navQuery is mostly used for local searches, no need for large node pool. SetNavMesh(nav); @@ -864,7 +865,7 @@ namespace DotRecast.Detour.Crowd { using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildProximityGrid); - _grid = new DtProximityGrid(_config.maxAgentRadius * 3); + _grid.Clear(); for (var i = 0; i < agents.Count; i++) {