2 use crate::{LandGenerationParameters, LandGenerator}; |
2 use crate::{LandGenerationParameters, LandGenerator}; |
3 use integral_geometry::{Point, Polygon, Rect, Size}; |
3 use integral_geometry::{Point, Polygon, Rect, Size}; |
4 use land2d::Land2D; |
4 use land2d::Land2D; |
5 |
5 |
6 pub struct MazeTemplate { |
6 pub struct MazeTemplate { |
7 width: usize, |
7 pub width: usize, |
8 height: usize, |
8 pub height: usize, |
9 cell_size: usize, |
9 pub cell_size: usize, |
10 inverted: bool, |
10 pub inverted: bool, |
11 distortion_limiting_factor: u32, |
11 pub distortion_limiting_factor: u32, |
12 braidness: usize, |
12 pub braidness: usize, |
13 } |
13 } |
14 |
14 |
15 pub struct MazeLandGenerator { |
15 pub struct MazeLandGenerator { |
16 maze_template: MazeTemplate, |
16 maze_template: MazeTemplate, |
17 } |
17 } |
46 |
46 |
47 let num_steps = if self.maze_template.inverted { 3 } else { 1 }; |
47 let num_steps = if self.maze_template.inverted { 3 } else { 1 }; |
48 let mut step_done = vec![false; num_steps]; |
48 let mut step_done = vec![false; num_steps]; |
49 let mut last_cell = vec![Point::diag(0); num_steps]; |
49 let mut last_cell = vec![Point::diag(0); num_steps]; |
50 let mut came_from_pos = vec![0; num_steps]; |
50 let mut came_from_pos = vec![0; num_steps]; |
51 let mut came_from = vec![vec![Point::diag(0); num_cells.area()]; num_steps]; |
51 let mut came_from = vec![vec![Point::diag(0); num_steps]; num_cells.area()]; |
52 |
52 |
53 let mut done = false; |
53 let mut done = false; |
54 let mut seen_list = vec![vec![None as Option<usize>; seen_cells.width]; seen_cells.height]; |
54 let mut seen_list = vec![vec![None as Option<usize>; seen_cells.width]; seen_cells.height]; |
55 let mut x_walls = vec![vec![true; seen_cells.width]; seen_cells.height - 1]; |
55 let mut x_walls = vec![vec![true; seen_cells.width]; seen_cells.height - 1]; |
56 let mut y_walls = vec![vec![true; seen_cells.width - 1]; seen_cells.height]; |
56 let mut y_walls = vec![vec![true; seen_cells.width - 1]; seen_cells.height]; |
64 for current_step in 0..num_steps { |
64 for current_step in 0..num_steps { |
65 let x = random_numbers.next().unwrap_or_default() as usize % (seen_cells.width - 1) |
65 let x = random_numbers.next().unwrap_or_default() as usize % (seen_cells.width - 1) |
66 / num_steps; |
66 / num_steps; |
67 last_cell[current_step] = Point::new( |
67 last_cell[current_step] = Point::new( |
68 (x + current_step * seen_cells.width / num_steps) as i32, |
68 (x + current_step * seen_cells.width / num_steps) as i32, |
69 random_numbers.next().unwrap_or_default() as i32 / num_steps as i32, |
69 random_numbers.next().unwrap_or_default() as i32 % seen_cells.height as i32, |
70 ); |
70 ); |
71 } |
71 } |
72 |
72 |
73 let see_cell = |current_step: usize, start_dir: Point, seen_list: &mut Vec<Vec<Option<usize>>>, x_walls: &mut Vec<Vec<bool>>, y_walls: &mut Vec<Vec<bool>>, |
73 let see_cell = |current_step: usize, start_dir: Point, seen_list: &mut Vec<Vec<Option<usize>>>, x_walls: &mut Vec<Vec<bool>>, y_walls: &mut Vec<Vec<bool>>, |
74 last_cell: &mut Vec<Point>, came_from: &mut Vec<Vec<Point>>, came_from_pos: &mut Vec<i32>| { |
74 last_cell: &mut Vec<Point>, came_from: &mut Vec<Vec<Point>>, came_from_pos: &mut Vec<i32>| { |
|
75 let mut dir = start_dir; |
75 loop { |
76 loop { |
76 let p = last_cell[current_step]; |
77 let p = dbg!(last_cell[current_step]); |
77 seen_list[p.y as usize][p.x as usize] = Some(current_step); |
78 seen_list[p.y as usize][p.x as usize] = Some(dbg!(current_step)); |
78 |
|
79 let mut dir = start_dir; |
|
80 |
79 |
81 let next_dir_clockwise = true;//random_numbers.next().unwrap_or_default() % 2 == 0; |
80 let next_dir_clockwise = true;//random_numbers.next().unwrap_or_default() % 2 == 0; |
82 |
81 |
83 for _ in 0..5 { |
82 for _ in 0..5 { |
84 let sp = p + dir; |
83 let sp = dbg!(p) + dbg!(dir); |
85 let when_seen = |
84 let when_seen = |
86 if sp.x < 0 |
85 if sp.x < 0 |
87 || sp.x >= seen_cells.width as i32 |
86 || sp.x >= seen_cells.width as i32 |
88 || sp.y < 0 |
87 || sp.y < 0 |
89 || sp.y >= seen_cells.height as i32 |
88 || sp.y >= seen_cells.height as i32 |
128 y_walls[p.y as usize][p.x as usize - 1] = false; |
127 y_walls[p.y as usize][p.x as usize - 1] = false; |
129 } |
128 } |
130 if dir.x == 1 { |
129 if dir.x == 1 { |
131 y_walls[p.y as usize][p.x as usize] = false; |
130 y_walls[p.y as usize][p.x as usize] = false; |
132 } |
131 } |
133 last_cell[current_step] = p + dir; |
132 last_cell[current_step] = dbg!(sp); |
134 came_from_pos[current_step] += 1; |
133 came_from_pos[current_step] += 1; |
135 came_from[came_from_pos[current_step] as usize][current_step] = p; |
134 came_from[came_from_pos[current_step] as usize][current_step] = p; |
|
135 return true; |
136 } |
136 } |
137 _ => { |
137 _ => { |
138 return true; |
138 return true; |
139 } |
139 } |
140 } |
140 } |