diff --git a/android/Cargo.toml b/android/Cargo.toml index cffc3c84..459f3c1c 100644 --- a/android/Cargo.toml +++ b/android/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" publish = false [dependencies] -maplibre = { path = "../maplibre" } +maplibre = { path = "../maplibre", features = ["thread-safe-futures"] } maplibre-winit = { path = "../maplibre-winit", version = "0.0.1" } env_logger = "0.9.0" log = "0.4.17" diff --git a/android/src/lib.rs b/android/src/lib.rs index 7dc44c6b..62511f1a 100644 --- a/android/src/lib.rs +++ b/android/src/lib.rs @@ -1,14 +1,12 @@ +#![deny(unused_imports)] + use std::ffi::CString; use jni::{objects::JClass, JNIEnv}; use log::Level; -use maplibre::{ - platform::{http_client::ReqwestHttpClient, run_multithreaded, scheduler::TokioScheduler}, - render::settings::{Backends, WgpuSettings}, -}; -use maplibre_winit::{run_headed_map, WinitMapWindowConfig}; +use maplibre_winit::run_headed_map; -#[cfg(not(target_os = "android"))] +#[cfg(not(any(no_pendantic_os_check, target_os = "android")))] compile_error!("android works only on android."); #[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] diff --git a/apple/Cargo.toml b/apple/Cargo.toml index 80c17c2c..3d49610a 100644 --- a/apple/Cargo.toml +++ b/apple/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" publish = false [dependencies] -maplibre = { path = "../maplibre" } +maplibre = { path = "../maplibre", features = ["thread-safe-futures"] } maplibre-winit = { path = "../maplibre-winit", version = "0.0.1" } env_logger = "0.9.0" diff --git a/apple/src/lib.rs b/apple/src/lib.rs index c5b41661..082ed612 100644 --- a/apple/src/lib.rs +++ b/apple/src/lib.rs @@ -1,12 +1,8 @@ -use maplibre::{ - io::apc::SchedulerAsyncProcedureCall, - platform::{http_client::ReqwestHttpClient, run_multithreaded, scheduler::TokioScheduler}, -}; -use maplibre_winit::{ - run_headed_map, WinitEnvironment, WinitEventLoop, WinitMapWindow, WinitMapWindowConfig, -}; +#![deny(unused_imports)] -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +use maplibre_winit::run_headed_map; + +#[cfg(not(any(no_pendantic_os_check, target_os = "macos", target_os = "ios")))] compile_error!("apple works only on macOS and iOS."); #[no_mangle] diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index f2ea3053..f76f0d37 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -6,7 +6,7 @@ categories = [] edition = "2021" [dependencies] -maplibre = { path = "../maplibre", features = ["headless", "embed-static-tiles"] } +maplibre = { path = "../maplibre", features = ["headless", "embed-static-tiles", "thread-safe-futures"] } [dev-dependencies] criterion = { version = "0.3.6", features = ["async_tokio"] } diff --git a/benchmarks/benches/data.rs b/benchmarks/benches/data.rs index 30f23441..a5e4ffa5 100644 --- a/benchmarks/benches/data.rs +++ b/benchmarks/benches/data.rs @@ -1,9 +1,9 @@ -use std::{collections::HashSet, io::Cursor}; +use std::collections::HashSet; use criterion::{criterion_group, criterion_main, Criterion}; use maplibre::{ - benchmarking::{io::static_tile_fetcher::StaticTileFetcher, tessellation::Tessellated}, - coords::{TileCoords, WorldTileCoords, ZoomLevel}, + benchmarking::io::static_tile_fetcher::StaticTileFetcher, + coords::{TileCoords, ZoomLevel}, io::{ pipeline::{PipelineContext, PipelineProcessor, Processable}, tile_pipelines::{ParseTile, TessellateLayer}, diff --git a/benchmarks/benches/render.rs b/benchmarks/benches/render.rs index 705f5ad1..9d169ce9 100644 --- a/benchmarks/benches/render.rs +++ b/benchmarks/benches/render.rs @@ -1,28 +1,10 @@ -use std::collections::HashSet; - use criterion::{criterion_group, criterion_main, Criterion}; use maplibre::{ coords::{WorldTileCoords, ZoomLevel}, error::Error, - headless::{ - create_headless_renderer, environment::HeadlessEnvironment, map::HeadlessMap, - window::HeadlessMapWindowConfig, - }, - io::{ - apc::SchedulerAsyncProcedureCall, - pipeline::{PipelineContext, Processable}, - source_client::HttpSourceClient, - tile_pipelines::build_vector_tile_pipeline, - TileRequest, - }, - kernel::{Kernel, KernelBuilder}, - platform::{http_client::ReqwestHttpClient, run_multithreaded, scheduler::TokioScheduler}, - render::{ - builder::{InitializedRenderer, RendererBuilder}, - settings::{RendererSettings, TextureFormat}, - }, + headless::{create_headless_renderer, map::HeadlessMap}, + platform::run_multithreaded, style::Style, - window::WindowSize, }; fn headless_render(c: &mut Criterion) { @@ -30,7 +12,7 @@ fn headless_render(c: &mut Criterion) { let (mut map, tile) = run_multithreaded(async { let (kernel, renderer) = create_headless_renderer(1000, None).await; let style = Style::default(); - let mut map = HeadlessMap::new(style, renderer, kernel).unwrap(); + let map = HeadlessMap::new(style, renderer, kernel).unwrap(); let tile = map .fetch_tile( diff --git a/benchmarks/src/lib.rs b/benchmarks/src/lib.rs index 8b137891..70da8c01 100644 --- a/benchmarks/src/lib.rs +++ b/benchmarks/src/lib.rs @@ -1 +1 @@ - +#![deny(unused_imports)] diff --git a/justfile b/justfile index fab0c07d..ecaa2dd4 100644 --- a/justfile +++ b/justfile @@ -44,17 +44,22 @@ nightly-install-clippy: fixup: - cargo clippy --no-deps -p maplibre --fix + cargo clippy --allow-dirty --no-deps -p maplibre --fix cargo clippy --allow-dirty --no-deps -p maplibre-winit --fix cargo clippy --allow-dirty --no-deps -p maplibre-demo --fix cargo clippy --allow-dirty --no-deps -p benchmarks --fix # Web - cargo clippy --allow-dirty --no-deps -p web --target wasm32-unknown-unknown --fix - cargo clippy --allow-dirty --no-deps -p maplibre --target wasm32-unknown-unknown --fix - cargo clippy --allow-dirty --no-deps -p maplibre-winit --target wasm32-unknown-unknown --fix + RUSTUP_TOOLCHAIN=$NIGHTLY_TOOLCHAIN cargo clippy --allow-dirty --no-deps -p web --target wasm32-unknown-unknown --fix + RUSTUP_TOOLCHAIN=$NIGHTLY_TOOLCHAIN RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals --cfg=web_sys_unstable_apis' cargo clippy --allow-dirty --no-deps -p web --target wasm32-unknown-unknown --fix -Z build-std=std,panic_abort + RUSTUP_TOOLCHAIN=$NIGHTLY_TOOLCHAIN cargo clippy --allow-dirty --no-deps -p maplibre --target wasm32-unknown-unknown --fix + RUSTUP_TOOLCHAIN=$NIGHTLY_TOOLCHAIN cargo clippy --allow-dirty --no-deps -p maplibre-winit --target wasm32-unknown-unknown --fix # Android - cargo clippy --allow-dirty --no-deps -p maplibre-winit --target x86_64-linux-android --fix - cargo clippy --allow-dirty --no-deps -p maplibre-android --target x86_64-linux-android --fix + env "AR_x86_64-linux-android=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" "CC_x86_64-linux-android=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang" RUSTUP_TOOLCHAIN=$NIGHTLY_TOOLCHAIN cargo clippy --allow-dirty --no-deps -p maplibre --target x86_64-linux-android --fix + env "AR_x86_64-linux-android=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" "CC_x86_64-linux-android=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang" RUSTUP_TOOLCHAIN=$NIGHTLY_TOOLCHAIN cargo clippy --allow-dirty --no-deps -p maplibre-winit --target x86_64-linux-android --fix + env "AR_x86_64-linux-android=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" "CC_x86_64-linux-android=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang" RUSTUP_TOOLCHAIN=$NIGHTLY_TOOLCHAIN cargo clippy --allow-dirty --no-deps -p maplibre-android --target x86_64-linux-android --fix + # macOS/iOS + RUSTFLAGS="--cfg no_pendantic_os_check" cargo clippy --allow-dirty --no-deps -p apple --fix + # TODO check maplibre and maplibre-winit for apple targets check PROJECT ARCH: stable-install-clippy cargo clippy --no-deps -p {{PROJECT}} --target {{ARCH}} diff --git a/maplibre-build-tools/src/lib.rs b/maplibre-build-tools/src/lib.rs index c64a2dcc..f57f865f 100644 --- a/maplibre-build-tools/src/lib.rs +++ b/maplibre-build-tools/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(unused_imports)] + #[cfg(feature = "sqlite")] pub mod mbtiles; pub mod wgsl; diff --git a/maplibre-demo/Cargo.toml b/maplibre-demo/Cargo.toml index aa8dbc33..2cdddec2 100644 --- a/maplibre-demo/Cargo.toml +++ b/maplibre-demo/Cargo.toml @@ -14,7 +14,7 @@ trace = ["maplibre/trace"] [dependencies] env_logger = "0.9.0" -maplibre = { path = "../maplibre", version = "0.0.2", features = ["headless"] } +maplibre = { path = "../maplibre", version = "0.0.2", features = ["headless", "thread-safe-futures"] } maplibre-winit = { path = "../maplibre-winit", version = "0.0.1" } tile-grid = "0.3" diff --git a/maplibre-demo/src/headless.rs b/maplibre-demo/src/headless.rs index de442415..926cd57f 100644 --- a/maplibre-demo/src/headless.rs +++ b/maplibre-demo/src/headless.rs @@ -1,19 +1,9 @@ use maplibre::{ coords::{LatLon, WorldTileCoords}, - error::Error, - headless::{create_headless_renderer, map::HeadlessMap, window::HeadlessMapWindowConfig}, - io::apc::SchedulerAsyncProcedureCall, - kernel::KernelBuilder, - platform::{http_client::ReqwestHttpClient, scheduler::TokioScheduler}, - render::{ - builder::RendererBuilder, - settings::{RendererSettings, TextureFormat}, - }, + headless::{create_headless_renderer, map::HeadlessMap}, style::Style, util::grid::google_mercator, - window::WindowSize, }; -use maplibre_winit::WinitEnvironment; use tile_grid::{extent_wgs84_to_merc, Extent, GridIterator}; pub async fn run_headless(tile_size: u32, min: LatLon, max: LatLon) { diff --git a/maplibre-demo/src/main.rs b/maplibre-demo/src/main.rs index ff38891d..a1306e02 100644 --- a/maplibre-demo/src/main.rs +++ b/maplibre-demo/src/main.rs @@ -1,3 +1,5 @@ +#![deny(unused_imports)] + use std::io::ErrorKind; use clap::{builder::ValueParser, Parser, Subcommand}; @@ -18,7 +20,7 @@ struct Cli { fn parse_lat_long(env: &str) -> Result { let split = env.split(',').collect::>(); - if let (Some(latitude), Some(longitude)) = (split.get(0), split.get(1)) { + if let (Some(latitude), Some(longitude)) = (split.first(), split.get(1)) { Ok(LatLon::new( latitude.parse::().unwrap(), longitude.parse::().unwrap(), diff --git a/maplibre-winit/Cargo.toml b/maplibre-winit/Cargo.toml index 6add2389..e817cac7 100644 --- a/maplibre-winit/Cargo.toml +++ b/maplibre-winit/Cargo.toml @@ -18,7 +18,7 @@ wasm-bindgen = "0.2.81" wasm-bindgen-futures = "0.4.31" [dependencies] -maplibre = { path = "../maplibre", version = "0.0.2", default-features = false } +maplibre = { path = "../maplibre", version = "0.0.2" } winit = { version = "0.27.2", default-features = false } cgmath = "0.18.0" instant = { version = "0.1.12", features = ["wasm-bindgen"] } # TODO: Untrusted dependency diff --git a/maplibre-winit/src/input/tilt_handler.rs b/maplibre-winit/src/input/tilt_handler.rs index 115e68fe..1e0e5700 100644 --- a/maplibre-winit/src/input/tilt_handler.rs +++ b/maplibre-winit/src/input/tilt_handler.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use cgmath::{Deg, Rad, Zero}; +use cgmath::{Deg, Zero}; use maplibre::world::ViewState; use super::UpdateState; diff --git a/maplibre-winit/src/lib.rs b/maplibre-winit/src/lib.rs index b47ec4ee..f50592cf 100644 --- a/maplibre-winit/src/lib.rs +++ b/maplibre-winit/src/lib.rs @@ -1,24 +1,14 @@ -pub mod input; +#![deny(unused_imports)] -use std::{cell::RefCell, fmt::Debug, marker::PhantomData, ops::Deref, rc::Rc}; +use std::{fmt::Debug, marker::PhantomData}; use instant::Instant; -use log::info; use maplibre::{ environment::Environment, error::Error, event_loop::{EventLoop, EventLoopProxy}, - io::{ - apc::{AsyncProcedureCall, Message}, - scheduler::Scheduler, - source_client::HttpClient, - transferables::{DefaultTransferables, Transferables}, - }, + io::{apc::AsyncProcedureCall, scheduler::Scheduler, source_client::HttpClient}, map::Map, - render::{ - builder::RendererBuilder, - settings::{Backends, WgpuSettings}, - }, window::{HeadedMapWindow, MapWindowConfig}, }; use winit::{ @@ -28,6 +18,8 @@ use winit::{ use crate::input::{InputController, UpdateState}; +pub mod input; + pub type RawWinitWindow = winit::window::Window; pub type RawWinitEventLoop = winit::event_loop::EventLoop; pub type RawEventLoopProxy = winit::event_loop::EventLoopProxy; @@ -77,7 +69,7 @@ pub struct WinitEventLoop { impl EventLoop for WinitEventLoop { type EventLoopProxy = WinitEventLoopProxy; - fn run(mut self, mut map: Map, max_frames: Option) + fn run(self, mut map: Map, max_frames: Option) where E: Environment, ::MapWindow: HeadedMapWindow, @@ -88,16 +80,18 @@ impl EventLoop for WinitEventLoop { let mut input_controller = InputController::new(0.2, 100.0, 0.1); self.event_loop - .run(move |event, window_target, control_flow| { + .run(move |event, _window_target, control_flow| { #[cfg(target_os = "android")] if !map.has_renderer() && event == Event::Resumed { use tokio::{runtime::Handle, task}; + use maplibre::render::settings::WgpuSettings; + use maplibre::render::builder::RendererBuilder; task::block_in_place(|| { Handle::current().block_on(async { map.initialize_renderer(RendererBuilder::new() .with_wgpu_settings(WgpuSettings { - backends: Some(Backends::VULKAN), // FIXME: Change + backends: Some(maplibre::render::settings::Backends::VULKAN), // FIXME: Change ..WgpuSettings::default() })).await.unwrap(); }) diff --git a/maplibre-winit/src/noweb.rs b/maplibre-winit/src/noweb.rs index ee6438d8..ff8c9f36 100644 --- a/maplibre-winit/src/noweb.rs +++ b/maplibre-winit/src/noweb.rs @@ -11,16 +11,12 @@ use maplibre::{ kernel::{Kernel, KernelBuilder}, map::Map, platform::{http_client::ReqwestHttpClient, run_multithreaded, scheduler::TokioScheduler}, - render::{ - builder::{InitializationResult, InitializedRenderer, RendererBuilder}, - settings::{Backends, RendererSettings, WgpuSettings}, - }, style::Style, - window::{HeadedMapWindow, MapWindow, MapWindowConfig, WindowSize}, + window::{MapWindow, MapWindowConfig, WindowSize}, }; use winit::window::WindowBuilder; -use super::{RawWinitEventLoop, RawWinitWindow, WinitMapWindow}; +use super::WinitMapWindow; use crate::{WinitEnvironment, WinitEventLoop}; pub struct WinitMapWindowConfig { @@ -90,8 +86,10 @@ pub fn run_headed_map(cache_path: Option) { #[cfg(not(target_os = "android"))] { + use maplibre::render::{builder::RendererBuilder, settings::WgpuSettings}; + map.initialize_renderer(RendererBuilder::new().with_wgpu_settings(WgpuSettings { - backends: Some(Backends::VULKAN), // FIXME: Change + backends: Some(maplibre::render::settings::Backends::VULKAN), // FIXME: Change ..WgpuSettings::default() })) .await diff --git a/maplibre-winit/src/web.rs b/maplibre-winit/src/web.rs index 913bc54b..994a7068 100644 --- a/maplibre-winit/src/web.rs +++ b/maplibre-winit/src/web.rs @@ -1,9 +1,9 @@ use std::marker::PhantomData; -use maplibre::window::{HeadedMapWindow, MapWindow, MapWindowConfig, WindowSize}; +use maplibre::window::{MapWindow, MapWindowConfig, WindowSize}; use winit::{platform::web::WindowBuilderExtWebSys, window::WindowBuilder}; -use super::{RawWinitEventLoop, RawWinitWindow, WinitMapWindow}; +use super::WinitMapWindow; use crate::WinitEventLoop; pub struct WinitMapWindowConfig { diff --git a/maplibre/Cargo.toml b/maplibre/Cargo.toml index 6c62ea53..55e6de34 100644 --- a/maplibre/Cargo.toml +++ b/maplibre/Cargo.toml @@ -9,7 +9,7 @@ description = "Native Maps for Web, Mobile and Desktop" readme = "../README.md" [features] -default = ["thread-safe-futures"] +default = [] web-webgl = ["wgpu/webgl"] # Enable tracing using tracy on desktop/mobile and the chrome profiler on web trace = ["tracing-subscriber", "tracing-tracy", "tracy-client"] diff --git a/maplibre/src/context.rs b/maplibre/src/context.rs index e8466d95..20f06401 100644 --- a/maplibre/src/context.rs +++ b/maplibre/src/context.rs @@ -1,8 +1,4 @@ -use crate::{ - render::Renderer, - style::Style, - world::{ViewState, World}, -}; +use crate::{render::Renderer, style::Style, world::World}; /// Stores the context of the map. pub struct MapContext { diff --git a/maplibre/src/coords.rs b/maplibre/src/coords.rs index 4e4f1711..a89e5f62 100644 --- a/maplibre/src/coords.rs +++ b/maplibre/src/coords.rs @@ -32,7 +32,7 @@ const fn create_zoom_bounds() -> [u32; DIM] { let mut result: [u32; DIM] = [0; DIM]; let mut i = 0; while i < DIM { - result[i as usize] = 2u32.pow(i as u32); + result[i] = 2u32.pow(i as u32); i += 1; } result diff --git a/maplibre/src/environment.rs b/maplibre/src/environment.rs index 1bcd1379..5dc83189 100644 --- a/maplibre/src/environment.rs +++ b/maplibre/src/environment.rs @@ -1,14 +1,5 @@ use crate::{ - event_loop::EventLoopConfig, - io::{ - apc::AsyncProcedureCall, - scheduler::Scheduler, - source_client::{HttpClient, HttpSourceClient, SourceClient}, - transferables::{ - DefaultTessellatedLayer, DefaultTileTessellated, DefaultUnavailableLayer, Transferables, - }, - }, - kernel::Kernel, + io::{apc::AsyncProcedureCall, scheduler::Scheduler, source_client::HttpClient}, window::MapWindowConfig, }; diff --git a/maplibre/src/error.rs b/maplibre/src/error.rs index 3b64d41a..b959213b 100644 --- a/maplibre/src/error.rs +++ b/maplibre/src/error.rs @@ -1,10 +1,10 @@ //! Errors which can happen in various parts of the library. -use std::{borrow::Cow, fmt, fmt::Formatter, sync::mpsc::SendError}; +use std::{borrow::Cow, sync::mpsc::SendError}; use lyon::tessellation::TessellationError; -use crate::render::{error::RenderError, graph::RenderGraphError}; +use crate::render::error::RenderError; /// Enumeration of errors which can happen during the operation of the library. #[derive(Debug)] diff --git a/maplibre/src/headless/map.rs b/maplibre/src/headless/map.rs index ac4d38de..51175b55 100644 --- a/maplibre/src/headless/map.rs +++ b/maplibre/src/headless/map.rs @@ -11,19 +11,17 @@ use crate::{ io::{ pipeline::{PipelineContext, PipelineProcessor, Processable}, tile_pipelines::build_vector_tile_pipeline, - tile_repository::{StoredLayer, StoredTile, TileStatus}, + tile_repository::{StoredLayer, StoredTile}, RawLayer, TileRequest, }, kernel::Kernel, render::{ - builder::UninitializedRenderer, create_default_render_graph, draw_graph, - error::RenderError, eventually::Eventually, register_default_render_stages, resource::Head, - stages::RenderStageLabel, Renderer, ShaderVertex, + create_default_render_graph, draw_graph, eventually::Eventually, + register_default_render_stages, stages::RenderStageLabel, Renderer, ShaderVertex, }, schedule::{Schedule, Stage}, style::Style, tessellation::{IndexDataType, OverAlignedVertexBuffer}, - window::WindowSize, world::World, }; diff --git a/maplibre/src/headless/mod.rs b/maplibre/src/headless/mod.rs index d248a68b..2d4efd46 100644 --- a/maplibre/src/headless/mod.rs +++ b/maplibre/src/headless/mod.rs @@ -6,10 +6,7 @@ use crate::{ io::apc::SchedulerAsyncProcedureCall, kernel::{Kernel, KernelBuilder}, platform::{http_client::ReqwestHttpClient, scheduler::TokioScheduler}, - render::{ - builder::{InitializedRenderer, RendererBuilder}, - Renderer, - }, + render::{builder::RendererBuilder, Renderer}, window::{MapWindowConfig, WindowSize}, }; diff --git a/maplibre/src/io/apc.rs b/maplibre/src/io/apc.rs index 7ce1423f..be27fbe4 100644 --- a/maplibre/src/io/apc.rs +++ b/maplibre/src/io/apc.rs @@ -1,5 +1,4 @@ use std::{ - collections::HashMap, future::Future, pin::Pin, sync::{ @@ -11,7 +10,6 @@ use std::{ use serde::{Deserialize, Serialize}; use crate::{ - coords::WorldTileCoords, error::Error, io::{ scheduler::Scheduler, @@ -120,7 +118,7 @@ pub struct SchedulerContext { impl Context for SchedulerContext { fn send(&self, data: Message) -> Result<(), Error> { - self.sender.send(data).map_err(|e| Error::APC) + self.sender.send(data).map_err(|_e| Error::APC) } fn source_client(&self) -> &SourceClient { diff --git a/maplibre/src/io/pipeline.rs b/maplibre/src/io/pipeline.rs index e3a5606c..04239330 100644 --- a/maplibre/src/io/pipeline.rs +++ b/maplibre/src/io/pipeline.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use downcast_rs::{impl_downcast, Downcast}; +use downcast_rs::Downcast; use geozero::mvt::tile; use crate::{ diff --git a/maplibre/src/io/scheduler.rs b/maplibre/src/io/scheduler.rs index 67e4cb7b..99f09551 100644 --- a/maplibre/src/io/scheduler.rs +++ b/maplibre/src/io/scheduler.rs @@ -27,7 +27,7 @@ pub trait Scheduler: 'static { pub struct NopScheduler; impl Scheduler for NopScheduler { - fn schedule(&self, future_factory: impl FnOnce() -> T + Send + 'static) -> Result<(), Error> + fn schedule(&self, _future_factory: impl FnOnce() -> T + Send + 'static) -> Result<(), Error> where T: Future + 'static, { diff --git a/maplibre/src/io/tile_repository.rs b/maplibre/src/io/tile_repository.rs index 78e4a1f2..962bfe9d 100644 --- a/maplibre/src/io/tile_repository.rs +++ b/maplibre/src/io/tile_repository.rs @@ -1,8 +1,6 @@ //! Tile cache. -use std::collections::{btree_map, BTreeMap, HashSet}; - -use geozero::mvt::tile; +use std::collections::{btree_map, BTreeMap}; use crate::{ coords::{Quadkey, WorldTileCoords}, @@ -112,7 +110,7 @@ impl TileRepository { .map(|key| self.tree.entry(key)) { match entry { - btree_map::Entry::Vacant(entry) => { + btree_map::Entry::Vacant(_entry) => { panic!("Can not add a tessellated layer if no request has been started before.") } btree_map::Entry::Occupied(mut entry) => { @@ -155,7 +153,11 @@ impl TileRepository { /// Checks if a layer has been fetched. pub fn has_tile(&self, coords: &WorldTileCoords) -> bool { - if let Some(_) = coords.build_quad_key().and_then(|key| self.tree.get(&key)) { + if coords + .build_quad_key() + .and_then(|key| self.tree.get(&key)) + .is_some() + { return false; } true diff --git a/maplibre/src/lib.rs b/maplibre/src/lib.rs index 73b8358c..2f7dd672 100644 --- a/maplibre/src/lib.rs +++ b/maplibre/src/lib.rs @@ -16,6 +16,8 @@ //! maplibre = "0.0.2" //! ``` +#![deny(unused_imports)] + // Internal modules pub(crate) mod tessellation; diff --git a/maplibre/src/map.rs b/maplibre/src/map.rs index 15835fb9..0e5b48ab 100644 --- a/maplibre/src/map.rs +++ b/maplibre/src/map.rs @@ -2,7 +2,7 @@ use std::rc::Rc; use crate::{ context::MapContext, - coords::{LatLon, WorldCoords, Zoom, TILE_SIZE}, + coords::{LatLon, Zoom}, environment::Environment, error::Error, kernel::Kernel, @@ -11,13 +11,11 @@ use crate::{ InitializationResult, InitializedRenderer, RendererBuilder, UninitializedRenderer, }, create_default_render_graph, register_default_render_stages, - settings::{RendererSettings, WgpuSettings}, - Renderer, }, schedule::{Schedule, Stage}, stages::register_stages, style::Style, - window::{HeadedMapWindow, MapWindow, MapWindowConfig, WindowSize}, + window::{HeadedMapWindow, MapWindow, MapWindowConfig}, world::World, }; @@ -47,7 +45,7 @@ where register_stages::(&mut schedule, kernel.clone()); - let mut window = kernel.map_window_config().create(); + let window = kernel.map_window_config().create(); let map = Self { kernel, @@ -78,13 +76,13 @@ where let world = World::new_at( window_size, LatLon::new(center[0], center[1]), - style.zoom.map(|zoom| Zoom::new(zoom)).unwrap_or_default(), + style.zoom.map(Zoom::new).unwrap_or_default(), cgmath::Deg::(style.pitch.unwrap_or_default()), ); match result { InitializationResult::Initialized(InitializedRenderer { renderer, .. }) => { - *&mut self.map_context = MapContextState::Ready(MapContext { + self.map_context = MapContextState::Ready(MapContext { world, style: std::mem::take(style), renderer, diff --git a/maplibre/src/platform/noweb/http_client.rs b/maplibre/src/platform/noweb/http_client.rs index ef230faa..b5941dcd 100644 --- a/maplibre/src/platform/noweb/http_client.rs +++ b/maplibre/src/platform/noweb/http_client.rs @@ -40,7 +40,8 @@ impl ReqwestHttpClient { } } -#[async_trait] +#[cfg_attr(not(feature = "thread-safe-futures"), async_trait(?Send))] +#[cfg_attr(feature = "thread-safe-futures", async_trait)] impl HttpClient for ReqwestHttpClient { async fn fetch(&self, url: &str) -> Result, Error> { let response = self.client.get(url).send().await?; diff --git a/maplibre/src/platform/noweb/scheduler.rs b/maplibre/src/platform/noweb/scheduler.rs index 427ed927..c13dfb45 100644 --- a/maplibre/src/platform/noweb/scheduler.rs +++ b/maplibre/src/platform/noweb/scheduler.rs @@ -12,6 +12,7 @@ impl TokioScheduler { } impl Scheduler for TokioScheduler { + #[cfg(feature = "thread-safe-futures")] fn schedule(&self, future_factory: impl FnOnce() -> T + Send + 'static) -> Result<(), Error> where T: Future + Send + 'static, @@ -19,4 +20,13 @@ impl Scheduler for TokioScheduler { tokio::task::spawn((future_factory)()); Ok(()) } + + // FIXME: Provide a working implementation + #[cfg(not(feature = "thread-safe-futures"))] + fn schedule(&self, _future_factory: impl FnOnce() -> T + 'static) -> Result<(), Error> + where + T: Future + 'static, + { + Ok(()) + } } diff --git a/maplibre/src/render/builder.rs b/maplibre/src/render/builder.rs index ff93b29e..39cdfa98 100644 --- a/maplibre/src/render/builder.rs +++ b/maplibre/src/render/builder.rs @@ -1,15 +1,10 @@ -use std::marker::PhantomData; - use crate::{ - environment::Environment, error::Error, - kernel::Kernel, render::{ settings::{RendererSettings, WgpuSettings}, Renderer, }, - style::Style, - window::{HeadedMapWindow, MapWindow, MapWindowConfig}, + window::{HeadedMapWindow, MapWindowConfig}, }; pub struct RendererBuilder { @@ -94,7 +89,7 @@ impl UninitializedRenderer { let renderer = Renderer::initialize( existing_window, self.wgpu_settings.clone(), - self.renderer_settings.clone(), + self.renderer_settings, ) .await?; Ok(InitializationResult::Initialized(InitializedRenderer { diff --git a/maplibre/src/render/camera.rs b/maplibre/src/render/camera.rs index 5e7e1e84..1be13249 100644 --- a/maplibre/src/render/camera.rs +++ b/maplibre/src/render/camera.rs @@ -141,8 +141,8 @@ impl Camera { let oz = min_depth; let pz = max_depth - min_depth; Matrix4::from_cols( - Vector4::new(self.width as f64 / 2.0, 0.0, 0.0, 0.0), - Vector4::new(0.0, -self.height as f64 / 2.0, 0.0, 0.0), + Vector4::new(self.width / 2.0, 0.0, 0.0, 0.0), + Vector4::new(0.0, -self.height / 2.0, 0.0, 0.0), Vector4::new(0.0, 0.0, pz, 0.0), Vector4::new(ox, oy, oz, 1.0), ) @@ -181,11 +181,11 @@ impl Camera { let x = 0.0; let y = 0.0; - let ox = x + self.width as f64 / 2.0; - let oy = y + self.height as f64 / 2.0; + let ox = x + self.width / 2.0; + let oy = y + self.height / 2.0; let oz = min_depth; - let px = self.width as f64; - let py = self.height as f64; + let px = self.width; + let py = self.height; let pz = max_depth - min_depth; let xd = ndc.x; let yd = ndc.y; diff --git a/maplibre/src/render/mod.rs b/maplibre/src/render/mod.rs index d811b419..aa8fbcf0 100644 --- a/maplibre/src/render/mod.rs +++ b/maplibre/src/render/mod.rs @@ -412,10 +412,7 @@ impl Renderer { #[cfg(test)] mod tests { - use crate::{ - render::{settings::RendererSettings, RenderState}, - window::{MapWindow, MapWindowConfig, WindowSize}, - }; + use crate::window::{MapWindow, MapWindowConfig, WindowSize}; pub struct HeadlessMapWindowConfig { size: WindowSize, @@ -445,7 +442,8 @@ mod tests { use log::LevelFilter; use crate::render::{ - graph::RenderGraph, graph_runner::RenderGraphRunner, resource::Surface, + graph::RenderGraph, graph_runner::RenderGraphRunner, resource::Surface, RenderState, + RendererSettings, }; let _ = env_logger::builder() diff --git a/maplibre/src/render/resource/buffer_pool.rs b/maplibre/src/render/resource/buffer_pool.rs index e975534b..76b6cb53 100644 --- a/maplibre/src/render/resource/buffer_pool.rs +++ b/maplibre/src/render/resource/buffer_pool.rs @@ -247,7 +247,7 @@ impl, B, V: Pod, I: Pod, TM: Pod, FM: Pod> BufferPool> PipelineProcessor fn layer_indexing_finished( &mut self, - coords: &WorldTileCoords, - geometries: Vec>, + _coords: &WorldTileCoords, + _geometries: Vec>, ) -> Result<(), Error> { // FIXME (wasm-executor): Readd /* if let Ok(mut geometry_index) = self.state.geometry_index.lock() { diff --git a/maplibre/src/stages/populate_tile_store_stage.rs b/maplibre/src/stages/populate_tile_store_stage.rs index 6fa88313..c3ef550a 100644 --- a/maplibre/src/stages/populate_tile_store_stage.rs +++ b/maplibre/src/stages/populate_tile_store_stage.rs @@ -1,6 +1,6 @@ //! Receives data from async threads and populates the [`crate::io::tile_repository::TileRepository`]. -use std::{borrow::BorrowMut, cell::RefCell, ops::Deref, rc::Rc}; +use std::rc::Rc; use crate::{ context::MapContext, diff --git a/maplibre/src/stages/request_stage.rs b/maplibre/src/stages/request_stage.rs index 3716bca2..4eb41a5f 100644 --- a/maplibre/src/stages/request_stage.rs +++ b/maplibre/src/stages/request_stage.rs @@ -1,26 +1,15 @@ //! Requests tiles which are currently in view -use std::{ - borrow::Borrow, - cell::RefCell, - collections::{HashMap, HashSet}, - future::Future, - ops::Deref, - pin::Pin, - process::Output, - rc::Rc, - str::FromStr, -}; +use std::{collections::HashSet, rc::Rc}; use crate::{ context::MapContext, - coords::{ViewRegion, WorldTileCoords, ZoomLevel}, + coords::{ViewRegion, WorldTileCoords}, environment::Environment, error::Error, io::{ apc::{AsyncProcedureCall, AsyncProcedureFuture, Context, Input, Message}, pipeline::{PipelineContext, Processable}, - source_client::{HttpSourceClient, SourceClient}, tile_pipelines::build_vector_tile_pipeline, tile_repository::TileRepository, transferables::{Transferables, UnavailableLayer}, diff --git a/maplibre/src/window.rs b/maplibre/src/window.rs index c6955a79..59ad080a 100644 --- a/maplibre/src/window.rs +++ b/maplibre/src/window.rs @@ -1,11 +1,7 @@ //! Utilities for the window system. -use std::{cell::RefCell, rc::Rc}; - use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; -use crate::environment::Environment; - /// Window of a certain [`WindowSize`]. This can either be a proper window or a headless one. pub trait MapWindow { fn size(&self) -> WindowSize; diff --git a/maplibre/src/world.rs b/maplibre/src/world.rs index f88dd86f..40f99e8d 100644 --- a/maplibre/src/world.rs +++ b/maplibre/src/world.rs @@ -1,9 +1,8 @@ use std::ops::{Deref, DerefMut}; -use cgmath::{Angle, Point3}; +use cgmath::Angle; use crate::{ - context::MapContext, coords::{LatLon, ViewRegion, WorldCoords, Zoom, ZoomLevel, TILE_SIZE}, io::tile_repository::TileRepository, render::camera::{Camera, Perspective, ViewProjection}, diff --git a/web/Cargo.toml b/web/Cargo.toml index 4f66f8a3..f35c1615 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -19,7 +19,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] async-trait = "0.1.56" -maplibre = { path = "../maplibre", default-features = false, features = [] } +maplibre = { path = "../maplibre" } maplibre-winit = { path = "../maplibre-winit", version = "0.0.1" } log = "0.4.17" diff --git a/web/lib/build.mjs b/web/lib/build.mjs index fb2571df..cc67bb84 100644 --- a/web/lib/build.mjs +++ b/web/lib/build.mjs @@ -260,6 +260,7 @@ const start = async () => { emitTypeScript(); } catch (e) { console.error("Failed to start building: " + e.message) + process.exit(1) } } diff --git a/web/src/lib.rs b/web/src/lib.rs index 5cc9614a..673ab732 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -1,15 +1,12 @@ +#![deny(unused_imports)] #![feature(allocator_api, new_uninit)] -use std::{borrow::BorrowMut, cell::RefCell, mem, ops::Deref, rc::Rc}; - use maplibre::{ event_loop::EventLoop, - io::{apc::SchedulerAsyncProcedureCall, scheduler::NopScheduler}, kernel::{Kernel, KernelBuilder}, map::Map, - render::builder::{InitializedRenderer, RendererBuilder}, + render::builder::RendererBuilder, style::Style, - window::MapWindowConfig, }; use maplibre_winit::{WinitEnvironment, WinitMapWindowConfig}; use wasm_bindgen::prelude::*; @@ -19,7 +16,7 @@ use crate::platform::http_client::WHATWGFetchHttpClient; mod error; mod platform; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(no_pendantic_os_check, target_arch = "wasm32")))] compile_error!("web works only on wasm32."); #[cfg(feature = "trace")] @@ -48,7 +45,7 @@ pub fn wasm_bindgen_start() { #[cfg(not(target_feature = "atomics"))] type CurrentEnvironment = WinitEnvironment< - NopScheduler, + maplibre::io::scheduler::NopScheduler, WHATWGFetchHttpClient, platform::singlethreaded::apc::PassingAsyncProcedureCall, (), @@ -91,7 +88,7 @@ pub async fn run_maplibre(new_worker: js_sys::Function) { { kernel_builder = kernel_builder .with_apc(platform::singlethreaded::apc::PassingAsyncProcedureCall::new(new_worker, 4)) - .with_scheduler(NopScheduler); + .with_scheduler(maplibre::io::scheduler::NopScheduler); } let kernel: Kernel> = kernel_builder.build(); diff --git a/web/src/platform/mod.rs b/web/src/platform/mod.rs index c9fe5bc2..6d810810 100644 --- a/web/src/platform/mod.rs +++ b/web/src/platform/mod.rs @@ -1,6 +1,3 @@ -use std::future::Future; - -use maplibre::error::Error; pub mod http_client; #[cfg(target_feature = "atomics")] diff --git a/web/src/platform/multithreaded/pool.rs b/web/src/platform/multithreaded/pool.rs index 2b459b19..aa294da5 100644 --- a/web/src/platform/multithreaded/pool.rs +++ b/web/src/platform/multithreaded/pool.rs @@ -2,13 +2,13 @@ //! web workers which can be used to execute work. //! Adopted from [wasm-bindgen example](https://github.com/rustwasm/wasm-bindgen/blob/0eba2efe45801b71f8873bc368c58a8ed8e894ff/examples/raytrace-parallel/src/pool.rs) -use std::{borrow::BorrowMut, cell::RefCell, future::Future, rc::Rc}; +use std::{cell::RefCell, rc::Rc}; use js_sys::Promise; use rand::prelude::*; -use wasm_bindgen::{prelude::*, JsCast}; +use wasm_bindgen::prelude::*; use wasm_bindgen_futures::JsFuture; -use web_sys::{DedicatedWorkerGlobalScope, ErrorEvent, Event, MessageEvent, Worker}; +use web_sys::Worker; #[wasm_bindgen()] extern "C" { @@ -91,10 +91,7 @@ impl WorkerPool { /// message is sent to it. fn worker(&self) -> Result { let workers = self.state.workers.borrow(); - let result = match workers.choose(&mut thread_rng()) { - Some(worker) => Some(worker), - None => None, - }; + let result = workers.choose(&mut thread_rng()); if result.is_none() { self.spawn()?; diff --git a/web/src/platform/multithreaded/pool_scheduler.rs b/web/src/platform/multithreaded/pool_scheduler.rs index 25eb8331..4f105b08 100644 --- a/web/src/platform/multithreaded/pool_scheduler.rs +++ b/web/src/platform/multithreaded/pool_scheduler.rs @@ -1,12 +1,10 @@ use std::future::Future; -use log::warn; use maplibre::{error::Error, io::scheduler::Scheduler}; use wasm_bindgen::{prelude::*, JsCast}; use web_sys::Worker; use super::pool::WorkerPool; -use crate::CurrentEnvironment; pub struct WebWorkerPoolScheduler { pool: WorkerPool, diff --git a/web/src/platform/singlethreaded/apc.rs b/web/src/platform/singlethreaded/apc.rs index b167689f..07766940 100644 --- a/web/src/platform/singlethreaded/apc.rs +++ b/web/src/platform/singlethreaded/apc.rs @@ -1,41 +1,23 @@ -use std::{ - any::TypeId, - borrow::Borrow, - cell::RefCell, - collections::HashMap, - marker::PhantomData, - mem, - mem::{size_of, MaybeUninit}, - ops::Deref, - pin::Pin, - rc::Rc, - sync::{ - mpsc, - mpsc::{Receiver, Sender}, - }, -}; +use std::{cell::RefCell, mem, rc::Rc}; use js_sys::Uint8Array; use log::info; use maplibre::{ - environment::Environment, error::Error, io::{ apc::{AsyncProcedure, AsyncProcedureCall, Context, Input, Message}, - scheduler::Scheduler, - source_client::{HttpClient, HttpSourceClient, SourceClient}, + source_client::{HttpSourceClient, SourceClient}, transferables::Transferables, }, - kernel::Kernel, }; use wasm_bindgen::{prelude::*, JsCast, JsValue}; -use web_sys::{console::info, DedicatedWorkerGlobalScope, Worker}; +use web_sys::{DedicatedWorkerGlobalScope, Worker}; use crate::{ platform::singlethreaded::transferables::{ InnerData, LinearTessellatedLayer, LinearTransferables, }, - CurrentEnvironment, MapType, WHATWGFetchHttpClient, + WHATWGFetchHttpClient, }; type UsedTransferables = LinearTransferables; @@ -100,9 +82,8 @@ impl SerializableMessage for Message { data: unsafe { let mut uninit = Box::::new_zeroed(); data.raw_copy_to_ptr(uninit.as_mut_ptr() as *mut u8); - let x = uninit.assume_init(); - x + uninit.assume_init() }, }) } @@ -135,11 +116,11 @@ impl Context for PassingContext { } let global: DedicatedWorkerGlobalScope = - js_sys::global().dyn_into().map_err(|e| Error::APC)?; + js_sys::global().dyn_into().map_err(|_e| Error::APC)?; let array = js_sys::Array::new(); array.push(&JsValue::from(tag as u32)); array.push(&serialized_array_buffer); - global.post_message(&array).map_err(|e| Error::APC) + global.post_message(&array).map_err(|_e| Error::APC) } fn source_client(&self) -> &SourceClient { @@ -235,7 +216,7 @@ pub unsafe fn singlethreaded_main_entry( data: Uint8Array, ) -> Result<(), JsValue> { // FIXME (wasm-executor): Can we make this call safe? check if it was cloned before? - let mut received: Rc = Rc::from_raw(received_ptr); + let received: Rc = Rc::from_raw(received_ptr); let message = Message::::deserialize( SerializedMessageTag::from_u32(type_id).unwrap(),