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

This commit is contained in:
Jonathan G Rennison
2024-01-22 01:34:37 +00:00
parent a40aa5e5b8
commit 423877374b
3 changed files with 34 additions and 2 deletions

View File

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