1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Merge pull request #24038 from ZehMatt/spatial-index-perf

Improve performance of spatial indexing
This commit is contained in:
Matt
2025-03-21 15:53:42 +02:00
committed by GitHub

View File

@@ -452,7 +452,7 @@ void UpdateEntitiesSpatialIndex()
{
for (auto& entityId : entityList)
{
auto* entity = GetEntity(entityId);
auto* entity = TryGetEntity(entityId);
if (entity == nullptr || entity->Type == EntityType::Null)
continue;
@@ -475,9 +475,29 @@ CoordsXYZ EntityBase::GetLocation() const
void EntityBase::SetLocation(const CoordsXYZ& newLocation)
{
if (GetLocation() == newLocation)
{
// No change, this can happen quite often when the entity is interpolated.
return;
}
x = newLocation.x;
y = newLocation.y;
z = newLocation.z;
if (SpatialIndex & kSpatialIndexDirtyMask)
{
// Already marked as dirty.
return;
}
const auto newSpatialIndex = ComputeSpatialIndex({ x, y });
if (newSpatialIndex == GetSpatialIndex(this))
{
// Avoid marking it dirty when we don't leave the current tile.
return;
}
SpatialIndex |= kSpatialIndexDirtyMask;
}