mln_engine/tile_store/
tile.rs1use std::sync::Arc;
5
6use mln_style::layer::SourceKind;
7
8use crate::layer::tile_layout::Dependencies;
9use crate::log_target;
10use crate::map::MapMode;
11use crate::tile::OverscaledTileID;
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)]
21pub enum TileNecessity {
22 Optional,
24 Required,
26}
27
28#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
33pub(crate) struct TileLoadOrder(u32);
34
35impl TileLoadOrder {
36 const RANKS: u32 = 1 << 24;
37
38 pub(crate) const UNWANTED: TileLoadOrder = TileLoadOrder(u32::MAX);
40
41 #[must_use]
45 pub(crate) fn coarse(rank: usize) -> Self {
46 Self::band(1, rank)
47 }
48
49 #[must_use]
51 pub(crate) fn ideal(rank: usize) -> Self {
52 Self::band(2, rank)
53 }
54
55 fn band(band: u32, rank: usize) -> Self {
56 TileLoadOrder(band * Self::RANKS + (rank as u32).min(Self::RANKS - 1))
57 }
58
59 #[must_use]
61 pub(crate) fn value(self) -> u32 {
62 self.0
63 }
64}
65
66#[derive(Clone, Copy, Debug, PartialEq, Eq)]
67#[repr(u8)]
68pub enum TileOperation {
69 RequestedFromCache,
71 RequestedFromNetwork,
73 LoadFromNetwork,
75 LoadFromCache,
77 StartParse,
79 EndParse,
81 Error,
83 Cancelled,
85 NullOp,
87}
88
89pub(crate) struct Shown {
90 pub(crate) contents: Contents,
91 pub(crate) feature_state_version: u64,
93 pub(crate) answer_outdated: bool,
96 pub(crate) world_copy: bool,
99}
100
101impl Shown {
102 pub(crate) fn new(contents: Contents, feature_state_version: u64) -> Self {
103 Shown { contents, feature_state_version, answer_outdated: false, world_copy: false }
104 }
105}
106
107impl crate::source::source_state::FeatureStateTarget for Shown {
108 fn feature_state_version(&mut self) -> &mut u64 {
109 &mut self.feature_state_version
110 }
111
112 fn set_feature_state(
113 &mut self,
114 states: &crate::layer::bucket::LayerFeatureStates,
115 changed: &mut crate::layer::layer_drawing::ChangedBuckets,
116 ) {
117 if let Some(contents) = self.contents.geometry_mut() {
118 contents.set_feature_state(states, changed);
119 }
120 }
121}
122
123pub(crate) struct Tile {
124 pub(crate) id: OverscaledTileID,
125 pub(crate) load: Load,
126 pub(crate) pipeline: Pipeline,
127 pub(crate) shown: Option<Shown>,
128 pub(super) settled: bool,
131}
132
133impl Tile {
134 pub(crate) fn new(id: OverscaledTileID, load: Load, pipeline: Pipeline) -> Self {
135 Tile { id, load, pipeline, shown: None, settled: false }
136 }
137
138 pub(crate) fn contents(&self) -> Option<&Contents> {
139 self.shown.as_ref().map(|shown| &shown.contents)
140 }
141
142 pub(crate) fn contents_mut(&mut self) -> Option<&mut Contents> {
145 self.shown.as_mut().map(|shown| &mut shown.contents)
146 }
147
148 pub(crate) fn is_renderable(&self) -> bool {
150 self.contents().is_some_and(Contents::is_renderable)
151 }
152
153 pub(crate) fn is_settled(&self) -> bool {
154 self.settled
155 }
156
157 pub(crate) fn is_pending(&self) -> bool {
158 self.pipeline.is_pending(self.settled)
159 }
160
161 pub(crate) fn is_complete(&self) -> bool {
164 self.settled && !self.is_pending()
165 }
166
167 pub(crate) fn has_work(&self) -> bool {
168 self.pipeline.has_work()
169 }
170
171 pub(crate) fn fades_out(&self) -> bool {
174 self.pipeline.layout().is_some_and(|layout| layout.params.mode == MapMode::Continuous)
175 }
176
177 pub(crate) fn dependencies(&self, mut f: impl FnMut(&Dependencies)) {
180 if let Some(contents) = self.contents().and_then(Contents::geometry) {
181 f(&contents.deps);
182 }
183 if let Some(deps) = self.pipeline.layout().and_then(Layout::dependencies) {
184 f(deps);
185 }
186 }
187
188 pub(crate) fn layer_properties_updated(
190 &mut self,
191 layer_properties: &Arc<dyn crate::layer::layer_type::ErasedEvaluatedLayer>,
192 ) -> bool {
193 self.shown.as_mut().is_some_and(|shown| shown.contents.layer_properties_updated(layer_properties))
194 }
195
196 pub(crate) fn dump_debug_logs(&self, kind: SourceKind) {
197 let kind = match kind {
198 SourceKind::Geometry | SourceKind::None => "Geometry",
199 SourceKind::Raster => "Raster",
200 SourceKind::RasterDem => "RasterDEM",
201 };
202 let yes = |value: bool| if value { "yes" } else { "no" };
203 log::info!(target: log_target::GENERAL, "Tile::Kind: {kind}");
204 log::info!(target: log_target::GENERAL, "Tile::id: {}", self.id);
205 log::info!(target: log_target::GENERAL, "Tile::renderable: {}", yes(self.is_renderable()));
206 log::info!(target: log_target::GENERAL, "Tile::complete: {}", yes(self.is_complete()));
207 log::info!(target: log_target::GENERAL, "Tile::loaded: {}", yes(self.settled));
208 }
209}