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