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