author | Wuzzy <Wuzzy@disroot.org> |
Mon, 19 Jun 2023 14:09:37 +0200 | |
changeset 15960 | 79b1129b4d03 |
parent 15828 | 44b49f255e31 |
child 15905 | 022ec6b916b7 |
permissions | -rw-r--r-- |
15828 | 1 |
use crate::{ |
2 |
outline::OutlinePoints, outline_template::OutlineTemplate, LandGenerationParameters, |
|
3 |
LandGenerator, |
|
4 |
}; |
|
14069 | 5 |
use integral_geometry::{Point, Size}; |
14026 | 6 |
use land2d::Land2D; |
14066
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14054
diff
changeset
|
7 |
|
14054
3185fb34f3b5
update theme editor to use new land generator implementation
alfadur
parents:
14052
diff
changeset
|
8 |
pub struct TemplatedLandGenerator { |
14026 | 9 |
outline_template: OutlineTemplate, |
10 |
} |
|
11 |
||
12 |
impl TemplatedLandGenerator { |
|
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
13 |
pub fn new(outline_template: OutlineTemplate) -> Self { |
14026 | 14 |
Self { outline_template } |
15 |
} |
|
16 |
} |
|
17 |
||
18 |
impl LandGenerator for TemplatedLandGenerator { |
|
19 |
fn generate_land<T: Copy + PartialEq, I: Iterator<Item = u32>>( |
|
20 |
&self, |
|
14121 | 21 |
parameters: &LandGenerationParameters<T>, |
14026 | 22 |
random_numbers: &mut I, |
23 |
) -> Land2D<T> { |
|
14078 | 24 |
let mut land = Land2D::new(self.outline_template.size, parameters.basic); |
14026 | 25 |
|
14100 | 26 |
let mut points = OutlinePoints::from_outline_template( |
27 |
&self.outline_template, |
|
28 |
land.play_box(), |
|
15828 | 29 |
land.size().size(), |
14100 | 30 |
random_numbers, |
31 |
); |
|
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
32 |
|
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
33 |
// mirror |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
34 |
if self.outline_template.can_mirror { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
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:
14026
diff
changeset
|
36 |
if b & 1 != 0 { |
14095 | 37 |
points.mirror(); |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
38 |
} |
14026 | 39 |
} |
40 |
} |
|
41 |
||
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
42 |
// flip |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
43 |
if self.outline_template.can_flip { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
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:
14026
diff
changeset
|
45 |
if b & 1 != 0 { |
14095 | 46 |
points.flip(); |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
47 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
48 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
49 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
50 |
|
14121 | 51 |
if !parameters.skip_distort { |
52 |
points.distort(parameters.distance_divisor, random_numbers); |
|
53 |
} |
|
54 |
||
55 |
if !parameters.skip_bezier { |
|
14140 | 56 |
points.bezierize(5); |
14121 | 57 |
} |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
58 |
|
14066
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14054
diff
changeset
|
59 |
points.draw(&mut land, parameters.zero); |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
60 |
|
14066
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14054
diff
changeset
|
61 |
for p in &points.fill_points { |
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14054
diff
changeset
|
62 |
land.fill(*p, parameters.zero, parameters.zero) |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
63 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
64 |
|
14066
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14054
diff
changeset
|
65 |
points.draw(&mut land, parameters.basic); |
14026 | 66 |
|
67 |
land |
|
68 |
} |
|
69 |
} |