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.rs33
1 files changed, 5 insertions, 28 deletions
diff --git a/dungeon/src/map.rs b/dungeon/src/map.rs
index b1c5f16..ed92882 100644
--- a/dungeon/src/map.rs
+++ b/dungeon/src/map.rs
@@ -76,10 +76,6 @@ pub struct Floor {
tiles: Box<[Tile; TILE_COUNT]>,
/// The position the player starts at
player_start: Pos,
- /// The seed used when generating the dungeon grid
- seed: u64,
- /// Seeded rng by `seed`
- rng: SmallRng,
/// The computed hash of the tile map
hash: RefCell<u64>,
/// If the tiles are dirty (hash needs to be recomputed)
@@ -87,17 +83,10 @@ pub struct Floor {
}
impl Floor {
/// Construct a floor from its components
- pub fn from_parts(
- tiles: Box<[Tile; TILE_COUNT]>,
- player_start: Pos,
- seed: u64,
- rng: SmallRng,
- ) -> Self {
+ pub fn new(tiles: Box<[Tile; TILE_COUNT]>, player_start: Pos) -> Self {
Self {
tiles,
player_start,
- seed,
- rng,
hash: RefCell::new(0),
dirty: RefCell::new(true),
}
@@ -109,12 +98,6 @@ impl Floor {
self.player_start
}
- /// Returns the seed used to generate the map
- #[must_use]
- pub const fn seed(&self) -> u64 {
- self.seed
- }
-
/// Returns a `Tile` on the dungeon grid at `Pos`.
#[must_use]
pub const fn get(&self, pos: Pos) -> Tile {
@@ -174,21 +157,15 @@ impl Floor {
/// Returns a random open (no wall) position
#[must_use]
- pub fn random_walkable_pos(&mut self) -> Pos {
+ pub fn random_walkable_pos(&self, rng: &mut SmallRng) -> Pos {
loop {
- let pos = self.rng().random();
+ let pos = rng.random();
if !self.get(pos).is_walkable() {
continue;
}
break pos;
}
}
-
- /// Returns the random number gen for the `Floor`
- #[must_use]
- pub fn rng(&mut self) -> &mut SmallRng {
- &mut self.rng
- }
}
impl Display for Floor {
/// Display the floor as a string for debugging
@@ -196,7 +173,7 @@ impl Display for Floor {
/// # Examples
/// ```no_run
/// use dungeon::Dungeon;
- /// let dungeon = Dungeon::default();
+ /// let dungeon = Dungeon::random();
/// let floor = &dungeon.floor;
/// println!("{floor}");
/// ```
@@ -228,7 +205,7 @@ mod tests {
// Test floor printing
#[test]
fn test_floor_display() {
- let dungeon = Dungeon::default();
+ let dungeon = Dungeon::random();
let floor = &dungeon.floor;
// Print the display for visual inspection
println!("{floor}");