mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Start working on a specific headless API
This commit is contained in:
parent
1c297ff10b
commit
ad6a0be20d
@ -8,7 +8,7 @@ use maplibre::io::pipeline::{PipelineContext, PipelineProcessor};
|
||||
use maplibre::io::scheduler::ScheduleMethod;
|
||||
use maplibre::io::source_client::{HttpClient, HttpSourceClient};
|
||||
use maplibre::io::{LayerTessellateMessage, TileRequest, TileRequestID};
|
||||
use maplibre::map_schedule::{EventuallyMapContext, MapSchedule};
|
||||
use maplibre::map_schedule::{EventuallyMapContext, InteractiveMapSchedule};
|
||||
use maplibre::platform::http_client::ReqwestHttpClient;
|
||||
use maplibre::platform::run_multithreaded;
|
||||
use maplibre::platform::schedule_method::TokioScheduleMethod;
|
||||
@ -136,21 +136,19 @@ fn run_headless() {
|
||||
&mut pipeline_context,
|
||||
);
|
||||
|
||||
match &mut map.map_schedule_mut().map_context {
|
||||
EventuallyMapContext::Full(context) => {
|
||||
while let Some(v) = pipeline_context
|
||||
.processor
|
||||
.as_any_mut()
|
||||
.downcast_mut::<HeadlessPipelineProcessor>()
|
||||
.unwrap()
|
||||
.layers
|
||||
.pop()
|
||||
{
|
||||
context.tile_cache.put_tessellated_layer(v);
|
||||
}
|
||||
}
|
||||
EventuallyMapContext::Premature(_) => {}
|
||||
EventuallyMapContext::_Uninitialized => {}
|
||||
let mut processor = pipeline_context.teardown();
|
||||
|
||||
while let Some(v) = processor
|
||||
.as_any_mut()
|
||||
.downcast_mut::<HeadlessPipelineProcessor>()
|
||||
.unwrap()
|
||||
.layers
|
||||
.pop()
|
||||
{
|
||||
map.map_schedule_mut()
|
||||
.map_context
|
||||
.tile_cache
|
||||
.put_tessellated_layer(v);
|
||||
}
|
||||
|
||||
match map.map_schedule_mut().update_and_redraw() {
|
||||
@ -170,5 +168,6 @@ fn main() {
|
||||
#[cfg(feature = "trace")]
|
||||
enable_tracing();
|
||||
|
||||
run_headless()
|
||||
run_headless();
|
||||
run_in_window();
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ use winit::event::{ElementState, KeyboardInput, VirtualKeyCode, WindowEvent};
|
||||
use winit::event_loop::ControlFlow;
|
||||
|
||||
use crate::input::{InputController, UpdateState};
|
||||
use maplibre::map_schedule::MapSchedule;
|
||||
use maplibre::map_schedule::InteractiveMapSchedule;
|
||||
use maplibre::window::{EventLoop, HeadedMapWindow, MapWindow, MapWindowConfig};
|
||||
use winit::event::Event;
|
||||
|
||||
@ -71,7 +71,11 @@ where
|
||||
SM: ScheduleMethod,
|
||||
HC: HttpClient,
|
||||
{
|
||||
fn run(mut self, mut map_schedule: MapSchedule<MWC, SM, HC>, max_frames: Option<u64>) {
|
||||
fn run(
|
||||
mut self,
|
||||
mut map_schedule: InteractiveMapSchedule<MWC, SM, HC>,
|
||||
max_frames: Option<u64>,
|
||||
) {
|
||||
let mut last_render_time = Instant::now();
|
||||
let mut current_frame: u64 = 0;
|
||||
|
||||
|
||||
@ -70,7 +70,11 @@ pub struct PipelineContext {
|
||||
pub processor: Box<dyn PipelineProcessor>,
|
||||
}
|
||||
|
||||
impl PipelineContext {}
|
||||
impl PipelineContext {
|
||||
pub fn teardown(self) -> Box<dyn PipelineProcessor> {
|
||||
self.processor
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Processable {
|
||||
type Input;
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
use crate::io::scheduler::{ScheduleMethod, Scheduler};
|
||||
use crate::io::source_client::HttpClient;
|
||||
use crate::map_schedule::MapSchedule;
|
||||
use crate::map_schedule::{InteractiveMapSchedule, SimpleMapSchedule};
|
||||
use crate::render::settings::{RendererSettings, WgpuSettings};
|
||||
use crate::render::{RenderState, Renderer};
|
||||
use crate::style::Style;
|
||||
@ -53,7 +53,7 @@ where
|
||||
SM: ScheduleMethod,
|
||||
HC: HttpClient,
|
||||
{
|
||||
map_schedule: MapSchedule<MWC, SM, HC>,
|
||||
map_schedule: InteractiveMapSchedule<MWC, SM, HC>,
|
||||
window: MWC::MapWindow,
|
||||
}
|
||||
|
||||
@ -95,11 +95,31 @@ where
|
||||
self.window.run(self.map_schedule, max_frames);
|
||||
}
|
||||
|
||||
pub fn map_schedule(&self) -> &MapSchedule<MWC, SM, HC> {
|
||||
pub fn map_schedule(&self) -> &InteractiveMapSchedule<MWC, SM, HC> {
|
||||
&self.map_schedule
|
||||
}
|
||||
|
||||
pub fn map_schedule_mut(&mut self) -> &mut MapSchedule<MWC, SM, HC> {
|
||||
pub fn map_schedule_mut(&mut self) -> &mut InteractiveMapSchedule<MWC, SM, HC> {
|
||||
&mut self.map_schedule
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HeadlessMap<MWC, SM, HC>
|
||||
where
|
||||
MWC: MapWindowConfig,
|
||||
SM: ScheduleMethod,
|
||||
HC: HttpClient,
|
||||
{
|
||||
map_schedule: SimpleMapSchedule<MWC, SM, HC>,
|
||||
window: MWC::MapWindow,
|
||||
}
|
||||
impl<MWC, SM, HC> HeadlessMap<MWC, SM, HC>
|
||||
where
|
||||
MWC: MapWindowConfig,
|
||||
SM: ScheduleMethod,
|
||||
HC: HttpClient,
|
||||
{
|
||||
pub fn map_schedule_mut(&mut self) -> &mut SimpleMapSchedule<MWC, SM, HC> {
|
||||
&mut self.map_schedule
|
||||
}
|
||||
}
|
||||
@ -147,7 +167,7 @@ where
|
||||
.await
|
||||
.ok();
|
||||
Map {
|
||||
map_schedule: MapSchedule::new(
|
||||
map_schedule: InteractiveMapSchedule::new(
|
||||
self.map_window_config,
|
||||
window_size,
|
||||
renderer,
|
||||
@ -161,7 +181,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn initialize_headless(self) -> Map<MWC, SM, HC> {
|
||||
pub async fn initialize_headless(self) -> HeadlessMap<MWC, SM, HC> {
|
||||
let window = self.map_window_config.create();
|
||||
let window_size = window.size();
|
||||
|
||||
@ -171,17 +191,15 @@ where
|
||||
self.renderer_settings.clone(),
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
Map {
|
||||
map_schedule: MapSchedule::new(
|
||||
.expect("Failed to initialize renderer");
|
||||
HeadlessMap {
|
||||
map_schedule: SimpleMapSchedule::new(
|
||||
self.map_window_config,
|
||||
window_size,
|
||||
renderer,
|
||||
self.scheduler,
|
||||
self.http_client,
|
||||
self.style,
|
||||
self.wgpu_settings,
|
||||
self.renderer_settings,
|
||||
),
|
||||
window,
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ impl EventuallyMapContext {
|
||||
}
|
||||
|
||||
/// Stores the state of the map, dispatches tile fetching and caching, tessellation and drawing.
|
||||
pub struct MapSchedule<MWC, SM, HC>
|
||||
pub struct InteractiveMapSchedule<MWC, SM, HC>
|
||||
where
|
||||
MWC: MapWindowConfig,
|
||||
SM: ScheduleMethod,
|
||||
@ -82,7 +82,7 @@ where
|
||||
suspended: bool,
|
||||
}
|
||||
|
||||
impl<MWC, SM, HC> MapSchedule<MWC, SM, HC>
|
||||
impl<MWC, SM, HC> InteractiveMapSchedule<MWC, SM, HC>
|
||||
where
|
||||
MWC: MapWindowConfig,
|
||||
SM: ScheduleMethod,
|
||||
@ -103,7 +103,7 @@ where
|
||||
let mut schedule = Schedule::default();
|
||||
|
||||
let http_source_client: HttpSourceClient<HC> = HttpSourceClient::new(http_client);
|
||||
//register_stages(&mut schedule, http_source_client, Box::new(scheduler));
|
||||
register_stages(&mut schedule, http_source_client, Box::new(scheduler));
|
||||
|
||||
register_render_stages(&mut schedule);
|
||||
|
||||
@ -213,3 +213,71 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Stores the state of the map, dispatches tile fetching and caching, tessellation and drawing.
|
||||
pub struct SimpleMapSchedule<MWC, SM, HC>
|
||||
where
|
||||
MWC: MapWindowConfig,
|
||||
SM: ScheduleMethod,
|
||||
HC: HttpClient,
|
||||
{
|
||||
map_window_config: MWC,
|
||||
|
||||
pub map_context: MapContext,
|
||||
|
||||
schedule: Schedule,
|
||||
scheduler: Scheduler<SM>,
|
||||
http_client: HC,
|
||||
}
|
||||
|
||||
impl<MWC, SM, HC> SimpleMapSchedule<MWC, SM, HC>
|
||||
where
|
||||
MWC: MapWindowConfig,
|
||||
SM: ScheduleMethod,
|
||||
HC: HttpClient,
|
||||
{
|
||||
pub fn new(
|
||||
map_window_config: MWC,
|
||||
window_size: WindowSize,
|
||||
renderer: Renderer,
|
||||
scheduler: Scheduler<SM>,
|
||||
http_client: HC,
|
||||
style: Style,
|
||||
) -> Self {
|
||||
let view_state = ViewState::new(&window_size);
|
||||
let tile_cache = TileCache::new();
|
||||
let mut schedule = Schedule::default();
|
||||
|
||||
register_render_stages(&mut schedule);
|
||||
|
||||
Self {
|
||||
map_window_config,
|
||||
map_context: MapContext {
|
||||
view_state,
|
||||
style,
|
||||
tile_cache,
|
||||
renderer,
|
||||
},
|
||||
schedule,
|
||||
scheduler,
|
||||
http_client,
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(name = "update_and_redraw", skip_all)]
|
||||
pub fn update_and_redraw(&mut self) -> Result<(), Error> {
|
||||
self.schedule.run(&mut self.map_context);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn schedule(&self) -> &Schedule {
|
||||
&self.schedule
|
||||
}
|
||||
pub fn scheduler(&self) -> &Scheduler<SM> {
|
||||
&self.scheduler
|
||||
}
|
||||
pub fn http_client(&self) -> &HC {
|
||||
&self.http_client
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +102,6 @@ impl Default for Msaa {
|
||||
pub struct RendererSettings {
|
||||
pub msaa: Msaa,
|
||||
pub texture_format: wgpu::TextureFormat,
|
||||
pub surface_type: SurfaceType,
|
||||
}
|
||||
|
||||
impl Default for RendererSettings {
|
||||
@ -110,7 +109,6 @@ impl Default for RendererSettings {
|
||||
Self {
|
||||
msaa: Msaa::default(),
|
||||
texture_format: COLOR_TEXTURE_FORMAT,
|
||||
surface_type: SurfaceType::Headed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
//! Utilities for the window system.
|
||||
|
||||
use crate::{HttpClient, MapSchedule, ScheduleMethod};
|
||||
use crate::{HttpClient, InteractiveMapSchedule, ScheduleMethod};
|
||||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||
|
||||
/// Window with a [carte::window::WindowSize].
|
||||
@ -26,7 +26,7 @@ where
|
||||
SM: ScheduleMethod,
|
||||
HC: HttpClient,
|
||||
{
|
||||
fn run(self, map_schedule: MapSchedule<MWC, SM, HC>, max_frames: Option<u64>);
|
||||
fn run(self, map_schedule: InteractiveMapSchedule<MWC, SM, HC>, max_frames: Option<u64>);
|
||||
}
|
||||
|
||||
/// Window size with a width and an height in pixels.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user