diff --git a/Cargo.toml b/Cargo.toml index 7ef79cf..ba33ff0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,6 @@ edition = "2021" [dependencies] macroquad = "0.3" glob = "0.3.0" -futures = "0.3.21" \ No newline at end of file +futures = "0.3.21" +egui-macroquad = "0.11.0" +egui = "0.18.1" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 37af0e7..b614659 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use glob::{glob, GlobError}; use std::collections::VecDeque; +use std::sync::Arc; use std::{ collections::HashMap, path::PathBuf, @@ -51,7 +52,7 @@ fn get_files_in_dir(path: &str, filetype: &str) -> Result, GlobErro Ok(paths) } -const TILE_DIR: &str = "./tile_images/terrain/"; +const TILE_DIR: &str = "./tile_images/world/terrain/"; const LOD_FUZZYNESS: f32 = 1.0; fn coord_to_screen_pos(x: f32, y: f32, camera: &CameraSettings) -> (f32, f32) { @@ -126,11 +127,12 @@ fn sector_at_screen_pos( /// stores texture in hdd_texture_cache. Does not check if it is already there. async fn cache_texture( tile_data: (i32, i32, usize), + tile_dir: String, results_tx: Sender<((i32, i32, usize), Option)>, ) { let (sector_x, sector_y, lod) = tile_data; - let texture_dir = TILE_DIR.to_owned() + let texture_dir = tile_dir.to_owned() + &lod.to_string() + "/" + §or_x.to_string() @@ -403,6 +405,17 @@ struct CameraSettings { zoom_multiplier: f32, } +#[derive(PartialEq)] +#[derive(Debug)] +enum MapType{ + Terrain, + Night, + Height, + Biome, + Simple, + Light, +} + #[macroquad::main("Map Renderer")] async fn main() { // get initial tile dimensions @@ -452,7 +465,20 @@ async fn main() { let mut rolling_decode_buffer: VecDeque = VecDeque::new(); let mut rolling_average_decode_time: f64 = 0.0; + let mut render_lod_lines = false; + let mut selected_map_type = MapType::Terrain; + loop { + + let tile_type_string = match selected_map_type{ + MapType::Terrain => "terrain", + MapType::Night => "night", + MapType::Height => "height", + MapType::Biome => "biome", + MapType::Simple => "simple", + MapType::Light => "light", + }; + let tile_dir = "./tile_images/world/".to_owned() + tile_type_string + "/"; let frame_start_time = get_time(); clear_background(GRAY); @@ -602,7 +628,8 @@ async fn main() { // }; if let None = retriving_pools.get(&(sector_x, sector_y, lod)) { - let f = cache_texture((sector_x, sector_y, lod), results_tx.clone()); + let tile_dir2 = tile_dir.clone(); + let f = cache_texture((sector_x, sector_y, lod), tile_dir2, results_tx.clone()); // spawner.spawn_local(f).unwrap(); @@ -665,23 +692,20 @@ async fn main() { } } - // if textures_decoded > 0{ - // println!("textures_decoded: {}",textures_decoded); - // } - // remove any finished tiles for (tile_x, tile_y, tile_lod) in finished_tiles { retriving_pools.remove(&(tile_x, tile_y, tile_lod)); } - // println!("retriving_pools.len(): {}", retriving_pools.len()); //< - draw_tile_lines(&camera, lod, tile_dimensions); - + if render_lod_lines { + draw_tile_lines(&camera, lod, tile_dimensions); + } + let text_x_offset = 180.0; draw_text( &("fps: ".to_owned() + &get_fps().to_string()), - 20.0, + text_x_offset, 20.0, 30.0, WHITE, @@ -689,7 +713,7 @@ async fn main() { draw_text( &("zoom_multiplier: ".to_owned() + &camera.zoom_multiplier.to_string()), - 20.0, + text_x_offset, 40.0, 30.0, WHITE, @@ -697,7 +721,7 @@ async fn main() { draw_text( &("LOD: ".to_owned() + &lod.to_string()), - 20.0, + text_x_offset, 60.0, 30.0, WHITE, @@ -705,7 +729,7 @@ async fn main() { draw_text( &("rendered_tiles: ".to_owned() + &num_rendered_tiles.to_string()), - 20.0, + text_x_offset, 80.0, 30.0, WHITE, @@ -715,7 +739,7 @@ async fn main() { let mouse_coord = screen_pos_to_coord(mouse.0, mouse.1, &camera); draw_text( &("mouse.x: ".to_owned() + &mouse_coord.0.to_string()), - 20.0, + text_x_offset, 100.0, 30.0, WHITE, @@ -723,12 +747,47 @@ async fn main() { draw_text( &("mouse.y: ".to_owned() + &mouse_coord.1.to_string()), - 20.0, + text_x_offset, 120.0, 30.0, WHITE, ); + egui_macroquad::ui(|egui_ctx| { + egui::SidePanel::left("egui ❤ macroquad").show(egui_ctx, |ui| { + ui.heading("Render Options"); + + ui.checkbox(&mut render_lod_lines, "Render LOD lines"); + + egui::ComboBox::from_label("Select one!") + .selected_text(format!("{:?}", selected_map_type)) + .show_ui(ui, |ui| { + ui.selectable_value(&mut selected_map_type, MapType::Terrain, "Terrain"); + ui.selectable_value(&mut selected_map_type, MapType::Night, "Night"); + ui.selectable_value(&mut selected_map_type, MapType::Height, "Height"); + ui.selectable_value(&mut selected_map_type, MapType::Biome, "Biome"); + ui.selectable_value(&mut selected_map_type, MapType::Simple, "Simple"); + ui.selectable_value(&mut selected_map_type, MapType::Light, "Light"); + } + ); + + ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| { + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 0.0; + ui.label("powered by "); + ui.hyperlink_to("egui", "https://github.com/emilk/egui"); + ui.label(" and "); + ui.hyperlink_to( + "eframe", + "https://github.com/emilk/egui/tree/master/eframe", + ); + }); + }); + }); + }); + + egui_macroquad::draw(); + next_frame().await } }