mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-17 12:03:07 +01:00
Only iterate over active entities
This commit is contained in:
@@ -443,20 +443,22 @@ static void EntitySpatialRemove(EntityBase* entity)
|
||||
|
||||
void UpdateEntitiesSpatialIndex()
|
||||
{
|
||||
// TODO: This is not optimal, we should only iterate active entities.
|
||||
for (EntityId::UnderlyingType i = 0; i < MAX_ENTITIES; i++)
|
||||
for (auto& entityList : gEntityLists)
|
||||
{
|
||||
auto* entity = GetEntity(EntityId::FromUnderlying(i));
|
||||
if (entity == nullptr || entity->Type == EntityType::Null)
|
||||
continue;
|
||||
|
||||
if (entity->SpatialIndex & kSpatialIndexDirtyMask)
|
||||
for (auto& entityId : entityList)
|
||||
{
|
||||
if (entity->SpatialIndex != kInvalidSpatialIndex)
|
||||
auto* entity = GetEntity(entityId);
|
||||
if (entity == nullptr || entity->Type == EntityType::Null)
|
||||
continue;
|
||||
|
||||
if (entity->SpatialIndex & kSpatialIndexDirtyMask)
|
||||
{
|
||||
EntitySpatialRemove(entity);
|
||||
if (entity->SpatialIndex != kInvalidSpatialIndex)
|
||||
{
|
||||
EntitySpatialRemove(entity);
|
||||
}
|
||||
EntitySpatialInsert(entity, { entity->x, entity->y });
|
||||
}
|
||||
EntitySpatialInsert(entity, { entity->x, entity->y });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user