fix: SOH issue step1 (#41)

- https://github.com/ikpil/DotRecast/issues/41
This commit is contained in:
ikpil 2024-01-30 00:40:20 +09:00
parent 5073f657f9
commit 41df518a08
2 changed files with 32 additions and 9 deletions

View File

@ -894,10 +894,12 @@ namespace DotRecast.Detour.Crowd
{
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)
int MAX_NEIS = 32;
var ids = new DtCrowdAgent[MAX_NEIS];
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)
{
continue;

View File

@ -83,30 +83,51 @@ namespace DotRecast.Detour.Crowd
}
}
// 해당 셀 사이즈의 크기로 x ~ y 영역을 찾아, 군집 에이전트를 가져오는 코드
public int QueryItems(float minx, float miny, float maxx, float maxy, ref HashSet<DtCrowdAgent> result)
public int QueryItems(float minx, float miny, float maxx, float maxy, DtCrowdAgent[] ids, int maxIds)
{
int iminx = (int)MathF.Floor(minx * _invCellSize);
int iminy = (int)MathF.Floor(miny * _invCellSize);
int imaxx = (int)MathF.Floor(maxx * _invCellSize);
int imaxy = (int)MathF.Floor(maxy * _invCellSize);
int n = 0;
for (int y = iminy; y <= imaxy; ++y)
{
for (int x = iminx; x <= imaxx; ++x)
{
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)
{
var item = pool[idx];
// Check if the id exists already.
int end = n;
int i = 0;
while (i != end && ids[i] != item)
{
result.Add(ids[i]);
++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()