author | alfadur |
Fri, 02 Nov 2018 19:37:47 +0300 | |
changeset 14109 | f483f844da98 |
parent 14099 | bf40b5f938b0 |
child 14116 | b2feb190e4bc |
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 |
|
3185fb34f3b5
update theme editor to use new land generator implementation
alfadur
parents:
14073
diff
changeset
|
10 |
pub struct TemplatedLandGenerator { |
14047 | 11 |
outline_template: OutlineTemplate, |
12 |
} |
|
13 |
||
14 |
impl TemplatedLandGenerator { |
|
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
15 |
pub fn new(outline_template: OutlineTemplate) -> Self { |
14047 | 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, |
|
23 |
parameters: LandGenerationParameters<T>, |
|
24 |
random_numbers: &mut I, |
|
25 |
) -> Land2D<T> { |
|
14099 | 26 |
let mut land = Land2D::new(self.outline_template.size, parameters.basic); |
14047 | 27 |
|
14099 | 28 |
let mut points = |
29 |
OutlinePoints::from_outline_template(&self.outline_template, land.play_box(), land.size(), random_numbers); |
|
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
30 |
|
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
31 |
// mirror |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
32 |
if self.outline_template.can_mirror { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
33 |
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
|
34 |
if b & 1 != 0 { |
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
35 |
points |
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
36 |
.iter_mut() |
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
37 |
.for_each(|p| p.x = land.width() as i32 - 1 - p.x); |
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
38 |
} |
14047 | 39 |
} |
40 |
} |
|
41 |
||
14072
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
42 |
// flip |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
43 |
if self.outline_template.can_flip { |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
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:
14047
diff
changeset
|
45 |
if b & 1 != 0 { |
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
46 |
points |
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
47 |
.iter_mut() |
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
48 |
.for_each(|p| p.y = land.height() as i32 - 1 - p.y); |
14072
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 |
} |
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 |
points.distort(random_numbers); |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
54 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
55 |
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
|
56 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
57 |
for p in &points.fill_points { |
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
58 |
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
|
59 |
} |
8a0d69c16cad
Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents:
14047
diff
changeset
|
60 |
|
14087
649ccb9f8cfd
Commit broken code for divide_edges in hope for salvation
unc0rr
parents:
14075
diff
changeset
|
61 |
points.draw(&mut land, parameters.basic); |
14047 | 62 |
|
63 |
land |
|
64 |
} |
|
65 |
} |