Clippy fixes (#197)

* Apply clippy fixes

* Use nightly for android

* Use nightly for web

* Fix feature usage

* Deny unused imports

* Add ios and web fixup

* Exit with non-zero exit code

* Add no_pendantic_os_check cfg flag
This commit is contained in:
Max Ammann 2022-11-05 13:29:11 +01:00 committed by GitHub
parent 0b17bc83d4
commit 1444ae7782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 143 additions and 247 deletions

View File

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

View File

@ -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"))]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1 +1 @@
#![deny(unused_imports)]

View File

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

View File

@ -1,3 +1,5 @@
#![deny(unused_imports)]
#[cfg(feature = "sqlite")]
pub mod mbtiles;
pub mod wgsl;

View File

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

View File

@ -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) {

View File

@ -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<LatLon, std::io::Error> {
let split = env.split(',').collect::<Vec<_>>();
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::<f64>().unwrap(),
longitude.parse::<f64>().unwrap(),

View File

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

View File

@ -1,6 +1,6 @@
use std::time::Duration;
use cgmath::{Deg, Rad, Zero};
use cgmath::{Deg, Zero};
use maplibre::world::ViewState;
use super::UpdateState;

View File

@ -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<ET> = winit::event_loop::EventLoop<ET>;
pub type RawEventLoopProxy<ET> = winit::event_loop::EventLoopProxy<ET>;
@ -77,7 +69,7 @@ pub struct WinitEventLoop<ET: 'static> {
impl<ET: 'static + PartialEq + Debug> EventLoop<ET> for WinitEventLoop<ET> {
type EventLoopProxy = WinitEventLoopProxy<ET>;
fn run<E>(mut self, mut map: Map<E>, max_frames: Option<u64>)
fn run<E>(self, mut map: Map<E>, max_frames: Option<u64>)
where
E: Environment,
<E::MapWindowConfig as MapWindowConfig>::MapWindow: HeadedMapWindow,
@ -88,16 +80,18 @@ impl<ET: 'static + PartialEq + Debug> EventLoop<ET> for WinitEventLoop<ET> {
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();
})

View File

