mln_renderer/tile/
tile.rs1use std::sync::Arc;
5use std::time::Duration;
6
7use mln_map_types::MapMode;
8use mln_storage::Data;
9use mln_tile::TileData;
10use mln_tile_id::OverscaledTileID;
11
12use crate::layout::tile_layout::Dependencies;
13use crate::log_target;
14use crate::tile::contents::Contents;
15use crate::tile::loading::Load;
16use crate::tile::pipeline::{Layout, Pipeline};
17
18#[derive(Clone, Copy, Debug, PartialEq, Eq)]
22pub(crate) enum TileNecessity {
23 Optional,
24 Required,
25}
26
27#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
32pub(crate) struct TileLoadOrder(u32);
33
34impl TileLoadOrder {
35 const RANKS: u32 = 1 << 24;
36
37 pub(crate) const UNWANTED: TileLoadOrder = TileLoadOrder(u32::MAX);
39
40 #[must_use]
44 pub(crate) fn coarse(rank: usize) -> Self {
45 Self::band(1, rank)
46 }
47
48 #[must_use]
50 pub(crate) fn ideal(rank: usize) -> Self {
51 Self::band(2, rank)
52 }
53
54 fn band(band: u32, rank: usize) -> Self {
55 TileLoadOrder(band * Self::RANKS + (rank as u32).min(Self::RANKS - 1))
56 }
57
58 #[must_use]
60 pub(crate) fn value(self) -> u32 {
61 self.0
62 }
63}
64
65#[derive(Clone, Copy, Debug, PartialEq, Eq)]
66#[repr(u8)]
67pub enum TileOperation {
68 RequestedFromCache,
70 RequestedFromNetwork,
72 LoadFromNetwork,
74 LoadFromCache,
76 StartParse,
78 EndParse,
80 Error,
82 Cancelled,
84 NullOp,
86}
87
88#[derive(Clone, Copy, Debug, PartialEq, Eq)]
89pub(crate) struct TileUpdateParameters {
90 pub(crate) minimum_update_interval: Duration,
91 pub(crate) is_volatile: bool,
92}
93
94#[derive(Clone, Copy, Debug, PartialEq)]
95pub(crate) enum TileKind {
96 Geometry,
97 Raster,
98 Dem(mln_util::tileset::RasterEncoding),
99}
100
101pub(crate) enum TileInput {
105 Geometry { data: Option<TileData>, missing: bool },
106 Image { data: Option<Data>, missing: bool },
107}
108
109pub(crate) struct Shown {
110 pub(crate) contents: Contents,
111 pub(crate) feature_state_version: u64,
113 pub(crate) answer_outdated: bool,
116 pub(crate) world_copy: bool,
119}
120
121impl Shown {
122 pub(crate) fn new(contents: Contents, feature_state_version: u64) -> Self {
123 Shown { contents, feature_state_version, answer_outdated: false, world_copy: false }
124 }
125}
126
127impl crate::source_state::FeatureStateTarget for Shown {
128 fn feature_state_version(&mut self) -> &mut u64 {
129 &mut self.feature_state_version
130 }
131
132 fn set_feature_state(
133 &mut self,
134 states: &crate::bucket::LayerFeatureStates,
135 changed: &mut crate::layer_drawing::ChangedBuckets,
136 ) {
137 if let Some(contents) = self.contents.geometry_mut() {
138 contents.set_feature_state(states, changed);
139 }
140 }
141}
142
143pub(crate) struct Tile {
144 pub(crate) id: OverscaledTileID,
145 pub(crate) load: Load,
146 pub(crate) pipeline: Pipeline,
147 pub(crate) shown: Option<Shown>,
148 pub(super) settled: bool,
151}
152
153impl Tile {
154 pub(crate) fn new(id: OverscaledTileID, load: Load, pipeline: Pipeline) -> Self {
155 Tile { id, load, pipeline, shown: None, settled: false }
156 }
157
158 pub(crate) fn contents(&self) -> Option<&Contents> {
159 self.shown.as_ref().map(|shown| &shown.contents)
160 }
161
162 pub(crate) fn contents_mut(&mut self) -> Option<&mut Contents> {
165 self.shown.as_mut().map(|shown| &mut shown.contents)
166 }
167
168 pub(crate) fn is_renderable(&self) -> bool {
170 self.contents().is_some_and(Contents::is_renderable)
171 }
172
173 pub(crate) fn is_settled(&self) -> bool {
174 self.settled
175 }
176
177 pub(crate) fn is_pending(&self) -> bool {
178 self.pipeline.is_pending(self.settled)
179 }
180
181 pub(crate) fn is_complete(&self) -> bool {
184 self.settled && !self.is_pending()
185 }
186
187 pub(crate) fn has_work(&self) -> bool {
188 self.pipeline.has_work()
189 }
190
191 pub(crate) fn fades_out(&self) -> bool {
194 self.pipeline.layout().is_some_and(|layout| layout.params.mode == MapMode::Continuous)
195 }
196
197 pub(crate) fn dependencies(&self, mut f: impl FnMut(&Dependencies)) {
200 if let Some(contents) = self.contents().and_then(Contents::geometry) {
201 f(&contents.deps);
202 }
203 if let Some(deps) = self.pipeline.layout().and_then(Layout::dependencies) {
204 f(deps);
205 }
206 }
207
208 pub(crate) fn layer_properties_updated(
210 &mut self,
211 layer_properties: &Arc<dyn crate::layer_type::ErasedEvaluatedLayer>,
212 ) -> bool {
213 self.shown.as_mut().is_some_and(|shown| shown.contents.layer_properties_updated(layer_properties))
214 }
215
216 pub(crate) fn dump_debug_logs(&self, kind: TileKind) {
217 let kind = match kind {
218 TileKind::Geometry => "Geometry",
219 TileKind::Raster => "Raster",
220 TileKind::Dem(_) => "RasterDEM",
221 };
222 let yes = |value: bool| if value { "yes" } else { "no" };
223 log::info!(target: log_target::GENERAL, "Tile::Kind: {kind}");
224 log::info!(target: log_target::GENERAL, "Tile::id: {}", self.id);
225 log::info!(target: log_target::GENERAL, "Tile::renderable: {}", yes(self.is_renderable()));
226 log::info!(target: log_target::GENERAL, "Tile::complete: {}", yes(self.is_complete()));
227 log::info!(target: log_target::GENERAL, "Tile::loaded: {}", yes(self.settled));
228 }
229}