From 698a6491fc567c7504850f75bf54fca1dff31c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 12 Oct 2024 04:57:19 +0300 Subject: [PATCH] Ensure the spatial index invalidates when moving the entity position --- src/openrct2/entity/EntityBase.cpp | 12 ------------ src/openrct2/entity/EntityRegistry.cpp | 23 ++++++++++++++--------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/openrct2/entity/EntityBase.cpp b/src/openrct2/entity/EntityBase.cpp index 7b61eb001c..862211a732 100644 --- a/src/openrct2/entity/EntityBase.cpp +++ b/src/openrct2/entity/EntityBase.cpp @@ -20,18 +20,6 @@ template<> bool EntityBase::Is() const return true; } -CoordsXYZ EntityBase::GetLocation() const -{ - return { x, y, z }; -} - -void EntityBase::SetLocation(const CoordsXYZ& newLocation) -{ - x = newLocation.x; - y = newLocation.y; - z = newLocation.z; -} - void EntityBase::Invalidate() { if (x == kLocationNull) diff --git a/src/openrct2/entity/EntityRegistry.cpp b/src/openrct2/entity/EntityRegistry.cpp index 10ae01abb9..3a0104a815 100644 --- a/src/openrct2/entity/EntityRegistry.cpp +++ b/src/openrct2/entity/EntityRegistry.cpp @@ -464,6 +464,19 @@ void UpdateEntitiesSpatialIndex() } } +CoordsXYZ EntityBase::GetLocation() const +{ + return { x, y, z }; +} + +void EntityBase::SetLocation(const CoordsXYZ& newLocation) +{ + x = newLocation.x; + y = newLocation.y; + z = newLocation.z; + SpatialIndex |= kSpatialIndexDirtyMask; +} + void EntityBase::MoveTo(const CoordsXYZ& newLocation) { if (x != kLocationNull) @@ -478,17 +491,9 @@ void EntityBase::MoveTo(const CoordsXYZ& newLocation) loc.x = kLocationNull; } - const auto newSpatialIndex = ComputeSpatialIndex(loc); - if (newSpatialIndex != GetSpatialIndex(this)) - { - SpatialIndex |= kSpatialIndexDirtyMask; - } - if (loc.x == kLocationNull) { - x = loc.x; - y = loc.y; - z = loc.z; + SetLocation(loc); } else {