forked from mirror/DotRecast
reuse neis
This commit is contained in:
parent
27ec4839db
commit
a2d2519daa
|
@ -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<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);
|
||||
List<DtCrowdNeighbour> result = new List<DtCrowdNeighbour>(proxAgents.Count);
|
||||
result.Clear();
|
||||
|
||||
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)
|
||||
{
|
||||
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<DtCrowdAgent> agents, DtCrowdAgentDebugInfo debug)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -81,14 +81,13 @@ namespace DotRecast.Detour.Crowd
|
|||
}
|
||||
|
||||
// 해당 셀 사이즈의 크기로 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 iminy = (int)Math.Floor(miny * _invCellSize);
|
||||
int imaxx = (int)Math.Floor(maxx * _invCellSize);
|
||||
int imaxy = (int)Math.Floor(maxy * _invCellSize);
|
||||
|
||||
HashSet<DtCrowdAgent> result = new HashSet<DtCrowdAgent>();
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue