author | unC0Rr |
Mon, 13 Feb 2023 12:31:30 +0100 | |
branch | transitional_engine |
changeset 15952 | da6b67f13c12 |
parent 15951 | 5f00829c55ec |
child 16058 | 9cbd18220eb7 |
permissions | -rw-r--r-- |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
1 |
use super::{outline::OutlinePoints, outline_template::OutlineTemplate}; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
2 |
use crate::{LandGenerationParameters, LandGenerator}; |
14047 | 3 |
use land2d::Land2D; |
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
4 |
|
14075
3185fb34f3b5
update theme editor to use new land generator implementation
alfadur
parents:
14073
diff
changeset
|
5 |
pub struct TemplatedLandGenerator { |
14047 | 6 |
outline_template: OutlineTemplate, |
7 |
} |
|
8 |
||
9 |
impl TemplatedLandGenerator { |
|
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
10 |
pub fn new(outline_template: OutlineTemplate) -> Self { |
14047 | 11 |
Self { outline_template } |
12 |
} |
|
13 |
} |
|
14 |
||
15 |
impl LandGenerator for TemplatedLandGenerator { |
|
15942 | 16 |
fn generate_land<T: Copy + PartialEq + Default, I: Iterator<Item = u32>>( |
14047 | 17 |
&self, |
14142 | 18 |
parameters: &LandGenerationParameters<T>, |
14047 | 19 |
random_numbers: &mut I, |
20 |
) -> Land2D<T> { |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15850
diff
changeset
|
21 |
let mut land = Land2D::new(&self.outline_template.size, parameters.basic); |
14047 | 22 |
|
14121 | 23 |
let mut points = OutlinePoints::from_outline_template( |
24 |
&self.outline_template, |
|
25 |
land.play_box(), |
|
15850 | 26 |
land.size().size(), |
14121 | 27 |
random_numbers, |
28 |
); |
|
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
29 |
|
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
30 |
// mirror |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
31 |
if self.outline_template.can_mirror { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
32 |
if let Some(b) = random_numbers.next() { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
33 |
if b & 1 != 0 { |
14116 | 34 |
points.mirror(); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
35 |
} |
14047 | 36 |
} |
37 |
} |
|
38 |
||
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
39 |
// flip |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
40 |
if self.outline_template.can_flip { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
41 |
if let Some(b) = random_numbers.next() { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
42 |
if b & 1 != 0 { |
14116 | 43 |
points.flip(); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
44 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
45 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
46 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
47 |
|
14142 | 48 |
if !parameters.skip_distort { |
49 |
points.distort(parameters.distance_divisor, random_numbers); |
|
50 |
} |
|
51 |
||
52 |
if !parameters.skip_bezier { |
|
14161 | 53 |
points.bezierize(5); |
14142 | 54 |
} |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
55 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
56 |
points.draw(&mut land, parameters.zero); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
57 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
58 |
for p in &points.fill_points { |
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
59 |
land.fill(*p, parameters.zero, parameters.zero) |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
60 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
61 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
62 |
points.draw(&mut land, parameters.basic); |
14047 | 63 |
|
64 |
land |
|
65 |
} |
|
66 |
} |