diff --git a/build.rs b/build.rs index a2e8a124..3ed134ee 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,4 @@ -use std::path::Path; +use std::path::{Path, PathBuf}; use std::{env, fs}; use mbtiles::extract; @@ -9,15 +9,22 @@ pub const MUNICH_Y: u32 = 11360; pub const MUNICH_Z: u8 = 15; /// Tiles which can be used by StaticTileFetcher -fn embed_tiles_statically() { - let root_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); +fn clean_static_tiles() -> PathBuf { let out_dir = env::var("OUT_DIR").unwrap(); let out = Path::new(&out_dir).join("extracted-tiles"); + if out.exists() && out.is_dir() { fs::remove_dir_all(&out).unwrap() } - fs::create_dir_all(&out).unwrap(); + + out +} + +fn embed_tiles_statically() { + let out = clean_static_tiles(); + + let root_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); let source = Path::new(&root_dir).join(format!("test-data/munich-{}.mbtiles", MUNICH_Z)); @@ -38,5 +45,6 @@ fn embed_tiles_statically() { fn main() { validate_project_wgsl(); + embed_tiles_statically(); } diff --git a/src/coords.rs b/src/coords.rs index 3b826d70..a87e65e1 100644 --- a/src/coords.rs +++ b/src/coords.rs @@ -28,7 +28,7 @@ pub struct TileCoords { impl TileCoords { /// Transforms the tile coordinates as defined by the tile grid addressing scheme into a representation which is /// used in the 3d-world. - pub fn into_world_tile(self, scheme: &TileAdressingScheme) -> WorldTileCoords { + pub fn into_world_tile(self, scheme: TileAdressingScheme) -> WorldTileCoords { match scheme { TileAdressingScheme::XYZ => WorldTileCoords { x: self.x as i32, @@ -75,7 +75,7 @@ pub struct WorldTileCoords { } impl WorldTileCoords { - pub fn into_tile(self, scheme: &TileAdressingScheme) -> TileCoords { + pub fn into_tile(self, scheme: TileAdressingScheme) -> TileCoords { match scheme { TileAdressingScheme::XYZ => TileCoords { x: self.x as u32, diff --git a/src/io/static_tile_fetcher.rs b/src/io/static_tile_fetcher.rs index c21a7985..14615cbe 100644 --- a/src/io/static_tile_fetcher.rs +++ b/src/io/static_tile_fetcher.rs @@ -49,20 +49,23 @@ impl TileFetcher for StaticTileFetcher { #[cfg(test)] mod tests { + use crate::coords::WorldTileCoords; use crate::io::{HttpFetcherConfig, TileFetcher}; + use style_spec::source::TileAdressingScheme; use super::StaticTileFetcher; #[tokio::test] async fn test_tiles_available() { - const MUNICH_X: u32 = 17425; - const MUNICH_Y: u32 = 11365; + const MUNICH_X: i32 = 17425; + const MUNICH_Y: i32 = 11365; const MUNICH_Z: u8 = 15; let fetcher = StaticTileFetcher::new(HttpFetcherConfig::default()); assert!(fetcher.fetch_tile(&(0, 0, 0).into()).await.is_err()); // World overview + let world_tile: WorldTileCoords = (MUNICH_X, MUNICH_Y, MUNICH_Z).into(); assert!(fetcher - .fetch_tile(&(MUNICH_X, MUNICH_Y, MUNICH_Z).into()) + .fetch_tile(&world_tile.into_tile(TileAdressingScheme::XYZ)) .await .is_ok()); // Maxvorstadt Munich } diff --git a/src/io/workflow.rs b/src/io/workflow.rs index 27360ed5..70e565a5 100644 --- a/src/io/workflow.rs +++ b/src/io/workflow.rs @@ -5,10 +5,11 @@ use crate::io::web_tile_fetcher::WebTileFetcher; use crate::io::{HttpFetcherConfig, TileFetcher}; use crate::render::ShaderVertex; use crate::tessellation::{IndexDataType, OverAlignedVertexBuffer, Tessellated}; -use crossbeam_channel::{unbounded as channel, Receiver, RecvError, SendError, Sender}; +//use crossbeam_channel::{unbounded as channel, Receiver, RecvError, SendError, Sender}; use log::{error, info, warn}; use std::collections::HashSet; use std::fmt::{Debug, Formatter}; +use std::sync::mpsc::{channel, Receiver, RecvError, SendError, Sender}; use std::sync::Mutex; use style_spec::source::TileAdressingScheme; use vector_tile::parse_tile_bytes; @@ -76,7 +77,7 @@ impl Workflow { #[derive(Clone)] pub enum LayerResult { - EmptyLayer { + UnavailableLayer { coords: WorldTileCoords, layer_name: String, }, @@ -98,14 +99,14 @@ impl Debug for LayerResult { impl LayerResult { pub fn get_coords(&self) -> WorldTileCoords { match self { - LayerResult::EmptyLayer { coords, .. } => *coords, + LayerResult::UnavailableLayer { coords, .. } => *coords, LayerResult::TessellatedLayer { coords, .. } => *coords, } } pub fn layer_name(&self) -> &str { match self { - LayerResult::EmptyLayer { layer_name, .. } => layer_name.as_str(), + LayerResult::UnavailableLayer { layer_name, .. } => layer_name.as_str(), LayerResult::TessellatedLayer { layer_data, .. } => layer_data.name(), } } @@ -200,11 +201,11 @@ impl DownloadTessellateLoop { layers: layers_to_load, } = self.request_receiver.recv()? { - let tile_coords = coords.into_tile(&TileAdressingScheme::TMS); + let tile_coords = coords.into_tile(TileAdressingScheme::TMS); match fetcher.fetch_tile(&tile_coords).await { Ok(data) => { info!("preparing tile {} with {}bytes", &tile_coords, data.len()); - let tile = parse_tile_bytes(data.as_slice()).expect("failed to load tile"); + let tile = parse_tile_bytes(data.as_slice()).expect("failed to load tile1"); for to_load in layers_to_load { if let Some(layer) = tile @@ -220,12 +221,20 @@ impl DownloadTessellateLoop { layer_data: layer.clone(), })?; } + + info!("layer {} ready: {}", to_load, &coords); + } else { + self.result_sender.send(LayerResult::UnavailableLayer { + coords, + layer_name: to_load.to_string(), + })?; + + info!("layer {} not found: {}", to_load, &coords); } } - info!("LayerResult ready: {}", &coords); } Err(err) => { - error!("LayerResult failed: {:?}", &err); + error!("fetching tile failed: {:?}", &err); } } } diff --git a/src/render/render_state.rs b/src/render/render_state.rs index ae5e20a7..243ec13a 100644 --- a/src/render/render_state.rs +++ b/src/render/render_state.rs @@ -395,7 +395,7 @@ impl RenderState { let layers = workflow.get_tessellated_layers_at(&coords, &loaded_layers); for result in layers { match result { - LayerResult::EmptyLayer { .. } => {} + LayerResult::UnavailableLayer { .. } => {} LayerResult::TessellatedLayer { coords, feature_indices,