diff --git a/maplibre-demo/Cargo.toml b/maplibre-demo/Cargo.toml index b5b59d6f..aa8dbc33 100644 --- a/maplibre-demo/Cargo.toml +++ b/maplibre-demo/Cargo.toml @@ -10,7 +10,7 @@ readme = "../README.md" [features] web-webgl = ["maplibre/web-webgl"] -trace = ["maplibre/trace", "tracing-subscriber", "tracing-tracy", "tracy-client"] +trace = ["maplibre/trace"] [dependencies] env_logger = "0.9.0" @@ -19,9 +19,4 @@ maplibre-winit = { path = "../maplibre-winit", version = "0.0.1" } tile-grid = "0.3" -tracing = "0.1.35" -tracing-subscriber = { version = "0.3.14", optional = true } -tracing-tracy = { version = "0.8", optional = true } -tracy-client = { version = "0.12.7", optional = true } - clap = { version = "3.2.12", features = ["derive"] } diff --git a/maplibre-demo/src/headed.rs b/maplibre-demo/src/headed.rs index 41e9e49c..4388b708 100644 --- a/maplibre-demo/src/headed.rs +++ b/maplibre-demo/src/headed.rs @@ -1,6 +1,6 @@ use maplibre::environment::DefaultTransferables; -use maplibre::platform::apc::SchedulerAsyncProcedureCall; +use maplibre::io::apc::SchedulerAsyncProcedureCall; use maplibre::{ platform::{http_client::ReqwestHttpClient, scheduler::TokioScheduler}, MapBuilder, diff --git a/maplibre-demo/src/headless.rs b/maplibre-demo/src/headless.rs index d189843f..ed0b9621 100644 --- a/maplibre-demo/src/headless.rs +++ b/maplibre-demo/src/headless.rs @@ -1,5 +1,5 @@ use maplibre::headless::HeadlessEnvironment; -use maplibre::platform::apc::SchedulerAsyncProcedureCall; +use maplibre::io::apc::SchedulerAsyncProcedureCall; use maplibre::{ coords::{LatLon, WorldTileCoords}, error::Error, diff --git a/maplibre-demo/src/main.rs b/maplibre-demo/src/main.rs index f32c5a3e..6d98795f 100644 --- a/maplibre-demo/src/main.rs +++ b/maplibre-demo/src/main.rs @@ -8,15 +8,6 @@ use crate::{headed::run_headed, headless::run_headless}; mod headed; mod headless; -#[cfg(feature = "trace")] -fn enable_tracing() { - use tracing_subscriber::{layer::SubscriberExt, Registry}; - - let subscriber = Registry::default().with(tracing_tracy::TracyLayer::new()); - - tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); -} - #[derive(Parser)] #[clap(author, version, about, long_about = None)] #[clap(propagate_version = true)] @@ -63,7 +54,7 @@ fn main() { env_logger::init_from_env(env_logger::Env::default().default_filter_or("info")); #[cfg(feature = "trace")] - enable_tracing(); + maplibre::platform::trace::enable_tracing(); let cli = Cli::parse(); diff --git a/maplibre/src/headless.rs b/maplibre/src/headless.rs index a6b84346..810ea962 100644 --- a/maplibre/src/headless.rs +++ b/maplibre/src/headless.rs @@ -14,8 +14,8 @@ use wgpu::{BufferAsyncError, BufferSlice}; use crate::environment::DefaultTransferables; use crate::io::apc::AsyncProcedureCall; +use crate::io::apc::SchedulerAsyncProcedureCall; use crate::io::transferables::Transferables; -use crate::platform::apc::SchedulerAsyncProcedureCall; use crate::{ context::{MapContext, ViewState}, coords::{LatLon, ViewRegion, WorldCoords, WorldTileCoords, Zoom, TILE_SIZE}, diff --git a/maplibre/src/io/apc.rs b/maplibre/src/io/apc.rs index 5cd24187..1a763ec0 100644 --- a/maplibre/src/io/apc.rs +++ b/maplibre/src/io/apc.rs @@ -27,13 +27,18 @@ pub enum Input { TileRequest(TileRequest), } -pub trait Context: 'static { +pub trait Context: Send + 'static { fn send(&self, data: Message); fn source_client(&self) -> &SourceClient; } -pub type AsyncProcedure = fn(input: Input, context: C) -> Pin>>; +#[cfg(not(feature = "no-thread-safe-futures"))] +pub type AsyncProcedureFuture = Pin + Send + 'static)>>; +#[cfg(feature = "no-thread-safe-futures")] +pub type AsyncProcedureFuture = Pin + 'static)>>; + +pub type AsyncProcedure = fn(input: Input, context: C) -> AsyncProcedureFuture; pub trait AsyncProcedureCall: 'static { type Context: Context + Send; diff --git a/maplibre/src/platform/mod.rs b/maplibre/src/platform/mod.rs index e76684cb..618c8f40 100644 --- a/maplibre/src/platform/mod.rs +++ b/maplibre/src/platform/mod.rs @@ -41,10 +41,9 @@ pub mod scheduler { pub use super::noweb::scheduler::*; } -/// APC for non-web targets. -pub mod apc { +pub mod trace { #[cfg(not(target_arch = "wasm32"))] - pub use super::noweb::apc::*; + pub use super::noweb::trace::*; } #[cfg(not(target_arch = "wasm32"))] diff --git a/maplibre/src/platform/noweb/mod.rs b/maplibre/src/platform/noweb/mod.rs index 5e4c7d39..868d6637 100644 --- a/maplibre/src/platform/noweb/mod.rs +++ b/maplibre/src/platform/noweb/mod.rs @@ -4,6 +4,7 @@ use std::future::Future; pub mod http_client; pub mod scheduler; +pub mod trace; pub fn run_multithreaded(future: F) -> F::Output { tokio::runtime::Builder::new_multi_thread() diff --git a/maplibre/src/platform/noweb/trace.rs b/maplibre/src/platform/noweb/trace.rs new file mode 100644 index 00000000..7d4de8ad --- /dev/null +++ b/maplibre/src/platform/noweb/trace.rs @@ -0,0 +1,8 @@ +#[cfg(feature = "trace")] +pub fn enable_tracing() { + use tracing_subscriber::{layer::SubscriberExt, Registry}; + + let subscriber = Registry::default().with(tracing_tracy::TracyLayer::new()); + + tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); +} diff --git a/maplibre/src/stages/request_stage.rs b/maplibre/src/stages/request_stage.rs index 872a954b..775fb6da 100644 --- a/maplibre/src/stages/request_stage.rs +++ b/maplibre/src/stages/request_stage.rs @@ -1,7 +1,7 @@ //! Requests tiles which are currently in view use crate::coords::ZoomLevel; -use crate::io::apc::{AsyncProcedureCall, Context, Input}; +use crate::io::apc::{AsyncProcedureCall, AsyncProcedureFuture, Context, Input}; use crate::io::pipeline::PipelineContext; use crate::io::pipeline::Processable; use crate::io::tile_pipelines::build_vector_tile_pipeline; @@ -72,7 +72,7 @@ impl Stage for RequestStage { pub fn schedule>( input: Input, context: C, -) -> Pin + 'static)>> { +) -> AsyncProcedureFuture { // FIXME: improve input handling let input = match input { Input::TileRequest(input) => Some(input),