MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / RebuildCache

Method RebuildCache

src/linkgraph/linkgraph_gui.cpp:71–119  ·  view source on GitHub ↗

* Rebuild the cache and recalculate which links and stations to be shown. */

Source from the content-addressed store, hash-verified

69 * Rebuild the cache and recalculate which links and stations to be shown.
70 */
71void LinkGraphOverlay::RebuildCache()
72{
73 this->cached_links.clear();
74 this->cached_stations.clear();
75 if (this->company_mask.None()) return;
76
77 DrawPixelInfo dpi;
78 this->GetWidgetDpi(&dpi);
79
80 for (const Station *sta : Station::Iterate()) {
81 if (sta->rect.IsEmpty()) continue;
82
83 Point pta = this->GetStationMiddle(sta);
84
85 StationID from = sta->index;
86 StationLinkMap &seen_links = this->cached_links[from];
87
88 uint supply = 0;
89 for (CargoType cargo : SetCargoBitIterator(this->cargo_mask)) {
90 if (!CargoSpec::Get(cargo)->IsValid()) continue;
91 if (!LinkGraph::IsValidID(sta->goods[cargo].link_graph)) continue;
92 const LinkGraph &lg = *LinkGraph::Get(sta->goods[cargo].link_graph);
93
94 ConstNode &from_node = lg[sta->goods[cargo].node];
95 supply += lg.Monthly(from_node.supply);
96 for (const Edge &edge : from_node.edges) {
97 StationID to = lg[edge.dest_node].station;
98 assert(from != to);
99 if (!Station::IsValidID(to) || seen_links.find(to) != seen_links.end()) {
100 continue;
101 }
102 const Station *stb = Station::Get(to);
103 assert(sta != stb);
104
105 /* Show links between stations of selected companies or "neutral" ones like oilrigs. */
106 if (stb->owner != OWNER_NONE && sta->owner != OWNER_NONE && !this->company_mask.Test(stb->owner)) continue;
107 if (stb->rect.IsEmpty()) continue;
108
109 if (!this->IsLinkVisible(pta, this->GetStationMiddle(stb), &dpi)) continue;
110
111 this->AddLinks(sta, stb);
112 seen_links[to]; // make sure it is created and marked as seen
113 }
114 }
115 if (this->IsPointVisible(pta, &dpi)) {
116 this->cached_stations.emplace_back(from, supply);
117 }
118 }
119}
120
121/**
122 * Determine if a certain point is inside the given DPI, with some lee way.

Callers 3

DrawMethod · 0.95
SetCargoMaskMethod · 0.95
SetCompanyMaskMethod · 0.95

Calls 13

GetWidgetDpiMethod · 0.95
GetStationMiddleMethod · 0.95
IsLinkVisibleMethod · 0.95
AddLinksMethod · 0.95
IsPointVisibleMethod · 0.95
NoneMethod · 0.80
MonthlyMethod · 0.80
TestMethod · 0.80
clearMethod · 0.45
IsEmptyMethod · 0.45
IsValidMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected