mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Move example code to separate file
This commit is contained in:
parent
b5f9a64183
commit
0fec1fe28a
12
src/example.rs
Normal file
12
src/example.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use crate::io::cache::Cache;
|
||||
|
||||
pub const MUNICH_OFFSET_X: u32 = 2178;
|
||||
pub const MUNICH_OFFSET_Y: u32 = 1421;
|
||||
|
||||
pub fn fetch_munich_tiles(cache: &Cache) {
|
||||
for x in 0..6 {
|
||||
for y in 0..6 {
|
||||
cache.fetch((MUNICH_OFFSET_X + x, MUNICH_OFFSET_Y + y, 12).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,10 +2,10 @@ mod fps_meter;
|
||||
mod input;
|
||||
mod platform;
|
||||
|
||||
// FIXME: Should not be public, currenlty used because of shader_ffi
|
||||
pub mod render;
|
||||
pub(crate) mod example;
|
||||
pub(crate) mod io;
|
||||
pub(crate) mod render;
|
||||
pub(crate) mod util;
|
||||
|
||||
pub mod io;
|
||||
pub mod main_loop;
|
||||
pub mod tesselation;
|
||||
mod util;
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use crate::example::fetch_munich_tiles;
|
||||
use log::{error, info, trace};
|
||||
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
@ -10,11 +11,7 @@ use crate::render::state::State;
|
||||
pub async fn setup(window: winit::window::Window, event_loop: EventLoop<()>, cache: Box<Cache>) {
|
||||
info!("== mapr ==");
|
||||
|
||||
for x in 0..6 {
|
||||
for y in 0..6 {
|
||||
cache.fetch((2178 + x, 1421 + y, 12).into())
|
||||
}
|
||||
}
|
||||
fetch_munich_tiles(cache.as_ref());
|
||||
|
||||
let mut input = InputHandler::new();
|
||||
let mut state = State::new(&window).await;
|
||||
|
||||
@ -61,12 +61,6 @@ pub async fn run(cache_ptr: *mut Cache) {
|
||||
height: body.client_height(),
|
||||
});
|
||||
|
||||
/* for x in 0..6 {
|
||||
for y in 0..6 {
|
||||
cache.fetch((2178 + x, 1421 + y, 12).into())
|
||||
}
|
||||
}*/
|
||||
|
||||
// Either call forget or the main loop to keep cache alive
|
||||
//std::mem::forget(cache);
|
||||
crate::main_loop::setup(window, event_loop, cache).await;
|
||||
@ -84,6 +78,6 @@ pub async fn run_cache_loop(cache_ptr: *mut Cache) {
|
||||
let mut cache: Box<Cache> = unsafe { Box::from_raw(cache_ptr) };
|
||||
|
||||
// Either call forget or the cache loop to keep cache alive
|
||||
// std::mem::forget(cache);
|
||||
cache.run_loop();
|
||||
std::mem::forget(cache);
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ use crate::tesselation::IndexDataType;
|
||||
/// Buffer and its size
|
||||
pub struct BackingBufferDescriptor<B>(pub B, pub wgpu::BufferAddress);
|
||||
|
||||
trait Queue<B> {
|
||||
pub trait Queue<B> {
|
||||
fn write_buffer(&self, buffer: &B, offset: wgpu::BufferAddress, data: &[u8]);
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ use std::default::Default;
|
||||
use std::io::Cursor;
|
||||
use std::ops::Range;
|
||||
|
||||
use crate::example::{MUNICH_OFFSET_X, MUNICH_OFFSET_Y};
|
||||
use log::{trace, warn};
|
||||
use lyon::tessellation::VertexBuffers;
|
||||
use wgpu::util::DeviceExt;
|
||||
@ -366,15 +367,12 @@ impl State {
|
||||
// TODO: Could we draw inspiration from StagingBelt (https://docs.rs/wgpu/latest/wgpu/util/struct.StagingBelt.html)?
|
||||
// TODO: What is StagingBelt for?
|
||||
pub fn upload_tile_geometry(&mut self, cache: &Cache) {
|
||||
const OFFSET_X: u32 = 2178;
|
||||
const OFFSET_Y: u32 = 1421;
|
||||
|
||||
let upload = cache.pop_all();
|
||||
|
||||
for tile in upload.iter() {
|
||||
let new_coords = TileCoords {
|
||||
x: tile.coords.x - OFFSET_X,
|
||||
y: tile.coords.y - OFFSET_Y,
|
||||
x: tile.coords.x - MUNICH_OFFSET_X,
|
||||
y: tile.coords.y - MUNICH_OFFSET_Y,
|
||||
z: tile.coords.z,
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user