diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 3186b92c52..5cff6843f8 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -4,6 +4,7 @@ - Improved: [#23590] Title bars are now drawn bigger when “Enlarged UI” is enabled. - Improved: [#23626] Add small, medium and large flat and sloped turns, S-bends and diagonal track to the Go-Karts. - Improved: [#23982] The scenario objective window has been merged into the scenario options window. +- Improved: [#24260] Better performance on parks that have a lot of Guests and Entertainers. - Change: [#23803] Lightning strikes and thunder happen at the same frequency independently of the game speed. - Change: [#23857] Replace display options tab with custom sprites. - Change: [#24069] [Plugin] Plugins are now available in the scenario editor and track designer. diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index b03b35573b..8608f87ff5 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -866,32 +866,42 @@ bool Staff::IsMechanicHeadingToFixRideBlockingPath() */ void Staff::EntertainerUpdateNearbyPeeps() const { - for (auto guest : EntityList()) + // Iterate over tiles within a 3-tile radius (96 units) + constexpr auto kTileRadius = 3; + constexpr auto kLookupRadius = kCoordsXYStep * kTileRadius; + + for (int32_t tileX = x - kLookupRadius; tileX <= x + kLookupRadius; tileX += kCoordsXYStep) { - if (guest->x == kLocationNull) - continue; - - int16_t z_dist = abs(z - guest->z); - if (z_dist > 48) - continue; - - int16_t x_dist = abs(x - guest->x); - int16_t y_dist = abs(y - guest->y); - - if (x_dist > 96) - continue; - - if (y_dist > 96) - continue; - - if (guest->State == PeepState::Walking) + for (int32_t tileY = y - kLookupRadius; tileY <= y + kLookupRadius; tileY += kCoordsXYStep) { - guest->HappinessTarget = std::min(guest->HappinessTarget + 4, kPeepMaxHappiness); - } - else if (guest->State == PeepState::Queuing) - { - guest->TimeInQueue = std::max(0, guest->TimeInQueue - 200); - guest->HappinessTarget = std::min(guest->HappinessTarget + 3, kPeepMaxHappiness); + for (auto* guest : EntityTileList({ tileX, tileY })) + { + if (guest->x == kLocationNull) + continue; + + int16_t z_dist = std::abs(z - guest->z); + if (z_dist > 48) + continue; + + int16_t x_dist = std::abs(x - guest->x); + int16_t y_dist = std::abs(y - guest->y); + + if (x_dist > kLookupRadius) + continue; + + if (y_dist > kLookupRadius) + continue; + + if (guest->State == PeepState::Walking) + { + guest->HappinessTarget = std::min(guest->HappinessTarget + 4, kPeepMaxHappiness); + } + else if (guest->State == PeepState::Queuing) + { + guest->TimeInQueue = std::max(0, guest->TimeInQueue - 200); + guest->HappinessTarget = std::min(guest->HappinessTarget + 3, kPeepMaxHappiness); + } + } } } }