Linkgraph overlay: Skip refresh if periodic cache rebuild has no changes

pull/642/head
Jonathan G Rennison 5 months ago
parent a40aa5e5b8
commit 423877374b

@ -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.
*/

@ -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<StationSupplyInfo> 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);

@ -271,8 +271,9 @@ struct MainWindow : Window
return;
}
this->viewport->overlay->SetDirty();
this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
if (this->viewport->overlay->RebuildCacheCheckCahnged()) {
this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
}
}
void OnPaint() override

Loading…
Cancel
Save