# HG changeset patch # User alfadur # Date 1540845488 -10800 # Node ID 0f517cbfe16d85ffca942ac08e3b4ad9dd30200c # Parent cef0c685fda87d3b2670d633601fb2393d0e4e4d start a theme editor as an excuse to see land generator in action diff -r cef0c685fda8 -r 0f517cbfe16d rust/theme-editor/Cargo.toml --- /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 diff -r cef0c685fda8 -r 0f517cbfe16d rust/theme-editor/src/main.rs --- /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 { + rnd: LaggedFibonacciPRNG, + generator: T +} + +impl LandSource { + 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) -> Land2D { + 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, + _ => () + } + } + } +} + +