Fix a test and switch to mpsc

This commit is contained in:
Maximilian Ammann 2022-03-10 17:00:34 +01:00
parent 2040887f39
commit ddcae6737c
5 changed files with 38 additions and 18 deletions

View File

@ -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();
}

View File

@ -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,

View File

@ -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
}

View File

@ -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);
}
}
}

View File

@ -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,