author | alfadur |
Mon, 29 Oct 2018 23:38:08 +0300 | |
changeset 14028 | 0f517cbfe16d |
child 14030 | 2ebd505e62c1 |
permissions | -rw-r--r-- |
14028
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
1 |
use sdl2::{ |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
2 |
keyboard::Scancode, |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
3 |
event::EventType |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
4 |
}; |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
5 |
|
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
6 |
use rand::{ |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
7 |
thread_rng, RngCore |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
8 |
}; |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
9 |
|
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
10 |
use landgen::{ |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
11 |
LandGenerator, |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
12 |
LandGenerationParameters |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
13 |
}; |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
14 |
use land2d::Land2D; |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
15 |
use lfprng::LaggedFibonacciPRNG; |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
16 |
|
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
17 |
struct LandSource<T> { |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
18 |
rnd: LaggedFibonacciPRNG, |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
19 |
generator: T |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
20 |
} |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
21 |
|
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
22 |
impl <T: LandGenerator> LandSource<T> { |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
23 |
fn new(generator: T) -> Self { |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
24 |
let mut init = [0u8; 64]; |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
25 |
thread_rng().fill_bytes(&mut init); |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
26 |
LandSource { |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
27 |
rnd: LaggedFibonacciPRNG::new(&init), |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
28 |
generator |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
29 |
} |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
30 |
} |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
31 |
fn next(&mut self, parameters: LandGenerationParameters<u32>) -> Land2D<u32> { |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
32 |
self.generator.generate_land(parameters, &mut self.rnd) |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
33 |
} |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
34 |
} |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
35 |
|
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
36 |
fn main() { |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
37 |
let sdl = sdl2::init().unwrap(); |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
38 |
let _image = sdl2::image::init(sdl2::image::INIT_PNG).unwrap(); |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
39 |
let events = sdl.event().unwrap(); |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
40 |
|
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
41 |
let mut pump = sdl.event_pump().unwrap(); |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
42 |
let video = sdl.video().unwrap(); |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
43 |
let _window = video.window("Theme Editor", 640, 480) |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
44 |
.position_centered() |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
45 |
.build().unwrap(); |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
46 |
|
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
47 |
'pool: loop { |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
48 |
use sdl2::event::Event::*; |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
49 |
pump.pump_events(); |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
50 |
|
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
51 |
while let Some(event) = pump.poll_event() { |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
52 |
match event { |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
53 |
Quit{ .. } => break 'pool, |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
54 |
_ => () |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
55 |
} |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
56 |
} |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
57 |
} |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
58 |
} |
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
59 |
|
0f517cbfe16d
start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff
changeset
|
60 |