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