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