equal
deleted
inserted
replaced
24 } |
24 } |
25 } |
25 } |
26 |
26 |
27 pub struct World { |
27 pub struct World { |
28 random_numbers_gen: LaggedFibonacciPRNG, |
28 random_numbers_gen: LaggedFibonacciPRNG, |
29 preview: Land2D<u8>, |
29 preview: Option<Land2D<u8>>, |
30 game_state: Option<GameState>, |
30 game_state: Option<GameState>, |
31 } |
31 } |
32 |
32 |
33 impl World { |
33 impl World { |
34 pub fn new() -> Self { |
34 pub fn new() -> Self { |
35 Self { |
35 Self { |
36 random_numbers_gen: LaggedFibonacciPRNG::new(&[]), |
36 random_numbers_gen: LaggedFibonacciPRNG::new(&[]), |
37 preview: Land2D::new(Size::new(0, 0), 0), |
37 preview: None, |
38 game_state: None, |
38 game_state: None, |
39 } |
39 } |
40 } |
40 } |
41 |
41 |
42 pub fn set_seed(&mut self, seed: &[u8]) { |
42 pub fn set_seed(&mut self, seed: &[u8]) { |
43 self.random_numbers_gen = LaggedFibonacciPRNG::new(seed); |
43 self.random_numbers_gen = LaggedFibonacciPRNG::new(seed); |
44 } |
44 } |
45 |
45 |
46 pub fn preview(&self) -> &Land2D<u8> { |
46 pub fn preview(&self) -> &Option<Land2D<u8>> { |
47 &self.preview |
47 &self.preview |
48 } |
48 } |
49 |
49 |
50 pub fn generate_preview(&mut self) { |
50 pub fn generate_preview(&mut self) { |
51 fn template() -> OutlineTemplate { |
51 fn template() -> OutlineTemplate { |
61 template |
61 template |
62 } |
62 } |
63 |
63 |
64 let params = LandGenerationParameters::new(0u8, u8::max_value(), 5, false, false); |
64 let params = LandGenerationParameters::new(0u8, u8::max_value(), 5, false, false); |
65 let landgen = TemplatedLandGenerator::new(template()); |
65 let landgen = TemplatedLandGenerator::new(template()); |
66 self.preview = landgen.generate_land(¶ms, &mut self.random_numbers_gen); |
66 self.preview = Some(landgen.generate_land(¶ms, &mut self.random_numbers_gen)); |
|
67 } |
|
68 |
|
69 pub fn dispose_preview(&mut self) { |
|
70 self.preview = None |
67 } |
71 } |
68 |
72 |
69 pub fn init(&mut self, template: OutlineTemplate) { |
73 pub fn init(&mut self, template: OutlineTemplate) { |
70 let physics = hwp::World::new(template.size); |
74 let physics = hwp::World::new(template.size); |
71 |
75 |