author | unc0rr |
Sat, 03 Nov 2018 18:29:58 +0100 | |
changeset 14142 | 69db1d2e4cec |
parent 14121 | 4d22be35cfa2 |
child 14161 | 3078123e84ea |
permissions | -rw-r--r-- |
14090 | 1 |
use integral_geometry::{Point, Size}; |
14047 | 2 |
use land2d::Land2D; |
3 |
use LandGenerationParameters; |
|
4 |
use LandGenerator; |
|
5 |
||
14090 | 6 |
use outline::OutlinePoints; |
7 |
use outline_template::OutlineTemplate; |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
8 |
|
14075
3185fb34f3b5
update theme editor to use new land generator implementation
alfadur
parents:
14073
diff
changeset
|
9 |
pub struct TemplatedLandGenerator { |
14047 | 10 |
outline_template: OutlineTemplate, |
11 |
} |
|
12 |
||
13 |
impl TemplatedLandGenerator { |
|
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
14 |
pub fn new(outline_template: OutlineTemplate) -> Self { |
14047 | 15 |
Self { outline_template } |
16 |
} |
|
17 |
} |
|
18 |
||
19 |
impl LandGenerator for TemplatedLandGenerator { |
|
20 |
fn generate_land<T: Copy + PartialEq, I: Iterator<Item = u32>>( |
|
21 |
&self, |
|
14142 | 22 |
parameters: &LandGenerationParameters<T>, |
14047 | 23 |
random_numbers: &mut I, |
24 |
) -> Land2D<T> { |
|
14099 | 25 |
let mut land = Land2D::new(self.outline_template.size, parameters.basic); |
14047 | 26 |
|
14121 | 27 |
let mut points = OutlinePoints::from_outline_template( |
28 |
&self.outline_template, |
|
29 |
land.play_box(), |
|
30 |
land.size(), |
|
31 |
random_numbers, |
|
32 |
); |
|
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
33 |
|
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
34 |
// mirror |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
35 |
if self.outline_template.can_mirror { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
36 |
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
|
37 |
if b & 1 != 0 { |
14116 | 38 |
points.mirror(); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
39 |
} |
14047 | 40 |
} |
41 |
} |
|
42 |
||
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
43 |
// flip |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
44 |
if self.outline_template.can_flip { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
45 |
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
|
46 |
if b & 1 != 0 { |
14116 | 47 |
points.flip(); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
48 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
49 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
50 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
51 |
|
14142 | 52 |
if !parameters.skip_distort { |
53 |
points.distort(parameters.distance_divisor, random_numbers); |
|
54 |
} |
|
55 |
||
56 |
if !parameters.skip_bezier { |
|
57 |
points.bezierize(); |
|
58 |
} |
|
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
59 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
60 |
points.draw(&mut land, parameters.zero); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
61 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
62 |
for p in &points.fill_points { |
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
63 |
land.fill(*p, parameters.zero, parameters.zero) |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
64 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
65 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
66 |
points.draw(&mut land, parameters.basic); |
14047 | 67 |
|
68 |
land |
|
69 |
} |
|
70 |
} |