1
0
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:
ζeh Matt
2024-09-27 11:40:18 +03:00
parent 2666a9937e
commit dfb053e286

View File

@@ -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 });
}
}
}