Ensure each entity is iterated only once
This commit is contained in:
@@ -193,6 +193,11 @@ BzSpatialGridIter bzSpatialGridIter(BzSpatialGrid *grid, f32 posX, f32 posY, f32
|
||||
}
|
||||
bool bzSpatialGridQueryNext(BzSpatialGridIter *it) {
|
||||
BzSpatialGridID **cell = getCell(it->_grid, it->_x, it->_y);
|
||||
|
||||
BzSpatialGridID id;
|
||||
BzSpatialGridEntry *entry;
|
||||
bool foundUnprocessed = false;
|
||||
while (!foundUnprocessed) {
|
||||
while (it->_cellIdx >= bzArraySize(*cell)) {
|
||||
it->_cellIdx = 0;
|
||||
it->_x++;
|
||||
@@ -205,15 +210,19 @@ bool bzSpatialGridQueryNext(BzSpatialGridIter *it) {
|
||||
}
|
||||
cell = getCell(it->_grid, it->_x, it->_y);
|
||||
}
|
||||
|
||||
BzSpatialGridID id = bzArrayGet(*cell, it->_cellIdx);
|
||||
BzSpatialGridEntry *entry = bzObjectPoolGetObject(it->_grid->entriesPool, id);
|
||||
id = bzArrayGet(*cell, it->_cellIdx);
|
||||
entry = bzObjectPoolGetObject(it->_grid->entriesPool, id);
|
||||
BZ_ASSERT(entry && id == entry->id);
|
||||
if (entry->queryIdx != it->_queryIdx) {
|
||||
entry->queryIdx = it->_queryIdx;
|
||||
foundUnprocessed = true;
|
||||
}
|
||||
it->_cellIdx++;
|
||||
}
|
||||
|
||||
it->entry = *entry;
|
||||
it->data = (void *) (entry + 1);
|
||||
|
||||
it->_cellIdx++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user