summaryrefslogtreecommitdiff
path: root/dungeon/src/map.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-11 20:46:17 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-11 20:54:28 -0500
commit0bedd7991a7f2e3e35ae6b23d4f041c5a48454b9 (patch)
tree73175729fc202e0cda237871d88c3822c23bed8c /dungeon/src/map.rs
parentdungeon: rewrite const_pos! (diff)
downloadDungeonCrawl-0bedd7991a7f2e3e35ae6b23d4f041c5a48454b9.tar.gz
DungeonCrawl-0bedd7991a7f2e3e35ae6b23d4f041c5a48454b9.tar.bz2
DungeonCrawl-0bedd7991a7f2e3e35ae6b23d4f041c5a48454b9.zip
dungeon: bsp generate should return a floor to use same single rng
- `Floor::new` is now `Floor::from_parts` and takes in and rng - updated bps tests to operate on a floor - removed pos < MAP_SIZE checks, since `Pos` gurentees this - bsp::generate now returns a floor
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 {