summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-13 10:11:41 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-13 10:11:41 -0500
commit59aea66fa02018110a55a75a64885669bcea07db (patch)
treee77e706d550a9eda149327f32677db67fd3b8a4a
parentdungeon: have Dungeon store the rng, not the Floor (diff)
downloadDungeonCrawl-59aea66fa02018110a55a75a64885669bcea07db.tar.gz
DungeonCrawl-59aea66fa02018110a55a75a64885669bcea07db.tar.bz2
DungeonCrawl-59aea66fa02018110a55a75a64885669bcea07db.zip
bsp: why was this unsafe?
-rw-r--r--dungeon/src/bsp.rs9
1 files changed, 3 insertions, 6 deletions
diff --git a/dungeon/src/bsp.rs b/dungeon/src/bsp.rs
index 905b29b..db9ff99 100644
--- a/dungeon/src/bsp.rs
+++ b/dungeon/src/bsp.rs
@@ -312,7 +312,7 @@ pub fn generate(rng: &mut SmallRng) -> Floor {
let mut stack = vec![&mut root];
while let Some(node) = stack.pop() {
if node.left.is_none() && node.right.is_none() {
- leaves.push(node as *mut Node);
+ leaves.push(node);
} else {
if let Some(left) = &mut node.left {
stack.push(left);
@@ -327,12 +327,9 @@ pub fn generate(rng: &mut SmallRng) -> Floor {
let mut splitted_any = false;
// Try splitting each leaf in order
- for &node_ptr in leaves.iter() {
- // Pointers obtained from boxed root remain valid while root lives
- // TODO: Store nodes in smart pointers to avoid unsafe?
- let node = unsafe { &mut *node_ptr };
+ for node_ptr in leaves.iter_mut() {
// Attempt to split if possible
- if node.split(rng) {
+ if node_ptr.split(rng) {
splitted_any = true;
}
}