start a theme editor as an excuse to see land generator in action
authoralfadur
Mon, 29 Oct 2018 23:38:08 +0300
changeset 14049 0f517cbfe16d
parent 14048 cef0c685fda8
child 14050 259175ab7e8c
start a theme editor as an excuse to see land generator in action
rust/theme-editor/Cargo.toml
rust/theme-editor/src/main.rs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rust/theme-editor/Cargo.toml	Mon Oct 29 23:38:08 2018 +0300
@@ -0,0 +1,16 @@
+[package]
+name = "theme-editor"
+version = "0.1.0"
+authors = ["Hedgewars Project"]
+edition = "2018"
+
+[dependencies.sdl2]
+version = "0.31"
+default-features = true
+features = ["image"]
+
+[dependencies]
+land2d = { path = "../land2d" }
+landgen = { path = "../landgen" }
+lfprng = { path = "../lfprng" }
+rand = "0.5"
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rust/theme-editor/src/main.rs	Mon Oct 29 23:38:08 2018 +0300
@@ -0,0 +1,60 @@
+use sdl2::{
+    keyboard::Scancode,
+    event::EventType
+};
+
+use rand::{
+    thread_rng, RngCore
+};
+
+use landgen::{
+    LandGenerator,
+    LandGenerationParameters
+};
+use land2d::Land2D;
+use lfprng::LaggedFibonacciPRNG;
+
+struct LandSource<T> {
+    rnd: LaggedFibonacciPRNG,
+    generator: T
+}
+
+impl <T: LandGenerator> LandSource<T> {
+    fn new(generator: T) -> Self {
+        let mut init = [0u8; 64];
+        thread_rng().fill_bytes(&mut init);
+        LandSource {
+            rnd: LaggedFibonacciPRNG::new(&init),
+            generator
+        }
+    }
+    fn next(&mut self, parameters: LandGenerationParameters<u32>) -> Land2D<u32> {
+        self.generator.generate_land(parameters, &mut self.rnd)
+    }
+}
+
+fn main() {
+    let sdl = sdl2::init().unwrap();
+    let _image = sdl2::image::init(sdl2::image::INIT_PNG).unwrap();
+    let events = sdl.event().unwrap();
+
+    let mut pump = sdl.event_pump().unwrap();
+    let video = sdl.video().unwrap();
+    let _window = video.window("Theme Editor", 640, 480)
+        .position_centered()
+        .build().unwrap();
+
+    'pool: loop {
+        use sdl2::event::Event::*;
+        pump.pump_events();
+
+        while let Some(event) = pump.poll_event() {
+            match event {
+                Quit{ .. } => break 'pool,
+                _ => ()
+            }
+        }    
+    }
+}
+
+