author | alfadur <mail@none> |
Wed, 06 Feb 2019 00:14:04 +0300 | |
changeset 14686 | 9f98086de1b6 |
parent 14373 | 4409344db447 |
child 14702 | 29dbe9ce8b7d |
permissions | -rw-r--r-- |
14295 | 1 |
use fpnum::{FPNum, fp}; |
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
2 |
use integral_geometry::{Point, Rect, Size}; |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
3 |
use land2d::Land2D; |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
4 |
use landgen::{ |
14295 | 5 |
outline_template::OutlineTemplate, |
6 |
template_based::TemplatedLandGenerator, |
|
7 |
LandGenerationParameters, |
|
8 |
LandGenerator, |
|
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
9 |
}; |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
10 |
use lfprng::LaggedFibonacciPRNG; |
14295 | 11 |
use hwphysics as hwp; |
12 |
||
13 |
struct GameState { |
|
14 |
land: Land2D<u32>, |
|
15 |
physics: hwp::World, |
|
16 |
} |
|
17 |
||
18 |
impl GameState { |
|
19 |
fn new(land: Land2D<u32>, physics: hwp::World) -> Self { |
|
20 |
Self { |
|
21 |
land, |
|
22 |
physics, |
|
23 |
} |
|
24 |
} |
|
25 |
} |
|
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
26 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
27 |
pub struct World { |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
28 |
random_numbers_gen: LaggedFibonacciPRNG, |
14373
4409344db447
Rework EngineInstance::generatePreview, add preview cleanup function in enginelib
unC0Rr
parents:
14295
diff
changeset
|
29 |
preview: Option<Land2D<u8>>, |
14295 | 30 |
game_state: Option<GameState>, |
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
31 |
} |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
32 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
33 |
impl World { |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
34 |
pub fn new() -> Self { |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
35 |
Self { |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
36 |
random_numbers_gen: LaggedFibonacciPRNG::new(&[]), |
14373
4409344db447
Rework EngineInstance::generatePreview, add preview cleanup function in enginelib
unC0Rr
parents:
14295
diff
changeset
|
37 |
preview: None, |
14295 | 38 |
game_state: None, |
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
39 |
} |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
40 |
} |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
41 |
|
14272 | 42 |
pub fn set_seed(&mut self, seed: &[u8]) { |
43 |
self.random_numbers_gen = LaggedFibonacciPRNG::new(seed); |
|
44 |
} |
|
45 |
||
14373
4409344db447
Rework EngineInstance::generatePreview, add preview cleanup function in enginelib
unC0Rr
parents:
14295
diff
changeset
|
46 |
pub fn preview(&self) -> &Option<Land2D<u8>> { |
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
47 |
&self.preview |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
48 |
} |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
49 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
50 |
pub fn generate_preview(&mut self) { |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
51 |
fn template() -> OutlineTemplate { |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
52 |
let mut template = OutlineTemplate::new(Size::new(4096, 2048)); |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
53 |
template.islands = vec![vec![ |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
54 |
Rect::from_size_coords(100, 2050, 1, 1), |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
55 |
Rect::from_size_coords(100, 500, 400, 1200), |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
56 |
Rect::from_size_coords(3600, 500, 400, 1200), |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
57 |
Rect::from_size_coords(3900, 2050, 1, 1), |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
58 |
]]; |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
59 |
template.fill_points = vec![Point::new(1, 0)]; |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
60 |
|
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
61 |
template |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
62 |
} |
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
63 |
|
14295 | 64 |
let params = LandGenerationParameters::new(0u8, u8::max_value(), 5, false, false); |
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
65 |
let landgen = TemplatedLandGenerator::new(template()); |
14373
4409344db447
Rework EngineInstance::generatePreview, add preview cleanup function in enginelib
unC0Rr
parents:
14295
diff
changeset
|
66 |
self.preview = Some(landgen.generate_land(¶ms, &mut self.random_numbers_gen)); |
4409344db447
Rework EngineInstance::generatePreview, add preview cleanup function in enginelib
unC0Rr
parents:
14295
diff
changeset
|
67 |
} |
4409344db447
Rework EngineInstance::generatePreview, add preview cleanup function in enginelib
unC0Rr
parents:
14295
diff
changeset
|
68 |
|
4409344db447
Rework EngineInstance::generatePreview, add preview cleanup function in enginelib
unC0Rr
parents:
14295
diff
changeset
|
69 |
pub fn dispose_preview(&mut self) { |
4409344db447
Rework EngineInstance::generatePreview, add preview cleanup function in enginelib
unC0Rr
parents:
14295
diff
changeset
|
70 |
self.preview = None |
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
71 |
} |
14295 | 72 |
|
73 |
pub fn init(&mut self, template: OutlineTemplate) { |
|
74 |
let physics = hwp::World::new(template.size); |
|
75 |
||
76 |
let params = LandGenerationParameters::new(0u32, u32::max_value(), 5, false, false); |
|
77 |
let landgen = TemplatedLandGenerator::new(template); |
|
78 |
let land = landgen.generate_land(¶ms, &mut self.random_numbers_gen); |
|
79 |
||
80 |
self.game_state = Some(GameState::new(land, physics)); |
|
81 |
} |
|
82 |
||
83 |
pub fn step(&mut self) { |
|
84 |
if let Some(ref mut state) = self.game_state { |
|
85 |
state.physics.step(fp!(1), &state.land); |
|
86 |
} |
|
87 |
} |
|
14154
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
diff
changeset
|
88 |
} |