author | unC0Rr |
Wed, 04 Jan 2023 11:56:58 +0100 | |
branch | transitional_engine |
changeset 15905 | 022ec6b916b7 |
parent 15828 | 44b49f255e31 |
child 15912 | 6e22f4390b7e |
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> { |
|
15905
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15828
diff
changeset
|
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 |
} |