-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
refactorA task that will improve code readability, without changing outcome.A task that will improve code readability, without changing outcome.
Description
This function is quite bad with a large amount of guests.
OpenRCT2/src/openrct2/entity/Staff.cpp
Lines 867 to 897 in 32f652e
void Staff::EntertainerUpdateNearbyPeeps() const | |
{ | |
for (auto guest : EntityList<Guest>()) | |
{ | |
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) | |
{ | |
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); | |
} | |
} | |
} |
We can use the spatial mapping to only get nearby guests rather than iterating the entirety of all guests, with 100 entertainers and 50'000 guests this will result in 5'000'000 iterations just to find guests that are are at most 3 tiles away, very wasteful.
Credits to @LordMarcel for his "Limit park"
Metadata
Metadata
Assignees
Labels
refactorA task that will improve code readability, without changing outcome.A task that will improve code readability, without changing outcome.