Browse Source

Added a little more worldgen

master
Thomas Johnson 3 years ago
parent
commit
3e9301ab34
  1. 26
      src/world/gen.rs
  2. 4
      src/world/mod.rs

26
src/world/gen.rs

@ -1,5 +1,7 @@
use rogue_util::coord::{R2i, V2i};
use rogue_util::grid::{Grid};
use super::{Tile, Content};
use rand::rngs::SmallRng;
use rand::SeedableRng;
use rand_distr::{Poisson, Distribution, weighted::WeightedIndex, Uniform};
@ -15,8 +17,18 @@ const ROOM_TYPE_WEIGHTS: [usize; 2] = [1, 1];
const RECT_MIN_SIZE: isize = 3;
const RECT_MAX_SIZE: isize = 10;
const CIRC_MIN_RAD: isize = 3;
const CIRC_MAX_RAD: isize = 10;
const CIRC_MIN_RAD: isize = 1;
const CIRC_MAX_RAD: isize = 5;
pub mod extra_utils
{
use rogue_util::coord::{R2i, V2i};
pub fn enlarge_rect(rect: R2i, upper: V2i, lower: V2i)
{
}
}
#[derive(Clone, Debug)]
enum RoomShape
@ -96,7 +108,7 @@ fn get_nearby_room_shapes(seed: u64, coords: V2i) -> impl Iterator<Item=RoomShap
.map(move |shape| shape.offset_grid(v))).flatten()
}
fn carve_rooms<T: Iterator<Item=RoomShape>>(map: &mut [bool; GRID_USIZE * GRID_USIZE], shapes: T)
fn carve_rooms<T: Iterator<Item=RoomShape>>(map: &mut [Tile], shapes: T)
{
let gbox = R2i::origin_dim(V2i(0, 0), V2i(GRID_SIZE, GRID_SIZE));
for shape in shapes
@ -111,13 +123,19 @@ fn carve_rooms<T: Iterator<Item=RoomShape>>(map: &mut [bool; GRID_USIZE * GRID_U
RoomShape::Rect(rect) => true,
RoomShape::Circ(c, r) => (tile - c).l2_sq() < r * r,
} {
map[(tile.0 * GRID_SIZE + tile.1) as usize] = true;
map[(tile.0 * GRID_SIZE + tile.1) as usize].content = Content::Stone;
}
}
}
}
}
pub fn carve(seed: u64, grid: &mut Grid<Tile>, coords: V2i)
{
let rsi = get_nearby_room_shapes(seed, coords);
carve_rooms(grid.array_mut(), rsi);
}
#[cfg(test)]
mod test
{

4
src/world/mod.rs

@ -30,15 +30,17 @@ impl Default for Tile {
#[derive(Debug)]
pub struct World {
seed: u64,
cur_region: usize,
regions: Vec<Region<Tile>>,
}
impl World {
pub fn new() -> World {
pub fn new(seed: u64) -> World {
let start_region = RegionConfig::default().build().expect("Failed to make World");
// TODO: Worldgen on start_region
World {
seed,
cur_region: 0,
regions: vec![start_region],
}

Loading…
Cancel
Save