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