author | unC0Rr |
Tue, 03 Sep 2024 13:56:35 +0200 | |
branch | transitional_engine |
changeset 16029 | 9cbd18220eb7 |
parent 15922 | da6b67f13c12 |
child 16035 | 0caa3dfb3ba2 |
permissions | -rw-r--r-- |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15921
diff
changeset
|
1 |
use super::{outline::OutlinePoints, outline_template::OutlineTemplate}; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15921
diff
changeset
|
2 |
use crate::{LandGenerationParameters, LandGenerator}; |
14026 | 3 |
use land2d::Land2D; |
14066
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14054
diff
changeset
|
4 |
|
14054
3185fb34f3b5
update theme editor to use new land generator implementation
alfadur
parents:
14052
diff
changeset
|
5 |
pub struct TemplatedLandGenerator { |
14026 | 6 |
outline_template: OutlineTemplate, |
7 |
} |
|
8 |
||
9 |
impl TemplatedLandGenerator { |
|
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
10 |
pub fn new(outline_template: OutlineTemplate) -> Self { |
14026 | 11 |
Self { outline_template } |
12 |
} |
|
13 |
} |
|
14 |
||
15 |
impl LandGenerator for TemplatedLandGenerator { |
|
15912 | 16 |
fn generate_land<T: Copy + PartialEq + Default, I: Iterator<Item = u32>>( |
14026 | 17 |
&self, |
14121 | 18 |
parameters: &LandGenerationParameters<T>, |
14026 | 19 |
random_numbers: &mut I, |
20 |
) -> Land2D<T> { |
|
16029 | 21 |
let do_invert = self.outline_template.is_negative |
22 |
&& (!self.outline_template.can_invert || random_numbers.next().unwrap() & 1 == 0); |
|
23 |
let (basic, zero) = if do_invert { |
|
24 |
(parameters.zero, parameters.basic) |
|
25 |
} else { |
|
26 |
(parameters.basic, parameters.zero) |
|
27 |
}; |
|
28 |
||
29 |
let mut land = Land2D::new(&self.outline_template.size, basic); |
|
14026 | 30 |
|
14100 | 31 |
let mut points = OutlinePoints::from_outline_template( |
32 |
&self.outline_template, |
|
33 |
land.play_box(), |
|
15828 | 34 |
land.size().size(), |
14100 | 35 |
random_numbers, |
36 |
); |
|
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
37 |
|
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
38 |
// mirror |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
39 |
if self.outline_template.can_mirror { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
40 |
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
|
41 |
if b & 1 != 0 { |
14095 | 42 |
points.mirror(); |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
43 |
} |
14026 | 44 |
} |
45 |
} |
|
46 |
||
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
47 |
// flip |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
48 |
if self.outline_template.can_flip { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
49 |
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
|
50 |
if b & 1 != 0 { |
14095 | 51 |
points.flip(); |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
52 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
53 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
54 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
55 |
|
14121 | 56 |
if !parameters.skip_distort { |
57 |
points.distort(parameters.distance_divisor, random_numbers); |
|
58 |
} |
|
59 |
||
60 |
if !parameters.skip_bezier { |
|
14140 | 61 |
points.bezierize(5); |
14121 | 62 |
} |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
63 |
|
16029 | 64 |
points.draw(&mut land, zero); |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
65 |
|
14066
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14054
diff
changeset
|
66 |
for p in &points.fill_points { |
16029 | 67 |
land.fill(*p, zero, zero) |
14051
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
68 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14026
diff
changeset
|
69 |
|
16029 | 70 |
points.draw(&mut land, basic); |
14026 | 71 |
|
72 |
land |
|
73 |
} |
|
74 |
} |