forked from bit/DotRecastNetSim
fix: SOH issue step1 (#41)
- https://github.com/ikpil/DotRecast/issues/41
This commit is contained in:
parent
5073f657f9
commit
41df518a08
|
@ -894,10 +894,12 @@ namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
result.Clear();
|
result.Clear();
|
||||||
|
|
||||||
var proxAgents = new HashSet<DtCrowdAgent>();
|
int MAX_NEIS = 32;
|
||||||
int nids = grid.QueryItems(pos.X - range, pos.Z - range, pos.X + range, pos.Z + range, ref proxAgents);
|
var ids = new DtCrowdAgent[MAX_NEIS];
|
||||||
foreach (DtCrowdAgent ag in proxAgents)
|
int nids = grid.QueryItems(pos.X - range, pos.Z - range, pos.X + range, pos.Z + range, ids, ids.Length);
|
||||||
|
for (int i = 0; i < nids; ++i)
|
||||||
{
|
{
|
||||||
|
var ag = ids[i];
|
||||||
if (ag == skip)
|
if (ag == skip)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -83,30 +83,51 @@ namespace DotRecast.Detour.Crowd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 해당 셀 사이즈의 크기로 x ~ y 영역을 찾아, 군집 에이전트를 가져오는 코드
|
public int QueryItems(float minx, float miny, float maxx, float maxy, DtCrowdAgent[] ids, int maxIds)
|
||||||
public int QueryItems(float minx, float miny, float maxx, float maxy, ref HashSet<DtCrowdAgent> result)
|
|
||||||
{
|
{
|
||||||
int iminx = (int)MathF.Floor(minx * _invCellSize);
|
int iminx = (int)MathF.Floor(minx * _invCellSize);
|
||||||
int iminy = (int)MathF.Floor(miny * _invCellSize);
|
int iminy = (int)MathF.Floor(miny * _invCellSize);
|
||||||
int imaxx = (int)MathF.Floor(maxx * _invCellSize);
|
int imaxx = (int)MathF.Floor(maxx * _invCellSize);
|
||||||
int imaxy = (int)MathF.Floor(maxy * _invCellSize);
|
int imaxy = (int)MathF.Floor(maxy * _invCellSize);
|
||||||
|
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
long key = CombineKey(x, y);
|
long key = CombineKey(x, y);
|
||||||
if (_items.TryGetValue(key, out var ids))
|
bool hasPool = _items.TryGetValue(key, out var pool);
|
||||||
|
if (!hasPool)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ids.Count; ++i)
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int idx = 0; idx < pool.Count; ++idx)
|
||||||
{
|
{
|
||||||
result.Add(ids[i]);
|
var item = pool[idx];
|
||||||
|
|
||||||
|
// Check if the id exists already.
|
||||||
|
int end = n;
|
||||||
|
int i = 0;
|
||||||
|
while (i != end && ids[i] != item)
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Item not found, add it.
|
||||||
|
if (i == n)
|
||||||
|
{
|
||||||
|
ids[n++] = item;
|
||||||
|
|
||||||
|
if (n >= maxIds)
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.Count;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<(long, int)> GetItemCounts()
|
public IEnumerable<(long, int)> GetItemCounts()
|
||||||
|
|
Loading…
Reference in New Issue