Ensure each entity is iterated only once
This commit is contained in:
@@ -193,27 +193,36 @@ BzSpatialGridIter bzSpatialGridIter(BzSpatialGrid *grid, f32 posX, f32 posY, f32
|
|||||||
}
|
}
|
||||||
bool bzSpatialGridQueryNext(BzSpatialGridIter *it) {
|
bool bzSpatialGridQueryNext(BzSpatialGridIter *it) {
|
||||||
BzSpatialGridID **cell = getCell(it->_grid, it->_x, it->_y);
|
BzSpatialGridID **cell = getCell(it->_grid, it->_x, it->_y);
|
||||||
while (it->_cellIdx >= bzArraySize(*cell)) {
|
|
||||||
it->_cellIdx = 0;
|
|
||||||
it->_x++;
|
|
||||||
if (it->_x > it->index.maxX) {
|
|
||||||
it->_x = it->index.minX;
|
|
||||||
it->_y++;
|
|
||||||
if (it->_y > it->index.maxY) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cell = getCell(it->_grid, it->_x, it->_y);
|
|
||||||
}
|
|
||||||
|
|
||||||
BzSpatialGridID id = bzArrayGet(*cell, it->_cellIdx);
|
BzSpatialGridID id;
|
||||||
BzSpatialGridEntry *entry = bzObjectPoolGetObject(it->_grid->entriesPool, id);
|
BzSpatialGridEntry *entry;
|
||||||
BZ_ASSERT(entry && id == entry->id);
|
bool foundUnprocessed = false;
|
||||||
|
while (!foundUnprocessed) {
|
||||||
|
while (it->_cellIdx >= bzArraySize(*cell)) {
|
||||||
|
it->_cellIdx = 0;
|
||||||
|
it->_x++;
|
||||||
|
if (it->_x > it->index.maxX) {
|
||||||
|
it->_x = it->index.minX;
|
||||||
|
it->_y++;
|
||||||
|
if (it->_y > it->index.maxY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cell = getCell(it->_grid, it->_x, it->_y);
|
||||||
|
}
|
||||||
|
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->entry = *entry;
|
||||||
it->data = (void *) (entry + 1);
|
it->data = (void *) (entry + 1);
|
||||||
|
|
||||||
it->_cellIdx++;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user