rust/theme-editor/src/main.rs
author alfadur
Mon, 29 Oct 2018 23:38:08 +0300
changeset 14033 0f517cbfe16d
child 14035 2ebd505e62c1
permissions -rw-r--r--
start a theme editor as an excuse to see land generator in action

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,
                _ => ()
            }
        }    
    }
}