diff --git a/src/map_builders/bsp_dungeon.rs b/src/map_builders/bsp_dungeon.rs index 362657f..edf8727 100644 --- a/src/map_builders/bsp_dungeon.rs +++ b/src/map_builders/bsp_dungeon.rs @@ -15,16 +15,6 @@ pub struct BspDungeonBuilder { } impl MapBuilder for BspDungeonBuilder { - fn build_map(&mut self) { - self.build(); - } - - fn spawn_entities(&mut self, ecs: &mut World) { - for room in self.rooms.iter().skip(1) { - spawner::spawn_room(ecs, room, self.depth); - } - } - fn get_map(&self) -> Map { self.map.clone() } @@ -37,6 +27,16 @@ impl MapBuilder for BspDungeonBuilder { self.history.clone() } + fn build_map(&mut self) { + self.build(); + } + + fn spawn_entities(&mut self, ecs: &mut World) { + for room in self.rooms.iter().skip(1) { + spawner::spawn_room(ecs, room, self.depth); + } + } + fn take_snapshot(&mut self) { if SHOW_MAPGEN_VISUALIZER { let mut snapshot = self.map.clone(); diff --git a/src/map_builders/cellular_automata.rs b/src/map_builders/cellular_automata.rs index 76837e2..faadf1d 100644 --- a/src/map_builders/cellular_automata.rs +++ b/src/map_builders/cellular_automata.rs @@ -16,16 +16,6 @@ pub struct CellularAutomataBuilder { } impl MapBuilder for CellularAutomataBuilder { - fn build_map(&mut self) { - self.build(); - } - - fn spawn_entities(&mut self, ecs: &mut World) { - for area in self.noise_areas.iter() { - spawner::spawn_region(ecs, area.1, self.depth); - } - } - fn get_map(&self) -> Map { self.map.clone() } @@ -38,6 +28,16 @@ impl MapBuilder for CellularAutomataBuilder { self.history.clone() } + fn build_map(&mut self) { + self.build(); + } + + fn spawn_entities(&mut self, ecs: &mut World) { + for area in self.noise_areas.iter() { + spawner::spawn_region(ecs, area.1, self.depth); + } + } + fn take_snapshot(&mut self) { if SHOW_MAPGEN_VISUALIZER { let mut snapshot = self.map.clone(); diff --git a/src/map_builders/dla.rs b/src/map_builders/dla.rs index c68a12e..53af715 100644 --- a/src/map_builders/dla.rs +++ b/src/map_builders/dla.rs @@ -28,16 +28,6 @@ pub struct DLABuilder { } impl MapBuilder for DLABuilder { - fn build_map(&mut self) { - self.build(); - } - - fn spawn_entities(&mut self, ecs: &mut World) { - for area in self.noise_areas.iter() { - spawner::spawn_region(ecs, area.1, self.depth); - } - } - fn get_map(&self) -> Map { self.map.clone() } @@ -50,6 +40,16 @@ impl MapBuilder for DLABuilder { self.history.clone() } + fn build_map(&mut self) { + self.build(); + } + + fn spawn_entities(&mut self, ecs: &mut World) { + for area in self.noise_areas.iter() { + spawner::spawn_region(ecs, area.1, self.depth); + } + } + fn take_snapshot(&mut self) { if SHOW_MAPGEN_VISUALIZER { let mut snapshot = self.map.clone(); diff --git a/src/map_builders/drunkard.rs b/src/map_builders/drunkard.rs index 0239adb..aef7bc2 100644 --- a/src/map_builders/drunkard.rs +++ b/src/map_builders/drunkard.rs @@ -32,16 +32,6 @@ pub struct DrunkardsWalkBuilder { } impl MapBuilder for DrunkardsWalkBuilder { - fn build_map(&mut self) { - self.build(); - } - - fn spawn_entities(&mut self, ecs: &mut World) { - for area in self.noise_areas.iter() { - spawner::spawn_region(ecs, area.1, self.depth); - } - } - fn get_map(&self) -> Map { self.map.clone() } @@ -54,6 +44,16 @@ impl MapBuilder for DrunkardsWalkBuilder { self.history.clone() } + fn build_map(&mut self) { + self.build(); + } + + fn spawn_entities(&mut self, ecs: &mut World) { + for area in self.noise_areas.iter() { + spawner::spawn_region(ecs, area.1, self.depth); + } + } + fn take_snapshot(&mut self) { if SHOW_MAPGEN_VISUALIZER { let mut snapshot = self.map.clone(); diff --git a/src/map_builders/maze.rs b/src/map_builders/maze.rs index 7001596..f1fc4b0 100644 --- a/src/map_builders/maze.rs +++ b/src/map_builders/maze.rs @@ -15,16 +15,6 @@ pub struct MazeBuilder { } impl MapBuilder for MazeBuilder { - fn build_map(&mut self) { - self.build(); - } - - fn spawn_entities(&mut self, ecs: &mut World) { - for area in self.noise_areas.iter() { - spawner::spawn_region(ecs, area.1, self.depth); - } - } - fn get_map(&self) -> Map { self.map.clone() } @@ -37,6 +27,16 @@ impl MapBuilder for MazeBuilder { self.history.clone() } + fn build_map(&mut self) { + self.build(); + } + + fn spawn_entities(&mut self, ecs: &mut World) { + for area in self.noise_areas.iter() { + spawner::spawn_region(ecs, area.1, self.depth); + } + } + fn take_snapshot(&mut self) { if SHOW_MAPGEN_VISUALIZER { let mut snapshot = self.map.clone(); diff --git a/src/map_builders/mod.rs b/src/map_builders/mod.rs index 54e92b3..44b9585 100644 --- a/src/map_builders/mod.rs +++ b/src/map_builders/mod.rs @@ -23,17 +23,17 @@ use voronoi::VoronoiCellBuilder; use waveform_collapse::WaveformCollapseBuilder; pub trait MapBuilder { - fn build_map(&mut self); - fn spawn_entities(&mut self, ecs: &mut World); fn get_map(&self) -> Map; fn get_starting_position(&self) -> Position; fn get_snapshot_history(&self) -> Vec; + fn build_map(&mut self); + fn spawn_entities(&mut self, ecs: &mut World); fn take_snapshot(&mut self); } pub fn random_builder(new_depth: i32) -> Box { let mut rng = rltk::RandomNumberGenerator::new(); - let mut result: Box = match rng.roll_dice(1, 17) { + let mut result: Box = match rng.roll_dice(1, 16) { 1 => Box::new(BspDungeonBuilder::new(new_depth)), 2 => Box::new(BspInteriorBuilder::new(new_depth)), 3 => Box::new(CellularAutomataBuilder::new(new_depth)), @@ -49,7 +49,6 @@ pub fn random_builder(new_depth: i32) -> Box { 13 => Box::new(DLABuilder::insectoid(new_depth)), 14 => Box::new(VoronoiCellBuilder::pythagoras(new_depth)), 15 => Box::new(VoronoiCellBuilder::manhattan(new_depth)), - 16 => Box::new(WaveformCollapseBuilder::test_map(new_depth)), _ => Box::new(SimpleMapBuilder::new(new_depth)), }; diff --git a/src/map_builders/simple_map.rs b/src/map_builders/simple_map.rs index 374ac07..1cc034c 100644 --- a/src/map_builders/simple_map.rs +++ b/src/map_builders/simple_map.rs @@ -13,16 +13,6 @@ pub struct SimpleMapBuilder { } impl MapBuilder for SimpleMapBuilder { - fn build_map(&mut self) { - self.rooms_and_corridors(); - } - - fn spawn_entities(&mut self, ecs: &mut World) { - for room in self.rooms.iter().skip(1) { - spawner::spawn_room(ecs, room, self.depth); - } - } - fn get_map(&self) -> Map { self.map.clone() } @@ -35,6 +25,16 @@ impl MapBuilder for SimpleMapBuilder { self.history.clone() } + fn build_map(&mut self) { + self.rooms_and_corridors(); + } + + fn spawn_entities(&mut self, ecs: &mut World) { + for room in self.rooms.iter().skip(1) { + spawner::spawn_room(ecs, room, self.depth); + } + } + fn take_snapshot(&mut self) { if SHOW_MAPGEN_VISUALIZER { let mut snapshot = self.map.clone(); diff --git a/src/map_builders/voronoi.rs b/src/map_builders/voronoi.rs index ca4a35c..c5978aa 100644 --- a/src/map_builders/voronoi.rs +++ b/src/map_builders/voronoi.rs @@ -26,16 +26,6 @@ pub struct VoronoiCellBuilder { } impl MapBuilder for VoronoiCellBuilder { - fn build_map(&mut self) { - self.build(); - } - - fn spawn_entities(&mut self, ecs: &mut World) { - for area in self.noise_areas.iter() { - spawner::spawn_region(ecs, area.1, self.depth); - } - } - fn get_map(&self) -> Map { self.map.clone() } @@ -48,6 +38,16 @@ impl MapBuilder for VoronoiCellBuilder { self.history.clone() } + fn build_map(&mut self) { + self.build(); + } + + fn spawn_entities(&mut self, ecs: &mut World) { + for area in self.noise_areas.iter() { + spawner::spawn_region(ecs, area.1, self.depth); + } + } + fn take_snapshot(&mut self) { if SHOW_MAPGEN_VISUALIZER { let mut snapshot = self.map.clone(); diff --git a/src/map_builders/waveform_collapse/image_loader.rs b/src/map_builders/waveform_collapse/image_loader.rs deleted file mode 100644 index 75f125f..0000000 --- a/src/map_builders/waveform_collapse/image_loader.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::{Map, TileType}; -use rltk::rex::XpFile; - -/// Loads a RexPaint file, and converts it into our map format -pub fn load_rex_map(new_depth: i32, xp_file: &XpFile) -> Map { - let mut map = Map::new(new_depth); - - for layer in &xp_file.layers { - for y in 0..layer.height { - for x in 0..layer.width { - let cell = layer.get(x, y).unwrap(); - if x < map.width as usize && y < map.height as usize { - let idx = map.xy_idx(x as i32, y as i32); - match cell.ch { - 32 => map.tiles[idx] = TileType::Floor, // # - 35 => map.tiles[idx] = TileType::Wall, // # - _ => {} - } - } - } - } - } - - map -} diff --git a/src/map_builders/waveform_collapse/mod.rs b/src/map_builders/waveform_collapse/mod.rs index dea554a..0e1add0 100644 --- a/src/map_builders/waveform_collapse/mod.rs +++ b/src/map_builders/waveform_collapse/mod.rs @@ -1,6 +1,5 @@ mod common; mod constraints; -mod image_loader; mod solver; use super::common::{ @@ -10,39 +9,21 @@ use super::MapBuilder; use crate::{spawner, Map, Position, TileType, SHOW_MAPGEN_VISUALIZER}; use common::*; use constraints::*; -use image_loader::*; use rltk::RandomNumberGenerator; use solver::*; use specs::prelude::*; use std::collections::HashMap; -#[derive(PartialEq, Copy, Clone)] -pub enum WaveformMode { - TestMap, - Derived, -} - pub struct WaveformCollapseBuilder { map: Map, starting_position: Position, depth: i32, history: Vec, noise_areas: HashMap>, - mode: WaveformMode, derive_from: Option>, } impl MapBuilder for WaveformCollapseBuilder { - fn build_map(&mut self) { - self.build(); - } - - fn spawn_entities(&mut self, ecs: &mut World) { - for area in self.noise_areas.iter() { - spawner::spawn_region(ecs, area.1, self.depth); - } - } - fn get_map(&self) -> Map { self.map.clone() } @@ -55,6 +36,16 @@ impl MapBuilder for WaveformCollapseBuilder { self.history.clone() } + fn build_map(&mut self) { + self.build(); + } + + fn spawn_entities(&mut self, ecs: &mut World) { + for area in self.noise_areas.iter() { + spawner::spawn_region(ecs, area.1, self.depth); + } + } + fn take_snapshot(&mut self) { if SHOW_MAPGEN_VISUALIZER { let mut snapshot = self.map.clone(); @@ -73,7 +64,6 @@ impl WaveformCollapseBuilder { /// * derive_from - either None, or a boxed MapBuilder, as output by `random_builder` pub fn new( new_depth: i32, - mode: WaveformMode, derive_from: Option>, ) -> WaveformCollapseBuilder { WaveformCollapseBuilder { @@ -82,37 +72,19 @@ impl WaveformCollapseBuilder { depth: new_depth, history: Vec::new(), noise_areas: HashMap::new(), - mode, derive_from, } } - /// Creates a Wave Function Collapse builder using the baked-in WFC test map. - /// # Arguments - /// * new_depth - the new map depth - pub fn test_map(new_depth: i32) -> WaveformCollapseBuilder { - WaveformCollapseBuilder::new(new_depth, WaveformMode::TestMap, None) - } - /// Derives a map from a pre-existing map builder. /// # Arguments /// * new_depth - the new map depth /// * derive_from - either None, or a boxed MapBuilder, as output by `random_builder` pub fn derived_map(new_depth: i32, builder: Box) -> WaveformCollapseBuilder { - WaveformCollapseBuilder::new(new_depth, WaveformMode::Derived, Some(builder)) + WaveformCollapseBuilder::new(new_depth, Some(builder)) } fn build(&mut self) { - if self.mode == WaveformMode::TestMap { - self.map = load_rex_map( - self.depth, - &rltk::XpFile::from_resource("../resources/wfc-demo1.xp").unwrap(), - ); - self.take_snapshot(); - - return; - } - let mut rng = RandomNumberGenerator::new(); const CHUNK_SIZE: i32 = 8;