Skip to content

Optimize Staff::EntertainerUpdateNearbyPeeps #24260

@ZehMatt

Description

@ZehMatt

This function is quite bad with a large amount of guests.

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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions