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. * Rebuild the cache and recalculate which links and stations to be shown.
*/ */

View File

@@ -34,6 +34,8 @@ struct LinkProperties {
CargoID cargo; ///< Cargo type of the link. CargoID cargo; ///< Cargo type of the link.
uint32_t time; ///< Travel time of the link. uint32_t time; ///< Travel time of the link.
bool shared; ///< If this is a shared link to be drawn dashed. 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; StationID id;
uint quantity; uint quantity;
Point pt; Point pt;
bool operator==(const StationSupplyInfo&) const = default;
}; };
struct LinkInfo { struct LinkInfo {
@@ -54,6 +58,8 @@ public:
Point from_pt; Point from_pt;
Point to_pt; Point to_pt;
LinkProperties prop; LinkProperties prop;
bool operator==(const LinkInfo&) const = default;
}; };
typedef std::vector<StationSupplyInfo> StationSupplyList; 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) window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale), dirty(true)
{} {}
bool RebuildCacheCheckCahnged();
void RebuildCache(bool incremental = false); void RebuildCache(bool incremental = false);
bool CacheStillValid() const; bool CacheStillValid() const;
void MarkStationViewportLinksDirty(const Station *st); void MarkStationViewportLinksDirty(const Station *st);

View File

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