summaryrefslogtreecommitdiff
path: root/src/linkgraph
diff options
context:
space:
mode:
authorPeterN <peter@fuzzle.org>2019-02-23 19:19:41 +0000
committerGitHub <noreply@github.com>2019-02-23 19:19:41 +0000
commit87ebfe1227ecc811a18d9b9c791e3e21da3f5eb2 (patch)
tree2792f87f0fbcc12ef020a7942ecd708011c54de0 /src/linkgraph
parentf240f61fb2813a7cc3d2ad130477039b2a4701fd (diff)
downloadopenttd-87ebfe1227ecc811a18d9b9c791e3e21da3f5eb2.tar.xz
Fix #7004: Mark linkgraph dirty to be rebuilt on next draw call. (#7265)
Previously the linkgraph was rebuilt before the viewport extents were finalized.
Diffstat (limited to 'src/linkgraph')
-rw-r--r--src/linkgraph/linkgraph_gui.cpp6
-rw-r--r--src/linkgraph/linkgraph_gui.h8
2 files changed, 11 insertions, 3 deletions
diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp
index 7923fc26c..4db9f95b3 100644
--- a/src/linkgraph/linkgraph_gui.cpp
+++ b/src/linkgraph/linkgraph_gui.cpp
@@ -239,8 +239,12 @@ void LinkGraphOverlay::AddLinks(const Station *from, const Station *to)
* Draw the linkgraph overlay or some part of it, in the area given.
* @param dpi Area to be drawn to.
*/
-void LinkGraphOverlay::Draw(const DrawPixelInfo *dpi) const
+void LinkGraphOverlay::Draw(const DrawPixelInfo *dpi)
{
+ if (this->dirty) {
+ this->RebuildCache();
+ this->dirty = false;
+ }
this->DrawLinks(dpi);
this->DrawStationDots(dpi);
}
diff --git a/src/linkgraph/linkgraph_gui.h b/src/linkgraph/linkgraph_gui.h
index a933bfc68..93ec66629 100644
--- a/src/linkgraph/linkgraph_gui.h
+++ b/src/linkgraph/linkgraph_gui.h
@@ -56,11 +56,13 @@ public:
window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale)
{}
- void RebuildCache();
- void Draw(const DrawPixelInfo *dpi) const;
+ void Draw(const DrawPixelInfo *dpi);
void SetCargoMask(CargoTypes cargo_mask);
void SetCompanyMask(uint32 company_mask);
+ /** Mark the linkgraph dirty to be rebuilt next time Draw() is called. */
+ void SetDirty() { this->dirty = true; }
+
/** Get a bitmask of the currently shown cargoes. */
CargoTypes GetCargoMask() { return this->cargo_mask; }
@@ -75,6 +77,7 @@ protected:
LinkMap cached_links; ///< Cache for links to reduce recalculation.
StationSupplyList cached_stations; ///< Cache for stations to be drawn.
uint scale; ///< Width of link lines.
+ bool dirty; ///< Set if overlay should be rebuilt.
Point GetStationMiddle(const Station *st) const;
@@ -85,6 +88,7 @@ protected:
bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding = 0) const;
bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
void GetWidgetDpi(DrawPixelInfo *dpi) const;
+ void RebuildCache();
static void AddStats(uint new_cap, uint new_usg, uint new_flow, bool new_shared, LinkProperties &cargo);
static void DrawVertex(int x, int y, int size, int colour, int border_colour);