diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index def3618f5f..55e7f8d1f6 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -106,6 +106,30 @@ void LinkGraphOverlay::MarkStationViewportLinksDirty(const Station *st) } } +/** + * Rebuild the cache using RebuildCache, and return whether a re-draw is required. + */ +bool LinkGraphOverlay::RebuildCacheCheckCahnged() +{ + static LinkList prev_cached_links; + static StationSupplyList prev_cached_stations; + + uint64_t prev_rebuild_counter = this->rebuild_counter; + + prev_cached_links.swap(this->cached_links); + prev_cached_stations.swap(this->cached_stations); + + this->RebuildCache(false); + + if (prev_cached_links == this->cached_links && prev_cached_stations == this->cached_stations) { + /* No change */ + this->rebuild_counter = prev_rebuild_counter; + return false; + } + + return true; +} + /** * Rebuild the cache and recalculate which links and stations to be shown. */ diff --git a/src/linkgraph/linkgraph_gui.h b/src/linkgraph/linkgraph_gui.h index 2fa5c44f97..ad3bd47d95 100644 --- a/src/linkgraph/linkgraph_gui.h +++ b/src/linkgraph/linkgraph_gui.h @@ -34,6 +34,8 @@ struct LinkProperties { CargoID cargo; ///< Cargo type of the link. uint32_t time; ///< Travel time of the link. bool shared; ///< If this is a shared link to be drawn dashed. + + bool operator==(const LinkProperties&) const = default; }; /** @@ -46,6 +48,8 @@ public: StationID id; uint quantity; Point pt; + + bool operator==(const StationSupplyInfo&) const = default; }; struct LinkInfo { @@ -54,6 +58,8 @@ public: Point from_pt; Point to_pt; LinkProperties prop; + + bool operator==(const LinkInfo&) const = default; }; typedef std::vector StationSupplyList; @@ -73,6 +79,7 @@ public: window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale), dirty(true) {} + bool RebuildCacheCheckCahnged(); void RebuildCache(bool incremental = false); bool CacheStillValid() const; void MarkStationViewportLinksDirty(const Station *st); diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 3bccda9b98..0d86242a5e 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -271,8 +271,9 @@ struct MainWindow : Window return; } - this->viewport->overlay->SetDirty(); - this->GetWidget(WID_M_VIEWPORT)->SetDirty(this); + if (this->viewport->overlay->RebuildCacheCheckCahnged()) { + this->GetWidget(WID_M_VIEWPORT)->SetDirty(this); + } } void OnPaint() override