Avoid quadratic behaviour in updating nearby lists in RecomputeCatchmentForAll

This commit is contained in:
Jonathan G Rennison
2019-09-23 18:45:37 +01:00
parent 158f063a38
commit 725ff47267
2 changed files with 8 additions and 4 deletions

View File

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

View File

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