refactors entity spawning
This commit is contained in:
parent
e72d1bd694
commit
8664a8e066
13 changed files with 286 additions and 83 deletions
|
|
@ -21,17 +21,13 @@ pub struct VoronoiBuilder {
|
|||
noise_areas: HashMap<i32, Vec<usize>>,
|
||||
n_seeds: usize,
|
||||
distance_algorithm: DistanceAlgorithm,
|
||||
spawn_list: Vec<(usize, String)>,
|
||||
}
|
||||
|
||||
impl MapBuilder for VoronoiBuilder {
|
||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator) {
|
||||
return self.build(rng);
|
||||
}
|
||||
fn spawn_entities(&mut self, ecs: &mut World) {
|
||||
for area in self.noise_areas.iter() {
|
||||
spawner::spawn_region(ecs, area.1, self.depth);
|
||||
}
|
||||
}
|
||||
// Getters
|
||||
fn get_map(&mut self) -> Map {
|
||||
return self.map.clone();
|
||||
|
|
@ -39,6 +35,9 @@ impl MapBuilder for VoronoiBuilder {
|
|||
fn get_starting_pos(&mut self) -> Position {
|
||||
return self.starting_position.clone();
|
||||
}
|
||||
fn get_spawn_list(&self) -> &Vec<(usize, String)> {
|
||||
return &self.spawn_list;
|
||||
}
|
||||
// Mapgen visualisation stuff
|
||||
fn get_snapshot_history(&self) -> Vec<Map> {
|
||||
return self.history.clone();
|
||||
|
|
@ -64,6 +63,7 @@ impl VoronoiBuilder {
|
|||
noise_areas: HashMap::new(),
|
||||
n_seeds: 64,
|
||||
distance_algorithm: DistanceAlgorithm::Pythagoras,
|
||||
spawn_list: Vec::new(),
|
||||
}
|
||||
}
|
||||
pub fn manhattan(new_depth: i32) -> VoronoiBuilder {
|
||||
|
|
@ -75,6 +75,7 @@ impl VoronoiBuilder {
|
|||
noise_areas: HashMap::new(),
|
||||
n_seeds: 64,
|
||||
distance_algorithm: DistanceAlgorithm::Manhattan,
|
||||
spawn_list: Vec::new(),
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
|
|
@ -87,6 +88,7 @@ impl VoronoiBuilder {
|
|||
noise_areas: HashMap::new(),
|
||||
n_seeds: 64,
|
||||
distance_algorithm: DistanceAlgorithm::Chebyshev,
|
||||
spawn_list: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -174,5 +176,10 @@ impl VoronoiBuilder {
|
|||
|
||||
// Now we build a noise map for use in spawning entities later
|
||||
self.noise_areas = generate_voronoi_spawn_regions(&self.map, rng);
|
||||
|
||||
// Spawn the entities
|
||||
for area in self.noise_areas.iter() {
|
||||
spawner::spawn_region(&self.map, rng, area.1, self.depth, &mut self.spawn_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue