diff --git a/Cargo.toml b/Cargo.toml index 3ac6c3c..29dea0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,10 +49,11 @@ serde = "1.0.197" serde_json = "1.0.115" rust-embed = "8.3.0" tinyfiledialogs = "3.9.1" -# regex = { version = "1.10.4", optional = true } -# telnet = { version = "0.2.1", optional = true } +# dt = "1.0.6" +dt = {git = "https://github.com/iMilchshake/dt"} + [dev-dependencies] telnet = { version = "0.2.1"} diff --git a/src/config.rs b/src/config.rs index 6a3291e..bbb46a4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -47,6 +47,9 @@ pub struct GenerationConfig { /// probability for doing the last shift direction again pub momentum_prob: f32, + /// TODO: + pub max_distance: f32, + // ------- TODO: these should go somewhere else ----- pub waypoints: Vec, } @@ -103,6 +106,7 @@ impl Default for GenerationConfig { step_weights: vec![20, 11, 10, 9], platform_distance_bounds: (500, 750), momentum_prob: 0.01, + max_distance: 3.0, } } } diff --git a/src/editor.rs b/src/editor.rs index 44f1c78..64526af 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -127,7 +127,12 @@ pub fn edit_pos_i32(ui: &mut Ui, value: &mut i32) { ui.add(egui::DragValue::new(value).clamp_range(0..=isize::max_value())); } -pub fn edit_f32(ui: &mut Ui, value: &mut f32) { +// TODO: IMAGINE having a dynamic range argument.. imagine, that would be nice +pub fn edit_f32_wtf(ui: &mut Ui, value: &mut f32) { + ui.add(egui::Slider::new(value, 0.0..=15.0)); +} + +pub fn edit_f32_prob(ui: &mut Ui, value: &mut f32) { ui.add(egui::Slider::new(value, 0.0..=1.0)); } @@ -339,14 +344,14 @@ impl Editor { field_edit_widget( ui, &mut self.config.inner_rad_mut_prob, - edit_f32, + edit_f32_prob, "inner rad mut prob", true, ); field_edit_widget( ui, &mut self.config.inner_size_mut_prob, - edit_f32, + edit_f32_prob, "inner size mut prob", true, ); @@ -354,14 +359,14 @@ impl Editor { field_edit_widget( ui, &mut self.config.outer_rad_mut_prob, - edit_f32, + edit_f32_prob, "outer rad mut prob", true, ); field_edit_widget( ui, &mut self.config.outer_size_mut_prob, - edit_f32, + edit_f32_prob, "outer size mut prob", true, ); @@ -377,11 +382,27 @@ impl Editor { field_edit_widget( ui, &mut self.config.momentum_prob, - edit_f32, + edit_f32_prob, + "momentum prob", + true, + ); + + field_edit_widget( + ui, + &mut self.config.momentum_prob, + edit_f32_prob, "momentum prob", true, ); + field_edit_widget( + ui, + &mut self.config.max_distance, + edit_f32_wtf, + "max distance", + true, + ); + // only show these in setup mode ui.add_visible_ui(self.is_setup(), |ui| { vec_edit_widget( diff --git a/src/generator.rs b/src/generator.rs index 82af397..d0c6815 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -7,13 +7,13 @@ use crate::{ walker::CuteWalker, }; -use ndarray::{s, Array2}; +use dt::{dt, dt_bool, dt_int}; +use ndarray::{arr2, s, Array, Array2, Ix2, IxDyn}; pub struct Generator { pub walker: CuteWalker, pub map: Map, pub rnd: Random, - // TODO: should this really be part of the generator? } impl Generator { @@ -97,7 +97,27 @@ impl Generator { Ok(edge_bug) } - pub fn post_processing(&mut self) { + pub fn fill_area(&mut self, max_distance: &f32) -> Array2 { + let grid = self.map.grid.map(|val| *val != BlockType::Empty); + + let distance = dt_bool::(&grid.into_dyn()) + .into_dimensionality::() + .unwrap(); + + // let max = distance.fold(0.0, |v1, v2| f32::max(v1, *v2)); + + self.map + .grid + .zip_mut_with(&distance, |block_type, distance| { + if *block_type == BlockType::Empty && *distance > *max_distance { + *block_type = BlockType::Freeze; + } + }); + + distance + } + + pub fn post_processing(&mut self, config: &GenerationConfig) { self.fix_edge_bugs().expect("fix edge bugs failed"); self.map .generate_room(&self.map.spawn.clone(), 4, Some(&BlockType::Start)) @@ -105,6 +125,8 @@ impl Generator { self.map .generate_room(&self.walker.pos.clone(), 4, Some(&BlockType::Finish)) .expect("start finish room generation"); + + self.fill_area(&config.max_distance); } /// Generates an entire map with a single function call. This function is used by the CLI. @@ -124,7 +146,7 @@ impl Generator { gen.step(&config)?; } - gen.post_processing(); + gen.post_processing(config); Ok(gen.map) } diff --git a/src/main.rs b/src/main.rs index 5c2e3e0..4466459 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,7 +88,7 @@ async fn main() { // this is called ONCE after map was generated if editor.gen.walker.finished && !editor.is_setup() { - editor.gen.post_processing(); + editor.gen.post_processing(&editor.config); // switch into setup mode for next map editor.set_setup();