summaryrefslogtreecommitdiff
path: root/dungeon/src/map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dungeon/src/map.rs')
-rw-r--r--dungeon/src/map.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/dungeon/src/map.rs b/dungeon/src/map.rs
index a568950..7a6cc45 100644
--- a/dungeon/src/map.rs
+++ b/dungeon/src/map.rs
@@ -79,24 +79,28 @@ pub struct Floor {
player_start: Pos,
/// The seed used when generating the dungeon grid
seed: u64,
+ /// Seeded rng by `seed`
+ rng: StdRng,
/// The computed hash of the tile map
hash: RefCell<u64>,
/// If the tiles are dirty (hash needs to be recomputed)
dirty: RefCell<bool>,
- /// Custom rng
- rng: StdRng,
}
impl Floor {
- /// Internal constructor for `Floor`
- fn new(tiles: Box<[Tile; TILE_COUNT]>, player_start: Pos, seed: u64) -> Self {
- let rng = rand::rngs::StdRng::seed_from_u64(seed);
+ /// Construct a floor from its components
+ pub fn from_parts(
+ tiles: Box<[Tile; TILE_COUNT]>,
+ player_start: Pos,
+ seed: u64,
+ rng: StdRng,
+ ) -> Self {
Self {
tiles,
player_start,
seed,
+ rng,
hash: RefCell::new(0),
dirty: RefCell::new(true),
- rng,
}
}
@@ -134,9 +138,7 @@ impl Floor {
/// ```
#[must_use]
pub fn generate_seeded(seed: u64) -> Self {
- let (tiles, player_start) = bsp::generate(seed);
-
- Self::new(tiles, player_start, seed)
+ bsp::generate(seed)
}
/// Returns the start position of the player
@@ -210,7 +212,7 @@ impl Floor {
/// Returns a random open (no wall) position
#[must_use]
- pub fn random_pos(&mut self) -> Pos {
+ pub fn random_walkable_pos(&mut self) -> Pos {
loop {
let pos = self.rand().random();
if !self.get(pos).is_walkable() {
@@ -239,7 +241,9 @@ impl Default for Floor {
}
}
- Self::new(tiles, player_start, seed)
+ let rng = rand::rngs::StdRng::seed_from_u64(seed);
+
+ Self::from_parts(tiles, player_start, seed, rng)
}
}
impl Display for Floor {