Skip to content

Commit

Permalink
Add distance threshold for reaching waypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
iMilchshake committed Apr 21, 2024
1 parent 478832a commit f9559ac
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ pub struct GenerationConfig {
/// probability for doing the last shift direction again
pub momentum_prob: f32,

/// TODO:
/// maximum distance from empty blocks to nearest non empty block
pub max_distance: f32,

/// min distance to next waypoint that is considered reached
pub waypoint_reached_dist: usize,

// ------- TODO: these should go somewhere else -----
pub waypoints: Vec<Position>,
}
Expand Down Expand Up @@ -107,6 +110,7 @@ impl Default for GenerationConfig {
platform_distance_bounds: (500, 750),
momentum_prob: 0.01,
max_distance: 3.0,
waypoint_reached_dist: 250,
}
}
}
12 changes: 6 additions & 6 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,17 @@ impl Editor {

field_edit_widget(
ui,
&mut self.config.momentum_prob,
edit_f32_prob,
"momentum prob",
&mut self.config.max_distance,
edit_f32_wtf,
"max distance",
true,
);

field_edit_widget(
ui,
&mut self.config.max_distance,
edit_f32_wtf,
"max distance",
&mut self.config.waypoint_reached_dist,
edit_usize,
"waypoint reached dist",
true,
);

Expand Down
2 changes: 1 addition & 1 deletion src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Generator {

pub fn step(&mut self, config: &GenerationConfig) -> Result<(), &'static str> {
// check if walker has reached goal position
if self.walker.is_goal_reached() == Some(true) {
if self.walker.is_goal_reached(&config.waypoint_reached_dist) == Some(true) {
self.walker.next_waypoint();
}

Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ async fn main() {

clear_background(WHITE);
// draw_grid_blocks(&editor.gen.map.grid);
draw_waypoints(&editor.config.waypoints);
draw_chunked_grid(
&editor.gen.map.grid,
&editor.gen.map.chunk_edited,
editor.gen.map.chunk_size,
);
draw_walker(&editor.gen.walker);
draw_walker_kernel(&editor.gen.walker, KernelType::Outer);
draw_walker_kernel(&editor.gen.walker, KernelType::Inner);
draw_walker(&editor.gen.walker);

draw_waypoints(&editor.config.waypoints);

// if let Some(edge_bugs) = &edge_bugs {
// draw_bool_grid(edge_bugs, Color::new(1.0, 0.0, 0.0, 0.1));
Expand Down
6 changes: 4 additions & 2 deletions src/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ impl CuteWalker {
}
}

pub fn is_goal_reached(&self) -> Option<bool> {
self.goal.as_ref().map(|goal| self.pos.eq(goal))
pub fn is_goal_reached(&self, waypoint_reached_dist: &usize) -> Option<bool> {
self.goal
.as_ref()
.map(|goal| goal.distance_squared(&self.pos) < *waypoint_reached_dist)
}

pub fn next_waypoint(&mut self) {
Expand Down

0 comments on commit f9559ac

Please sign in to comment.