@ -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<ET> {
@ -90,8 +86,10 @@ pub fn run_headed_map(cache_path: Option<String>) {
#[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

View File

@ -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<ET> {

View File

@ -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"]

View File

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

View File

@ -32,7 +32,7 @@ const fn create_zoom_bounds<const DIM: usize>() -> [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

View File

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

View File

@ -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)]

View File

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

View File

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

View File

@ -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<T: Transferables, HC: HttpClient> {
impl<T: Transferables, HC: HttpClient> Context<T, HC> for SchedulerContext<T, HC> {
fn send(&self, data: Message<T>) -> 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<HC> {

View File

@ -1,6 +1,6 @@
use std::marker::PhantomData;
use downcast_rs::{impl_downcast, Downcast};
use downcast_rs::Downcast;
use geozero::mvt::tile;
use crate::{

View File

@ -27,7 +27,7 @@ pub trait Scheduler: 'static {
pub struct NopScheduler;
impl Scheduler for NopScheduler {
fn schedule<T>(&self, future_factory: impl FnOnce() -> T + Send + 'static) -> Result<(), Error>
fn schedule<T>(&self, _future_factory: impl FnOnce() -> T + Send + 'static) -> Result<(), Error>
where
T: Future<Output = ()> + 'static,
{

View File

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

View File

@ -16,6 +16,8 @@
//! maplibre = "0.0.2"
//! ```
#![deny(unused_imports)]
// Internal modules
pub(crate) mod tessellation;

View File

@ -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::<E>(&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::<f64>(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,

View File

@ -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<Vec<u8>, Error> {
let response = self.client.get(url).send().await?;

View File

@ -12,6 +12,7 @@ impl TokioScheduler {
}
impl Scheduler for TokioScheduler {
#[cfg(feature = "thread-safe-futures")]
fn schedule<T>(&self, future_factory: impl FnOnce() -> T + Send + 'static) -> Result<(), Error>
where
T: Future<Output = ()> + 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<T>(&self, _future_factory: impl FnOnce() -> T + 'static) -> Result<(), Error>
where
T: Future<Output = ()> + 'static,
{
Ok(())
}
}

View File

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

View File

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

View File

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

View File

@ -247,7 +247,7 @@ impl<Q: Queue<B>, B, V: Pod, I: Pod, TM: Pod, FM: Pod> BufferPool<Q, B, V, I, TM
style_layer,
buffer_vertices: self.vertices.make_room(vertices_bytes, &mut self.index),
buffer_indices: self.indices.make_room(indices_bytes, &mut self.index),
usable_indices: geometry.usable_indices as u32,
usable_indices: geometry.usable_indices,
buffer_layer_metadata: self
.layer_metadata
.make_room(layer_metadata_bytes, &mut self.index),

View File

@ -12,7 +12,7 @@ pub struct VertexBufferLayout {
}
/// Describes the fragment process in a render pipeline.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FragmentState {
/// The shader source
pub source: &'static str,

View File

@ -52,7 +52,7 @@ impl Default for WgpuSettings {
}
};
let mut features = Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES;
let features = Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES;
Self {
device_label: Default::default(),

View File

@ -2,7 +2,6 @@
use crate::{
context::MapContext,
coords::ViewRegion,
render::{eventually::Eventually::Initialized, RenderState, Renderer},
schedule::Stage,
world::World,

View File

@ -6,7 +6,7 @@ use crate::{
platform::MIN_WEBGL_BUFFER_SIZE,
render::{
resource::{FragmentState, RenderPipeline, RenderPipelineDescriptor, VertexState},
settings::{Msaa, RendererSettings},
settings::RendererSettings,
shaders::ShaderGlobals,
},
};

View File

@ -41,7 +41,7 @@ impl TileShape {
coords,
zoom_factor: zoom.scale_to_tile(&coords),
transform: coords.transform_for_zoom(zoom),
buffer_range: index as u64 * STRIDE..(index as u64 + 1) * STRIDE,
buffer_range: index * STRIDE..(index + 1) * STRIDE,
}
}
}

View File

@ -1,31 +1,20 @@
//! [Stages](Stage) for requesting and preparing data
use std::{
cell::RefCell,
marker::PhantomData,
rc::Rc,
sync::{mpsc, Arc, Mutex},
};
use std::{marker::PhantomData, rc::Rc};
use geozero::{mvt::tile, GeozeroDatasource};
use geozero::mvt::tile;
use request_stage::RequestStage;
use crate::{
coords::{WorldCoords, WorldTileCoords, Zoom, ZoomLevel},
coords::WorldTileCoords,
environment::Environment,
error::Error,
io::{
apc::{AsyncProcedureCall, Context, Message},
geometry_index::{GeometryIndex, IndexedGeometry, TileIndex},
pipeline::{PipelineContext, PipelineProcessor, Processable},
source_client::{HttpClient, HttpSourceClient},
tile_pipelines::build_vector_tile_pipeline,
transferables::{
DefaultTessellatedLayer, DefaultTileTessellated, DefaultTransferables,
DefaultUnavailableLayer, TessellatedLayer, TileTessellated, Transferables,
UnavailableLayer,
},
TileRequest,
apc::{Context, Message},
geometry_index::IndexedGeometry,
pipeline::PipelineProcessor,
source_client::HttpClient,
transferables::{TessellatedLayer, TileTessellated, Transferables, UnavailableLayer},
},
kernel::Kernel,
render::ShaderVertex,
@ -87,8 +76,8 @@ impl<'c, T: Transferables, HC: HttpClient, C: Context<T, HC>> PipelineProcessor
fn layer_indexing_finished(
&mut self,
coords: &WorldTileCoords,
geometries: Vec<IndexedGeometry<f64>>,
_coords: &WorldTileCoords,
_geometries: Vec<IndexedGeometry<f64>>,
) -> Result<(), Error> {
// FIXME (wasm-executor): Readd
/* if let Ok(mut geometry_index) = self.state.geometry_index.lock() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -260,6 +260,7 @@ const start = async () => {
emitTypeScript();
} catch (e) {
console.error("Failed to start building: " + e.message)
process.exit(1)
}
}

View File

@ -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<WinitEnvironment<_, _, _, ()>> = kernel_builder.build();

View File

@ -1,6 +1,3 @@
use std::future::Future;
use maplibre::error::Error;
pub mod http_client;
#[cfg(target_feature = "atomics")]

View File

@ -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<Worker, JsValue> {
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()?;

View File

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

View File

@ -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<LinearTransferables> {
data: unsafe {
let mut uninit = Box::<InnerData>::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<UsedTransferables, UsedHttpClient> 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<UsedHttpClient> {
@ -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<ReceivedType> = Rc::from_raw(received_ptr);
let received: Rc<ReceivedType> = Rc::from_raw(received_ptr);
let message = Message::<UsedTransferables>::deserialize(
SerializedMessageTag::from_u32(type_id).unwrap(),