Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Split apart unit and structure generation
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed Jun 27, 2023
1 parent 7047488 commit af1d5a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
22 changes: 15 additions & 7 deletions emergence_lib/src/world_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::structures::structure_manifest::Structure;
use crate::terrain::terrain_manifest::Terrain;
use crate::units::unit_manifest::Unit;
use crate::utils::noise::SimplexSettings;
use crate::world_gen::organism_generation::{generate_organisms, randomize_starting_organisms};
use crate::world_gen::structure_generation::{
generate_structures, generate_units, randomize_starting_organisms,
};
use crate::world_gen::terrain_generation::{
generate_landmarks, generate_terrain, initialize_water_table,
};
Expand All @@ -14,7 +16,7 @@ use bevy::prelude::*;
use bevy::utils::HashMap;
use bevy_framepace::{FramepaceSettings, Limiter};

mod organism_generation;
mod structure_generation;
mod terrain_generation;

/// Generate the world.
Expand All @@ -35,7 +37,9 @@ impl Plugin for GenerationPlugin {
generate_landmarks,
initialize_water_table,
apply_system_buffers,
generate_organisms,
generate_structures,
apply_system_buffers,
generate_units,
apply_system_buffers,
randomize_starting_organisms,
)
Expand Down Expand Up @@ -256,7 +260,7 @@ mod tests {
app.add_plugin(DummyManifestPlugin);
app.insert_resource(GenerationConfig::testing());
app.insert_resource(GlobalRng::new(0));
app.add_startup_systems((generate_terrain, generate_organisms).chain());
app.add_startup_systems((generate_terrain, generate_structures).chain());

app.update();
}
Expand All @@ -267,7 +271,9 @@ mod tests {
app.add_plugin(DummyManifestPlugin);
app.insert_resource(GenerationConfig::testing());
app.insert_resource(GlobalRng::new(0));
app.add_startup_systems((generate_terrain, generate_organisms, generate_landmarks).chain());
app.add_startup_systems(
(generate_terrain, generate_structures, generate_landmarks).chain(),
);

app.update();

Expand All @@ -290,7 +296,9 @@ mod tests {
app.add_plugin(DummyManifestPlugin);
app.insert_resource(GenerationConfig::testing());
app.insert_resource(GlobalRng::new(0));
app.add_startup_systems((generate_terrain, generate_organisms, generate_landmarks).chain());
app.add_startup_systems(
(generate_terrain, generate_structures, generate_landmarks).chain(),
);

app.update();

Expand All @@ -309,7 +317,7 @@ mod tests {
app.add_plugin(DummyManifestPlugin);
app.insert_resource(GenerationConfig::testing());
app.insert_resource(GlobalRng::new(0));
app.add_startup_systems((generate_terrain, generate_organisms).chain());
app.add_startup_systems((generate_terrain, generate_structures).chain());

app.update();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ use rand::{thread_rng, Rng};

use super::GenerationConfig;

/// Create starting organisms according to [`GenerationConfig`], and randomly place them on
/// passable tiles.
pub(super) fn generate_organisms(
/// Create starting structures according to [`GenerationConfig`], and randomly place them on
/// top of the terrain.
pub(super) fn generate_structures(
mut commands: Commands,
config: Res<GenerationConfig>,
maybe_unit_handles: Option<Res<UnitHandles>>,
unit_manifest: Res<UnitManifest>,
structure_manifest: Res<StructureManifest>,
map_geometry: Res<MapGeometry>,
mut rng: ResMut<GlobalRng>,
) {
info!("Generating organisms...");
info!("Generating structures...");

// Collect out so we can mutate the height map to flatten the terrain while in the loop
for voxel_pos in map_geometry.walkable_voxels() {
Expand All @@ -55,7 +53,23 @@ pub(super) fn generate_organisms(
}
}
}
}
}

/// Create starting units according to [`GenerationConfig`], and randomly place them on
/// passable tiles.
pub(super) fn generate_units(
mut commands: Commands,
config: Res<GenerationConfig>,
maybe_unit_handles: Option<Res<UnitHandles>>,
unit_manifest: Res<UnitManifest>,
map_geometry: Res<MapGeometry>,
mut rng: ResMut<GlobalRng>,
) {
info!("Generating units...");

// Collect out so we can mutate the height map to flatten the terrain while in the loop
for voxel_pos in map_geometry.walkable_voxels() {
for (&unit_id, &chance) in &config.unit_chances {
if rng.gen::<f32>() < chance {
let unit_bundle = if let Some(ref unit_handles) = maybe_unit_handles {
Expand Down

0 comments on commit af1d5a7

Please sign in to comment.