new creates Box. Ver 0.2
This commit is contained in:
parent
27023f0443
commit
16955e02da
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "mapgen"
|
||||
version = "0.1.2"
|
||||
version = "0.2.0"
|
||||
authors = ["Krzysztof Langner <klangner@gmail.com>"]
|
||||
description = "Map generator for games (dungeons, worlds etc.)"
|
||||
keywords = ["game", "map", "map-generator"]
|
||||
|
|
|
@ -31,7 +31,7 @@ pub struct World {
|
|||
impl World {
|
||||
pub fn new_cellular_automata(width: u32, height: u32, seed: u32) -> World {
|
||||
let mut rng = StdRng::seed_from_u64(seed as u64);
|
||||
let map = MapBuilder::new(Box::new(CellularAutomataGen::new()))
|
||||
let map = MapBuilder::new(CellularAutomataGen::new())
|
||||
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
|
||||
.with(CullUnreachable::new())
|
||||
.with(DistantExit::new())
|
||||
|
@ -47,7 +47,7 @@ impl World {
|
|||
|
||||
pub fn new_random_rooms(width: u32, height: u32, seed: u32) -> World {
|
||||
let mut rng = StdRng::seed_from_u64(seed as u64);
|
||||
let map = MapBuilder::new(Box::new(RandomRoomsGen::new()))
|
||||
let map = MapBuilder::new(RandomRoomsGen::new())
|
||||
.with(NearestCorridors::new())
|
||||
.build_map_with_rng(width as usize, height as usize, &mut rng);
|
||||
let tiles = (0..map.tiles.len())
|
||||
|
|
|
@ -39,8 +39,8 @@ impl MapGenerator for CellularAutomataGen {
|
|||
|
||||
impl CellularAutomataGen {
|
||||
/// Create generator which will create map with the given dimension.
|
||||
pub fn new() -> CellularAutomataGen {
|
||||
CellularAutomataGen {}
|
||||
pub fn new() -> Box<CellularAutomataGen> {
|
||||
Box::new(CellularAutomataGen {})
|
||||
}
|
||||
|
||||
/// Generate map
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
//! starting_point::{AreaStartingPosition, XStart, YStart},
|
||||
//! };
|
||||
//!
|
||||
//! let map = MapBuilder::new(Box::new(CellularAutomataGen::new()))
|
||||
//! let map = MapBuilder::new(CellularAutomataGen::new())
|
||||
//! .with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
|
||||
//! .build_map(80, 50);
|
||||
//!
|
||||
|
@ -104,7 +104,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_ca_map() {
|
||||
let map = MapBuilder::new(Box::new(CellularAutomataGen::new()))
|
||||
let map = MapBuilder::new(CellularAutomataGen::new())
|
||||
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
|
||||
.build_map(80, 50);
|
||||
|
||||
|
|
|
@ -40,12 +40,12 @@ impl MapGenerator for RandomRoomsGen {
|
|||
|
||||
|
||||
impl RandomRoomsGen {
|
||||
pub fn new() -> RandomRoomsGen {
|
||||
RandomRoomsGen{
|
||||
pub fn new() -> Box<RandomRoomsGen> {
|
||||
Box::new(RandomRoomsGen{
|
||||
max_rooms: 30,
|
||||
min_room_size: 6,
|
||||
max_room_size: 10
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn build_rooms(&self, width: usize, height: usize, rng : &mut StdRng) -> Map {
|
||||
|
|
Loading…
Reference in New Issue
Block a user