Skip to content

Commit

Permalink
Add Biome Settings for declaring biomes...
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGrimsey committed Nov 30, 2024
1 parent 6724516 commit a700504
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
5 changes: 2 additions & 3 deletions examples/basic_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ fn main() {

app.add_plugins(TerrainPlugin {
noise_settings: Some(TerrainNoiseSettings {
data: vec![],
splines: vec![],
noise_groups: vec![
NoiseGroup {
layers: vec![NoiseLayer {
Expand All @@ -57,7 +55,8 @@ fn main() {
}],
..default()
}
]
],
..default()
}),
terrain_settings: TerrainSettings {
tile_size_power: NonZeroU8::new(5).unwrap(),
Expand Down
5 changes: 2 additions & 3 deletions examples/many_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ fn main() {

app.add_plugins(TerrainPlugin {
noise_settings: Some(TerrainNoiseSettings {
data: vec![],
splines: vec![],
noise_groups: vec![
NoiseGroup {
layers: vec![
Expand Down Expand Up @@ -134,7 +132,8 @@ fn main() {
}],
filter_combinator: FilterCombinator::Min
}
]
],
..default()
}),
terrain_settings: TerrainSettings {
tile_size_power: NonZeroU8::new(7).unwrap(),
Expand Down
5 changes: 2 additions & 3 deletions examples/terrain_collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ fn main() {

app.add_plugins(TerrainPlugin {
noise_settings: Some(TerrainNoiseSettings {
data: vec![],
splines: vec![],
noise_groups: vec![
NoiseGroup {
layers: vec![NoiseLayer {
Expand All @@ -67,7 +65,8 @@ fn main() {
}],
..default()
}
]
],
..default()
}),
terrain_settings: TerrainSettings {
tile_size_power: NonZeroU8::new(6).unwrap(),
Expand Down
50 changes: 38 additions & 12 deletions src/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,25 +409,29 @@ pub fn calc_filter_strength(
FilterComparingTo::Data { index } => noise_settings
.data
.get(*index as usize)
.map(|layer| {
.map_or(0.0, |layer| {
layer.sample_scaled_raw(
pos.x,
pos.y,
noise_cache.get_by_index(data_noise_cache[*index as usize] as usize),
)
})
.unwrap_or(0.0),
}),
FilterComparingTo::Spline { index } => noise_settings
.splines
.get(*index as usize)
.map(|spline| {
.map_or(0.0, |spline| {
spline.sample_raw(
pos.x,
pos.y,
noise_cache.get_by_index(spline_noise_cache[*index as usize] as usize),
)
})
.unwrap_or(0.0),
}),
FilterComparingTo::Biome { index } => noise_settings
.biome
.get(*index as usize)
.map_or(0.0, |biome| {
calc_filter_strength(pos, &biome.filters, biome.filter_combinator, noise_settings, noise_cache, data_noise_cache, spline_noise_cache)
}),
};
let initial_filter_strength = initial_filter.get_filter(sample_filter(initial_filter));

Expand Down Expand Up @@ -466,25 +470,29 @@ fn calc_filter_strength_simd(
FilterComparingTo::Data { index } => noise_settings
.data
.get(*index as usize)
.map(|layer| {
.map_or(Vec4::ZERO, |layer| {
layer.sample_simd_scaled_raw(
x,
z,
noise_cache.get_by_index(data_noise_cache[*index as usize] as usize),
)
})
.unwrap_or(Vec4::ZERO),
}),
FilterComparingTo::Spline { index } => noise_settings
.splines
.get(*index as usize)
.map(|spline| {
.map_or(Vec4::ZERO, |spline| {
spline.sample_simd_raw(
x,
z,
noise_cache.get_by_index(spline_noise_cache[*index as usize] as usize),
)
})
.unwrap_or(Vec4::ZERO),
}),
FilterComparingTo::Biome { index } => noise_settings
.biome
.get(*index as usize)
.map_or(Vec4::ZERO, |biome| {
calc_filter_strength_simd(x, z, &biome.filters, biome.filter_combinator, noise_settings, noise_cache, data_noise_cache, spline_noise_cache)
}),
};
let initial_filter_strength = initial_filter.get_filter_simd(sample_filter(initial_filter));

Expand Down Expand Up @@ -621,6 +629,9 @@ pub enum FilterComparingTo {
Spline {
index: u32,
},
Biome {
index: u32
}
}
impl Default for FilterComparingTo {
fn default() -> Self {
Expand Down Expand Up @@ -725,10 +736,25 @@ impl Default for NoiseFilterCondition {
}
}

/**
* A biome.
*
* A collection of filters determining where a biome is placed.
*/
#[derive(Resource, Reflect, Clone, Default)]
pub struct BiomeSettings {
pub filters: Vec<NoiseFilter>,
pub filter_combinator: FilterCombinator

// Biome flags?
}

/// Noise layers to be applied to Terrain tiles.
#[derive(Resource, Reflect, Clone, Default)]
#[reflect(Resource)]
pub struct TerrainNoiseSettings {
pub biome: Vec<BiomeSettings>,

/// Data noise.
///
/// Not applied to the world but can be used to for filters.
Expand Down

0 comments on commit a700504

Please sign in to comment.