Codechange: Scan station catchment tiles when removing station from nearby towns/industries.

Avoid iterating all towns and industries when updating station catchment, and scan a limited portion of the map instead.

This provides a modest performance benefit when many towns/industries exist.

(cherry picked from commit c28762019ee4c0a60815b2c4df433a0d9bc82094)
pull/661/head
Peter Nelson 3 months ago committed by Jonathan G Rennison
parent 828d2146eb
commit 5462204930

@ -452,12 +452,24 @@ void Station::RemoveIndustryToDeliver(Industry *ind)
/**
* Remove this station from the nearby stations lists of all towns and industries.
* Remove this station from the nearby stations lists of nearby towns and industries.
*/
void Station::RemoveFromAllNearbyLists()
{
for (Town *t : Town::Iterate()) { t->stations_near.erase(this); }
for (Industry *i : Industry::Iterate()) { i->stations_near.erase(this); }
std::set<TownID> towns;
std::set<IndustryID> industries;
for (const auto &tile : this->catchment_tiles) {
TileType type = GetTileType(tile);
if (type == MP_HOUSE) {
towns.insert(GetTownIndex(tile));
} else if (type == MP_INDUSTRY) {
industries.insert(GetIndustryIndex(tile));
}
}
for (const TownID &townid : towns) { Town::Get(townid)->stations_near.erase(this); }
for (const IndustryID &industryid : industries) { Industry::Get(industryid)->stations_near.erase(this); }
}
/**

Loading…
Cancel
Save