Dolda2000 GitWeb
/
kaka
/
rust-sdl-test.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Only collide with walls from the front
[kaka/rust-sdl-test.git]
/
src
/
core
/
level
/
lvlgen.rs
diff --git
a/src/core/level/lvlgen.rs
b/src/core/level/lvlgen.rs
index
c2a02b5
..
af6ab76
100644
(file)
--- a/
src/core/level/lvlgen.rs
+++ b/
src/core/level/lvlgen.rs
@@
-1,9
+1,8
@@
-use common::{Point, Dimension};
-use std::rc::Rc;
+use geometry::{Point, Dimension};
use noise::{NoiseFn, OpenSimplex, Seedable};
use rand::Rng;
use super::{Grid, Level, WallRegion};
use noise::{NoiseFn, OpenSimplex, Seedable};
use rand::Rng;
use super::{Grid, Level, WallRegion};
-use {point, time_scope};
+use {point,
dimen,
time_scope};
////////// LEVEL GENERATOR /////////////////////////////////////////////////////
////////// LEVEL GENERATOR /////////////////////////////////////////////////////
@@
-27,13
+26,13
@@
impl LevelGenerator {
dbg!(self);
time_scope!("level generation");
dbg!(self);
time_scope!("level generation");
- let
cell_size = 2
0;
- 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 u
size);
let mut grid = Grid {
let mut grid = Grid {
-
cell_size: (cell_size, cell_siz
e).into(),
-
size: (width, height).into(
),
-
cells: vec!(vec!(true; height); width)
,
+
scale: (scale, scal
e).into(),
+
cells: vec!(vec!(true; size.height); size.width
),
+
size
,
};
// start with some noise
};
// start with some noise
@@
-119,7
+118,7
@@
impl LevelGenerator {
println!(" {} iterations needed", count);
}
println!(" {} iterations needed", count);
}
- fn neighbours(&self, grid: &
Vec<Vec<bool>>
, px: usize, py: usize, distance: usize) -> u8 {
+ fn neighbours(&self, grid: &
[Vec<bool>]
, px: usize, py: usize, distance: usize) -> u8 {
let mut count = 0;
for x in (px - distance)..=(px + distance) {
for y in (py - distance)..=(py + distance) {
let mut count = 0;
for x in (px - distance)..=(px + distance) {
for y in (py - distance)..=(py + distance) {
@@
-148,7
+147,7
@@
impl LevelGenerator {
}
}
Grid {
}
}
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
}
size: (width, height).into(),
cells
}
@@
-221,11
+220,11
@@
impl LevelGenerator {
}
}
}
}
- fn find_walls(&self, grid: &Grid<bool>) -> Vec<
Rc<WallRegion>
> {
+ fn find_walls(&self, grid: &Grid<bool>) -> Vec<
WallRegion
> {
let mut walls = vec!();
for r in self.find_regions(&grid) {
if r.value {
let mut walls = vec!();
for r in self.find_regions(&grid) {
if r.value {
- let outline = r.outline(&grid.
cell_siz
e);
+ let outline = r.outline(&grid.
scal
e);
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);
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);
@@
-267,7
+266,7
@@
impl Region {
(min.0, min.1, 1 + max.0 - min.0, 1 + max.1 - min.1)
}
(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);
let rect = self.enclosing_rect();
let (ox, oy, w, h) = rect;
let grid = self.grid(&rect);
@@
-293,7
+292,7
@@
impl Region {
}
#[allow(dead_code)]
}
#[allow(dead_code)]
- fn print_grid(&self, grid: &
Vec<Vec<bool>>
) {
+ fn print_grid(&self, grid: &
[Vec<bool>]
) {
let w = grid.len();
let h = grid[0].len();
let mut g = vec!(vec!(false; w); h);
let w = grid.len();
let h = grid[0].len();
let mut g = vec!(vec!(false; w); h);
@@
-326,7
+325,7
@@
impl Region {
grid
}
grid
}
- fn find_first_point_of_outline(&self, rect: &(usize, usize, usize, usize), grid: &
Vec<Vec<bool>>
) -> Point<isize> {
+ fn find_first_point_of_outline(&self, rect: &(usize, usize, usize, usize), grid: &
[Vec<bool>]
) -> Point<isize> {
let (ox, oy, w, h) = rect;
let is_outer_wall = (ox, oy) == (&0, &0); // we know this is always the outer wall of the level
for x in 0..*w {
let (ox, oy, w, h) = rect;
let is_outer_wall = (ox, oy) == (&0, &0); // we know this is always the outer wall of the level
for x in 0..*w {
@@
-342,7
+341,7
@@
impl Region {
panic!("no wall found!");
}
panic!("no wall found!");
}
- fn find_next_point_of_outline(&self, grid: &
Vec<Vec<bool>>
, p: &mut Point<isize>, directions: &mut Vec<(isize, isize)>) {
+ fn find_next_point_of_outline(&self, grid: &
[Vec<bool>]
, p: &mut Point<isize>, directions: &mut Vec<(isize, isize)>) {
directions.rotate_left(2);
loop {
let d = directions[0];
directions.rotate_left(2);
loop {
let d = directions[0];
@@
-354,7
+353,7
@@
impl Region {
}
}
}
}
- fn check(&self, p: Point<isize>, grid: &
Vec<Vec<bool>>
) -> bool {
+ fn check(&self, p: Point<isize>, grid: &
[Vec<bool>]
) -> bool {
if p.x < 0 || p.x >= grid.len() as isize || p.y < 0 || p.y >= grid[0].len() as isize {
false
} else {
if p.x < 0 || p.x >= grid.len() as isize || p.y < 0 || p.y >= grid[0].len() as isize {
false
} else {