summaryrefslogtreecommitdiff
path: root/dungeon/src/lib.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-18 10:24:03 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-18 10:24:03 -0500
commitff315c10418ced36de7996bd9a521f8b96c90631 (patch)
tree75a50d8c46cae6096e9b6693d62c3d21f82587ad /dungeon/src/lib.rs
parentdungeon: split rng into game/level to make maps consistant (diff)
downloadDungeonCrawl-ff315c10418ced36de7996bd9a521f8b96c90631.tar.gz
DungeonCrawl-ff315c10418ced36de7996bd9a521f8b96c90631.tar.bz2
DungeonCrawl-ff315c10418ced36de7996bd9a521f8b96c90631.zip
dungeon: port rands SmallRng to be reproducible
Diffstat (limited to 'dungeon/src/lib.rs')
-rw-r--r--dungeon/src/lib.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/dungeon/src/lib.rs b/dungeon/src/lib.rs
index 76a2bda..4e48b68 100644
--- a/dungeon/src/lib.rs
+++ b/dungeon/src/lib.rs
@@ -8,11 +8,9 @@ pub mod map;
pub mod msg;
pub mod player_input;
pub mod pos;
+pub mod rng;
-use rand::{
- Rng, SeedableRng, TryRngCore,
- rngs::{OsRng, SmallRng},
-};
+use rand::{Rng, SeedableRng, TryRngCore, rngs::OsRng};
use crate::{
entity::{Entity, Player},
@@ -20,6 +18,7 @@ use crate::{
msg::Message,
player_input::PlayerInput,
pos::FPos,
+ rng::DungeonRng,
};
/// Lets the caller know what has
@@ -45,8 +44,8 @@ pub struct Dungeon {
pub enemies: Vec<Entity>,
pub msg: Message,
seed: u64,
- level_rng: SmallRng,
- game_rng: SmallRng,
+ level_rng: DungeonRng,
+ game_rng: DungeonRng,
}
impl Dungeon {
/// Creates a new `Dungeon` with a provided seed.
@@ -61,8 +60,8 @@ impl Dungeon {
/// ```
#[must_use]
pub fn new(seed: u64) -> Self {
- let mut game_rng = SmallRng::seed_from_u64(seed);
- let mut level_rng = SmallRng::seed_from_u64(game_rng.random());
+ let mut game_rng = DungeonRng::seed_from_u64(seed);
+ let mut level_rng = DungeonRng::seed_from_u64(game_rng.random());
let floor = bsp::generate(&mut level_rng);
let player = Player::new(floor.player_start());
let enemies = vec![];
@@ -110,7 +109,7 @@ impl Dungeon {
/// Returns the runtime random number gen for the `Floor`
#[must_use]
- pub const fn rng(&mut self) -> &mut SmallRng {
+ pub const fn rng(&mut self) -> &mut DungeonRng {
&mut self.game_rng
}