refactors entity spawning
This commit is contained in:
parent
e72d1bd694
commit
8664a8e066
13 changed files with 286 additions and 83 deletions
|
|
@ -19,17 +19,13 @@ pub struct WaveFunctionCollapseBuilder {
|
|||
history: Vec<Map>,
|
||||
noise_areas: HashMap<i32, Vec<usize>>,
|
||||
derive_from: Option<Box<dyn MapBuilder>>,
|
||||
spawn_list: Vec<(usize, String)>,
|
||||
}
|
||||
|
||||
impl MapBuilder for WaveFunctionCollapseBuilder {
|
||||
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();
|
||||
|
|
@ -37,6 +33,9 @@ impl MapBuilder for WaveFunctionCollapseBuilder {
|
|||
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();
|
||||
|
|
@ -61,6 +60,7 @@ impl WaveFunctionCollapseBuilder {
|
|||
history: Vec::new(),
|
||||
noise_areas: HashMap::new(),
|
||||
derive_from,
|
||||
spawn_list: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +117,11 @@ impl WaveFunctionCollapseBuilder {
|
|||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_tile_gallery(&mut self, constraints: &Vec<MapChunk>, chunk_size: i32) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue