author | unC0Rr |
Mon, 02 Dec 2024 17:36:44 +0100 | |
branch | transitional_engine |
changeset 16074 | 58a2d806fc47 |
parent 16073 | 5c941f5deeec |
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> { |
|
16058 | 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); |
|
14047 | 30 |
|
14121 | 31 |
let mut points = OutlinePoints::from_outline_template( |
32 |
&self.outline_template, |
|
33 |
land.play_box(), |
|
15850 | 34 |
land.size().size(), |
14121 | 35 |
random_numbers, |
36 |
); |
|
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
37 |
|
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
38 |
// mirror |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
39 |
if self.outline_template.can_mirror { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
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:
14047
diff
changeset
|
41 |
if b & 1 != 0 { |
14116 | 42 |
points.mirror(); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
43 |
} |
14047 | 44 |
} |
45 |
} |
|
46 |
||
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
47 |
// flip |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
48 |
if self.outline_template.can_flip { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
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:
14047
diff
changeset
|
50 |
if b & 1 != 0 { |
14116 | 51 |
points.flip(); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
52 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
53 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
54 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
55 |
|
14142 | 56 |
if !parameters.skip_distort { |
16064 | 57 |
let distortion_limiting_factor = 100 + random_numbers.next().unwrap() % 8 * 10; |
58 |
||
16073
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16064
diff
changeset
|
59 |
points.distort( |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16064
diff
changeset
|
60 |
parameters.distance_divisor, |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16064
diff
changeset
|
61 |
distortion_limiting_factor, |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16064
diff
changeset
|
62 |
random_numbers, |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16064
diff
changeset
|
63 |
); |
14142 | 64 |
} |
65 |
||
66 |
if !parameters.skip_bezier { |
|
14161 | 67 |
points.bezierize(5); |
14142 | 68 |
} |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
69 |
|
16058 | 70 |
points.draw(&mut land, zero); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
71 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
72 |
for p in &points.fill_points { |
16058 | 73 |
land.fill(*p, zero, zero) |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
74 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
75 |
|
16058 | 76 |
points.draw(&mut land, basic); |
14047 | 77 |
|
78 |
land |
|
79 |
} |
|
80 |
} |