diff --git a/src/DotRecast.Detour.Crowd/DtCrowd.cs b/src/DotRecast.Detour.Crowd/DtCrowd.cs index 19b48ec..acf85e7 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowd.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowd.cs @@ -886,17 +886,19 @@ namespace DotRecast.Detour.Crowd } // Query neighbour agents - ag.neis = GetNeighbours(ag.npos, ag.option.height, ag.option.collisionQueryRange, ag, _grid); + GetNeighbours(ag.npos, ag.option.height, ag.option.collisionQueryRange, ag, ref ag.neis, _grid); } _telemetry.Stop("buildNeighbours"); } - private List GetNeighbours(RcVec3f pos, float height, float range, DtCrowdAgent skip, DtProximityGrid grid) + private int GetNeighbours(RcVec3f pos, float height, float range, DtCrowdAgent skip, ref List result, DtProximityGrid grid) { - HashSet proxAgents = grid.QueryItems(pos.x - range, pos.z - range, pos.x + range, pos.z + range); - List result = new List(proxAgents.Count); + result.Clear(); + + var proxAgents = new HashSet(); + int nids = grid.QueryItems(pos.x - range, pos.z - range, pos.x + range, pos.z + range, ref proxAgents); foreach (DtCrowdAgent ag in proxAgents) { if (ag == skip) @@ -922,7 +924,7 @@ namespace DotRecast.Detour.Crowd } result.Sort((o1, o2) => o1.dist.CompareTo(o2.dist)); - return result; + return result.Count; } private void FindCorners(IList agents, DtCrowdAgentDebugInfo debug) diff --git a/src/DotRecast.Detour.Crowd/DtCrowdNeighbour.cs b/src/DotRecast.Detour.Crowd/DtCrowdNeighbour.cs index 79b0c64..5f19093 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowdNeighbour.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowdNeighbour.cs @@ -3,7 +3,7 @@ /// Provides neighbor data for agents managed by the crowd. /// @ingroup crowd /// @see dtCrowdAgent::neis, dtCrowd - public class DtCrowdNeighbour + public readonly struct DtCrowdNeighbour { public readonly DtCrowdAgent agent; diff --git a/src/DotRecast.Detour.Crowd/DtProximityGrid.cs b/src/DotRecast.Detour.Crowd/DtProximityGrid.cs index 92b5ea4..d69ca8d 100644 --- a/src/DotRecast.Detour.Crowd/DtProximityGrid.cs +++ b/src/DotRecast.Detour.Crowd/DtProximityGrid.cs @@ -81,14 +81,13 @@ namespace DotRecast.Detour.Crowd } // 해당 셀 사이즈의 크기로 x ~ y 영역을 찾아, 군집 에이전트를 가져오는 코드 - public HashSet QueryItems(float minx, float miny, float maxx, float maxy) + public int QueryItems(float minx, float miny, float maxx, float maxy, ref HashSet result) { int iminx = (int)Math.Floor(minx * _invCellSize); int iminy = (int)Math.Floor(miny * _invCellSize); int imaxx = (int)Math.Floor(maxx * _invCellSize); int imaxy = (int)Math.Floor(maxy * _invCellSize); - HashSet result = new HashSet(); for (int y = iminy; y <= imaxy; ++y) { for (int x = iminx; x <= imaxx; ++x) @@ -104,7 +103,7 @@ namespace DotRecast.Detour.Crowd } } - return result; + return result.Count; } public IEnumerable<(long, int)> GetItemCounts()