Only iterate over each entry once
This commit is contained in:
@@ -139,6 +139,7 @@ EntityMapIter entityMapQueryIter(EntityMap *entityMap, Position pos, Size size)
|
||||
EntityMapIndex mapIndex = calculateMapIndex(entityMap, pos, size);
|
||||
EntityMapIter it = {
|
||||
.entityMap=entityMap,
|
||||
.queryIdx=entityMap->queryCount++,
|
||||
.index=mapIndex,
|
||||
.x=mapIndex.minX,
|
||||
.y=mapIndex.minY,
|
||||
@@ -159,10 +160,15 @@ bool entityMapQueryNext(EntityMapIter *it) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
it->cellIdx++;
|
||||
|
||||
EntityMapCell cell = it->entityMap->cells[cellOffset];
|
||||
it->entry = bzArrayGet(it->entityMap->entities, cell);
|
||||
EntityMapEntry *entry = &bzArrayGet(it->entityMap->entities, cell);
|
||||
if (entry->queryIdx == it->queryIdx) {
|
||||
return entityMapQueryNext(it);
|
||||
}
|
||||
entry->queryIdx = it->queryIdx;
|
||||
it->entry = *entry;
|
||||
|
||||
it->cellIdx++;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user