Avoid quadratic behaviour in updating nearby lists in RecomputeCatchmentForAll

pull/104/head
Jonathan G Rennison 5 years ago
parent 158f063a38
commit 725ff47267

@ -428,10 +428,10 @@ bool Station::CatchmentCoversTown(TownID t) const
* Recompute tiles covered in our catchment area.
* This will additionally recompute nearby towns and industries.
*/
void Station::RecomputeCatchment()
void Station::RecomputeCatchment(bool no_clear_nearby_lists)
{
this->industries_near.clear();
this->RemoveFromAllNearbyLists();
if (!no_clear_nearby_lists) this->RemoveFromAllNearbyLists();
if (this->rect.IsEmpty()) {
this->catchment_tiles.Reset();
@ -498,8 +498,12 @@ void Station::RecomputeCatchment()
*/
/* static */ void Station::RecomputeCatchmentForAll()
{
Town *t;
FOR_ALL_TOWNS(t) { t->stations_near.clear(); }
Industry *i;
FOR_ALL_INDUSTRIES(i) { i->stations_near.clear(); }
Station *st;
FOR_ALL_STATIONS(st) { st->RecomputeCatchment(); }
FOR_ALL_STATIONS(st) { st->RecomputeCatchment(true); }
}
/************************************************************************/

@ -504,7 +504,7 @@ public:
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override;
uint GetPlatformLength(TileIndex tile) const override;
void RecomputeCatchment();
void RecomputeCatchment(bool no_clear_nearby_lists = false);
static void RecomputeCatchmentForAll();
uint GetCatchmentRadius() const;

Loading…
Cancel
Save