reuse neis

This commit is contained in:
ikpil 2023-06-27 00:06:07 +09:00
parent 27ec4839db
commit a2d2519daa
3 changed files with 10 additions and 9 deletions

View File

@ -886,17 +886,19 @@ namespace DotRecast.Detour.Crowd
} }
// Query neighbour agents // 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"); _telemetry.Stop("buildNeighbours");
} }
private List<DtCrowdNeighbour> GetNeighbours(RcVec3f pos, float height, float range, DtCrowdAgent skip, DtProximityGrid grid) private int GetNeighbours(RcVec3f pos, float height, float range, DtCrowdAgent skip, ref List<DtCrowdNeighbour> result, DtProximityGrid grid)
{ {
HashSet<DtCrowdAgent> proxAgents = grid.QueryItems(pos.x - range, pos.z - range, pos.x + range, pos.z + range); result.Clear();
List<DtCrowdNeighbour> result = new List<DtCrowdNeighbour>(proxAgents.Count);
var proxAgents = new HashSet<DtCrowdAgent>();
int nids = grid.QueryItems(pos.x - range, pos.z - range, pos.x + range, pos.z + range, ref proxAgents);
foreach (DtCrowdAgent ag in proxAgents) foreach (DtCrowdAgent ag in proxAgents)
{ {
if (ag == skip) if (ag == skip)
@ -922,7 +924,7 @@ namespace DotRecast.Detour.Crowd
} }
result.Sort((o1, o2) => o1.dist.CompareTo(o2.dist)); result.Sort((o1, o2) => o1.dist.CompareTo(o2.dist));
return result; return result.Count;
} }
private void FindCorners(IList<DtCrowdAgent> agents, DtCrowdAgentDebugInfo debug) private void FindCorners(IList<DtCrowdAgent> agents, DtCrowdAgentDebugInfo debug)

View File

@ -3,7 +3,7 @@
/// Provides neighbor data for agents managed by the crowd. /// Provides neighbor data for agents managed by the crowd.
/// @ingroup crowd /// @ingroup crowd
/// @see dtCrowdAgent::neis, dtCrowd /// @see dtCrowdAgent::neis, dtCrowd
public class DtCrowdNeighbour public readonly struct DtCrowdNeighbour
{ {
public readonly DtCrowdAgent agent; public readonly DtCrowdAgent agent;

View File

@ -81,14 +81,13 @@ namespace DotRecast.Detour.Crowd
} }
// 해당 셀 사이즈의 크기로 x ~ y 영역을 찾아, 군집 에이전트를 가져오는 코드 // 해당 셀 사이즈의 크기로 x ~ y 영역을 찾아, 군집 에이전트를 가져오는 코드
public HashSet<DtCrowdAgent> QueryItems(float minx, float miny, float maxx, float maxy) public int QueryItems(float minx, float miny, float maxx, float maxy, ref HashSet<DtCrowdAgent> result)
{ {
int iminx = (int)Math.Floor(minx * _invCellSize); int iminx = (int)Math.Floor(minx * _invCellSize);
int iminy = (int)Math.Floor(miny * _invCellSize); int iminy = (int)Math.Floor(miny * _invCellSize);
int imaxx = (int)Math.Floor(maxx * _invCellSize); int imaxx = (int)Math.Floor(maxx * _invCellSize);
int imaxy = (int)Math.Floor(maxy * _invCellSize); int imaxy = (int)Math.Floor(maxy * _invCellSize);
HashSet<DtCrowdAgent> result = new HashSet<DtCrowdAgent>();
for (int y = iminy; y <= imaxy; ++y) for (int y = iminy; y <= imaxy; ++y)
{ {
for (int x = iminx; x <= imaxx; ++x) 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() public IEnumerable<(long, int)> GetItemCounts()