summaryrefslogtreecommitdiff
path: root/dungeon/src/bsp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dungeon/src/bsp.rs')
-rw-r--r--dungeon/src/bsp.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/dungeon/src/bsp.rs b/dungeon/src/bsp.rs
index 48a00e1..e0ac001 100644
--- a/dungeon/src/bsp.rs
+++ b/dungeon/src/bsp.rs
@@ -6,6 +6,7 @@ use rand::prelude::IndexedRandom;
use rand::{Rng, SeedableRng};
use std::cmp; // for min/max
+use crate::Floor;
use crate::map::{MAP_SIZE, TILE_COUNT, Tile};
use crate::{const_pos, pos::Pos};
@@ -286,8 +287,8 @@ fn carve_v_corridor(tiles: &mut [Tile; TILE_COUNT], y1: u16, y2: u16, x: u16) {
}
/// Top-level generator function for the dungeon using BSP.
-/// Returns (tiles, player_start).
-pub fn generate(seed: u64) -> (Box<[Tile; TILE_COUNT]>, Pos) {
+/// Returns a `Floor`
+pub fn generate(seed: u64) -> Floor {
let mut rng = rand::rngs::StdRng::seed_from_u64(seed);
// Initialize all tiles to walls
@@ -395,8 +396,8 @@ pub fn generate(seed: u64) -> (Box<[Tile; TILE_COUNT]>, Pos) {
let exit_idx = exit_pos.xy().0 + exit_pos.xy().1 * MAP_SIZE;
tiles_box[exit_idx as usize] = Tile::Stairs;
- // Return tiles and player_start
- (tiles_box, player_start)
+ // Return components turned into a `Floor`
+ Floor::from_parts(tiles_box, player_start, seed, rng)
}
/// BSP Unit Tests
@@ -467,12 +468,12 @@ mod tests {
#[test]
fn test_generate() {
let seed = 12345u64;
- let (tiles, player_start) = generate(seed);
+ let floor = generate(seed);
// Check that tiles contain some Room tiles
- let room_count = tiles.iter().filter(|&&t| t == Tile::Room).count();
+ let room_count = floor.tiles().iter().filter(|&&t| t == Tile::Room).count();
assert!(room_count > 0);
// Check that player_start is within bounds
- assert!(player_start.xy().0 < MAP_SIZE);
- assert!(player_start.xy().1 < MAP_SIZE);
+ assert!(floor.player_start().xy().0 < MAP_SIZE);
+ assert!(floor.player_start().xy().1 < MAP_SIZE);
}
}