mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Address some FIXMEs
This commit is contained in:
parent
92301d005e
commit
6b1fa188c2
@ -9,6 +9,7 @@ use crate::render::{error::RenderError, graph::RenderGraphError};
|
||||
/// Enumeration of errors which can happen during the operation of the library.
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
APC,
|
||||
Scheduler,
|
||||
Network(String),
|
||||
Tesselation(TessellationError),
|
||||
|
||||
@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
coords::WorldTileCoords,
|
||||
error::Error,
|
||||
io::{
|
||||
scheduler::Scheduler,
|
||||
source_client::{HttpClient, HttpSourceClient, SourceClient},
|
||||
@ -42,7 +43,8 @@ pub enum Input {
|
||||
/// Allows sending messages from workers to back to the caller.
|
||||
pub trait Context<T: Transferables, HC: HttpClient>: Send + 'static {
|
||||
/// Send a message back to the caller.
|
||||
fn send(&self, data: Message<T>);
|
||||
// FIXME (wasm-executor): handle results send() calls
|
||||
fn send(&self, data: Message<T>) -> Result<(), Error>;
|
||||
|
||||
fn source_client(&self) -> &SourceClient<HC>;
|
||||
}
|
||||
@ -117,8 +119,8 @@ 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>) {
|
||||
self.sender.send(data).unwrap(); // FIXME (wasm-executor): Remove unwrap
|
||||
fn send(&self, data: Message<T>) -> Result<(), Error> {
|
||||
self.sender.send(data).map_err(|e| Error::APC)
|
||||
}
|
||||
|
||||
fn source_client(&self) -> &SourceClient<HC> {
|
||||
@ -156,7 +158,7 @@ impl<HC: HttpClient, S: Scheduler> AsyncProcedureCall<HC> for SchedulerAsyncProc
|
||||
|
||||
fn call(&self, input: Input, procedure: AsyncProcedure<Self::Context>) {
|
||||
let sender = self.channel.0.clone();
|
||||
let client = self.http_client.clone(); // FIXME (wasm-executor): do not clone each time
|
||||
let client = self.http_client.clone(); // TODO (perf): do not clone each time
|
||||
|
||||
self.scheduler
|
||||
.schedule(move || async move {
|
||||
|
||||
@ -5,28 +5,40 @@ use geozero::mvt::tile;
|
||||
|
||||
use crate::{
|
||||
coords::WorldTileCoords,
|
||||
error::Error,
|
||||
io::geometry_index::IndexedGeometry,
|
||||
render::ShaderVertex,
|
||||
tessellation::{IndexDataType, OverAlignedVertexBuffer},
|
||||
};
|
||||
|
||||
/// Processes events which happen during the pipeline execution
|
||||
// FIXME (wasm-executor): handle results for messages below
|
||||
pub trait PipelineProcessor: Downcast {
|
||||
fn tile_finished(&mut self, _coords: &WorldTileCoords) {}
|
||||
fn layer_unavailable(&mut self, _coords: &WorldTileCoords, _layer_name: &str) {}
|
||||
fn tile_finished(&mut self, _coords: &WorldTileCoords) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn layer_unavailable(
|
||||
&mut self,
|
||||
_coords: &WorldTileCoords,
|
||||
_layer_name: &str,
|
||||
) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn layer_tesselation_finished(
|
||||
&mut self,
|
||||
_coords: &WorldTileCoords,
|
||||
_buffer: OverAlignedVertexBuffer<ShaderVertex, IndexDataType>,
|
||||
_feature_indices: Vec<u32>,
|
||||
_layer_data: tile::Layer,
|
||||
) {
|
||||
) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn layer_indexing_finished(
|
||||
&mut self,
|
||||
_coords: &WorldTileCoords,
|
||||
_geometries: Vec<IndexedGeometry<f64>>,
|
||||
) {
|
||||
) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -45,6 +45,7 @@ impl Processable for IndexLayer {
|
||||
) -> Self::Output {
|
||||
let index = IndexProcessor::new();
|
||||
|
||||
// FIXME: Handle result
|
||||
context
|
||||
.processor_mut()
|
||||
.layer_indexing_finished(&tile_request.coords, index.get_geometries());
|
||||
@ -78,6 +79,7 @@ impl Processable for TessellateLayer {
|
||||
|
||||
let mut tessellator = ZeroTessellator::<IndexDataType>::default();
|
||||
if let Err(e) = layer.process(&mut tessellator) {
|
||||
// FIXME: Handle result
|
||||
context
|
||||
.processor_mut()
|
||||
.layer_unavailable(coords, layer_name);
|
||||
@ -89,6 +91,7 @@ impl Processable for TessellateLayer {
|
||||
e
|
||||
);
|
||||
} else {
|
||||
// FIXME: Handle result
|
||||
context.processor_mut().layer_tesselation_finished(
|
||||
coords,
|
||||
tessellator.buffer.into(),
|
||||
@ -105,6 +108,7 @@ impl Processable for TessellateLayer {
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
for missing_layer in tile_request.layers.difference(&available_layers) {
|
||||
// FIXME: Handle result
|
||||
context
|
||||
.processor_mut()
|
||||
.layer_unavailable(coords, missing_layer);
|
||||
@ -118,6 +122,7 @@ impl Processable for TessellateLayer {
|
||||
|
||||
tracing::info!("tile tessellated at {} finished", &tile_request.coords);
|
||||
|
||||
// FIXME: Handle result
|
||||
context.processor_mut().tile_finished(&tile_request.coords);
|
||||
|
||||
(tile_request, tile)
|
||||
|
||||
@ -66,7 +66,7 @@ pub struct DefaultTessellatedLayer {
|
||||
pub buffer: OverAlignedVertexBuffer<ShaderVertex, IndexDataType>,
|
||||
/// Holds for each feature the count of indices.
|
||||
pub feature_indices: Vec<u32>,
|
||||
pub layer_data: Layer, // FIXME (wasm-executor): Introduce a better structure for this
|
||||
pub layer_data: Layer, // FIXME (perf): Introduce a better structure for this
|
||||
}
|
||||
|
||||
impl TessellatedLayer for DefaultTessellatedLayer {
|
||||
|
||||
@ -52,12 +52,16 @@ pub struct HeadedPipelineProcessor<T: Transferables, HC: HttpClient, C: Context<
|
||||
impl<'c, T: Transferables, HC: HttpClient, C: Context<T, HC>> PipelineProcessor
|
||||
for HeadedPipelineProcessor<T, HC, C>
|
||||
{
|
||||
fn tile_finished(&mut self, coords: &WorldTileCoords) {
|
||||
fn tile_finished(&mut self, coords: &WorldTileCoords) -> Result<(), Error> {
|
||||
self.context
|
||||
.send(Message::TileTessellated(T::TileTessellated::new(*coords)))
|
||||
}
|
||||
|
||||
fn layer_unavailable(&mut self, coords: &WorldTileCoords, layer_name: &str) {
|
||||
fn layer_unavailable(
|
||||
&mut self,
|
||||
coords: &WorldTileCoords,
|
||||
layer_name: &str,
|
||||
) -> Result<(), Error> {
|
||||
self.context
|
||||
.send(Message::UnavailableLayer(T::UnavailableLayer::new(
|
||||
*coords,
|
||||
@ -71,7 +75,7 @@ impl<'c, T: Transferables, HC: HttpClient, C: Context<T, HC>> PipelineProcessor
|
||||
buffer: OverAlignedVertexBuffer<ShaderVertex, IndexDataType>,
|
||||
feature_indices: Vec<u32>,
|
||||
layer_data: tile::Layer,
|
||||
) {
|
||||
) -> Result<(), Error> {
|
||||
self.context
|
||||
.send(Message::TessellatedLayer(T::TessellatedLayer::new(
|
||||
*coords,
|
||||
|
||||
@ -106,6 +106,7 @@ pub fn schedule<
|
||||
log::error!("{:?}", &e);
|
||||
for to_load in &input.layers {
|
||||
tracing::warn!("layer {} at {} unavailable", to_load, coords);
|
||||
// FIXME: Handle result
|
||||
context.send(
|
||||
Message::UnavailableLayer(<<E::AsyncProcedureCall as AsyncProcedureCall<
|
||||
E::HttpClient,
|
||||
|
||||
@ -62,7 +62,6 @@ impl<V, I> OverAlignedVertexBuffer<V, I> {
|
||||
V: Copy,
|
||||
I: Copy,
|
||||
{
|
||||
// FIXME (wasm-executor), make this fn not needed
|
||||
let mut buffers = VertexBuffers::with_capacity(0, 0);
|
||||
buffers.vertices = Vec::from(vertices);
|
||||
buffers.indices = Vec::from(indices);
|
||||
|
||||
@ -13,19 +13,19 @@ pub struct WebWorkerPoolScheduler {
|
||||
|
||||
impl WebWorkerPoolScheduler {
|
||||
pub fn new(new_worker: js_sys::Function) -> Self {
|
||||
Self {
|
||||
pool: WorkerPool::new(
|
||||
1,
|
||||
Box::new(move || {
|
||||
new_worker
|
||||
.call0(&JsValue::undefined())
|
||||
.unwrap() // FIXME (wasm-executor): Remove unwrap
|
||||
.dyn_into::<Worker>()
|
||||
.unwrap() // FIXME (wasm-executor): remove unwrap
|
||||
}),
|
||||
)
|
||||
.unwrap(), // FIXME (wasm-executor): Remove unwrap
|
||||
}
|
||||
// TODO: Are expects here oke?
|
||||
let pool = WorkerPool::new(
|
||||
1,
|
||||
Box::new(move || {
|
||||
new_worker
|
||||
.call0(&JsValue::undefined())
|
||||
.expect("Unable to call new_worker function")
|
||||
.dyn_into::<Worker>()
|
||||
.expect("new_worker function did not return a Worker")
|
||||
}),
|
||||
)
|
||||
.expect("Unable to create WorkerPool");
|
||||
Self { pool }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@ use std::{
|
||||
use js_sys::Uint8Array;
|
||||
use maplibre::{
|
||||
environment::Environment,
|
||||
error::Error,
|
||||
io::{
|
||||
apc::{AsyncProcedure, AsyncProcedureCall, Context, Input, Message},
|
||||
scheduler::Scheduler,
|
||||
@ -120,7 +121,7 @@ pub struct PassingContext {
|
||||
}
|
||||
|
||||
impl Context<UsedTransferables, UsedHttpClient> for PassingContext {
|
||||
fn send(&self, data: Message<UsedTransferables>) {
|
||||
fn send(&self, data: Message<UsedTransferables>) -> Result<(), Error> {
|
||||
let tag = data.tag();
|
||||
let serialized = data.serialize();
|
||||
|
||||
@ -130,11 +131,13 @@ impl Context<UsedTransferables, UsedHttpClient> for PassingContext {
|
||||
serialized_array.set(&Uint8Array::view(serialized), 0);
|
||||
}
|
||||
|
||||
let global = js_sys::global().unchecked_into::<DedicatedWorkerGlobalScope>(); // FIXME (wasm-executor): Remove unchecked
|
||||
let global = js_sys::global()
|
||||
.try_into::<DedicatedWorkerGlobalScope>()
|
||||
.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).unwrap(); // FIXME (wasm-executor) Remove unwrap
|
||||
global.post_message(&array).map_err(|e| Error::APC)
|
||||
}
|
||||
|
||||
fn source_client(&self) -> &SourceClient<UsedHttpClient> {
|
||||
|
||||
@ -131,7 +131,8 @@ impl TessellatedLayer for LinearTessellatedLayer {
|
||||
}
|
||||
|
||||
fn to_stored_layer(self) -> StoredLayer {
|
||||
let layer = StoredLayer::TessellatedLayer {
|
||||
// TODO: Avoid copies here
|
||||
StoredLayer::TessellatedLayer {
|
||||
coords: WrapperWorldTileCoords::peel(self.data.coords),
|
||||
layer_name: String::from_utf8(Vec::from(
|
||||
&self.data.layer_name[..self.data.layer_name_len],
|
||||
@ -143,9 +144,7 @@ impl TessellatedLayer for LinearTessellatedLayer {
|
||||
self.data.usable_indices,
|
||||
),
|
||||
feature_indices: Vec::from(&self.data.feature_indices[..self.data.feature_indices_len]),
|
||||
};
|
||||
|
||||
layer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user