Renamed Grid.cell_size -> scale
[kaka/rust-sdl-test.git] / src / core / level / lvlgen.rs
index 109337a..daf27e8 100644 (file)
@@ -2,7 +2,7 @@ use common::{Point, Dimension};
 use noise::{NoiseFn, OpenSimplex, Seedable};
 use rand::Rng;
 use super::{Grid, Level, WallRegion};
-use {point, time_scope};
+use {point, dimen, time_scope};
 
 ////////// LEVEL GENERATOR /////////////////////////////////////////////////////
 
@@ -26,13 +26,13 @@ impl LevelGenerator {
        dbg!(self);
        time_scope!("level generation");
 
-       let cell_size = 20;
-       let (width, height) = (2560 / cell_size, 1440 / cell_size);
+       let scale = 20.0;
+       let size = dimen!((2560.0 / scale) as usize, (1440.0 / scale) as usize);
 
        let mut grid = Grid {
-           cell_size: (cell_size, cell_size).into(),
-           size: (width, height).into(),
-           cells: vec!(vec!(true; height); width),
+           scale: (scale, scale).into(),
+           cells: vec!(vec!(true; size.height); size.width),
+           size,
        };
 
        // start with some noise
@@ -147,7 +147,7 @@ impl LevelGenerator {
            }
        }
        Grid {
-           cell_size: (grid.cell_size.width / 2, grid.cell_size.height / 2).into(),
+           scale: (grid.scale.width / 2.0, grid.scale.height / 2.0).into(),
            size: (width, height).into(),
            cells
        }
@@ -224,7 +224,7 @@ impl LevelGenerator {
        let mut walls = vec!();
        for r in self.find_regions(&grid) {
            if r.value {
-               let outline = r.outline(&grid.cell_size);
+               let outline = r.outline(&grid.scale);
                let mut floats = outline.iter().map(|p| point!(p.x as f64, p.y as f64)).collect();
                self.smooth_wall(&mut floats, self.wall_smooth_radius as isize);
                let wall = WallRegion::new(floats);
@@ -266,7 +266,7 @@ impl Region {
        (min.0, min.1, 1 + max.0 - min.0, 1 + max.1 - min.1)
     }
 
-    pub fn outline(&self, scale: &Dimension<usize>) -> Vec<Point<isize>> {
+    pub fn outline(&self, scale: &Dimension<f64>) -> Vec<Point<isize>> {
        let rect = self.enclosing_rect();
        let (ox, oy, w, h) = rect;
        let grid = self.grid(&rect);