From 0fec1fe28a2120758d08a577ee594470cc84bc96 Mon Sep 17 00:00:00 2001 From: Maximilian Ammann Date: Mon, 3 Jan 2022 10:32:34 +0100 Subject: [PATCH] Move example code to separate file --- src/example.rs | 12 ++++++++++++ src/lib.rs | 8 ++++---- src/main_loop.rs | 7 ++----- src/platform/web/mod.rs | 8 +------- src/render/buffer_pool.rs | 2 +- src/render/state.rs | 8 +++----- 6 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 src/example.rs diff --git a/src/example.rs b/src/example.rs new file mode 100644 index 00000000..ca039525 --- /dev/null +++ b/src/example.rs @@ -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()) + } + } +} diff --git a/src/lib.rs b/src/lib.rs index a92888d5..f5759c91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/main_loop.rs b/src/main_loop.rs index eb9f352c..972a6129 100644 --- a/src/main_loop.rs +++ b/src/main_loop.rs @@ -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) { 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; diff --git a/src/platform/web/mod.rs b/src/platform/web/mod.rs index f949833f..5b98d1d2 100644 --- a/src/platform/web/mod.rs +++ b/src/platform/web/mod.rs @@ -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 = 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); } diff --git a/src/render/buffer_pool.rs b/src/render/buffer_pool.rs index aeaaa7ec..9b7c4654 100644 --- a/src/render/buffer_pool.rs +++ b/src/render/buffer_pool.rs @@ -15,7 +15,7 @@ use crate::tesselation::IndexDataType; /// Buffer and its size pub struct BackingBufferDescriptor(pub B, pub wgpu::BufferAddress); -trait Queue { +pub trait Queue { fn write_buffer(&self, buffer: &B, offset: wgpu::BufferAddress, data: &[u8]); } diff --git a/src/render/state.rs b/src/render/state.rs index 71dabd9d..9af42d49 100644 --- a/src/render/state.rs +++ b/src/render/state.rs @@ -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, };