Codechange: Scan station catchment tiles when removing station from nearby towns/industries. (#12129)

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.
pull/678/head
Peter Nelson 2 months ago committed by GitHub
parent 00b442d6f9
commit 2d48829999
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -424,12 +424,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