Added shrub layer with example shrub

This commit is contained in:
Joshua Barretto 2021-09-01 00:44:55 +01:00
parent 263f02dc11
commit 3f7e0a5e52
6 changed files with 76 additions and 4 deletions

View File

@ -0,0 +1,8 @@
#![enable(unwrap_newtypes)]
[
(
specifier: "world.shrub.1",
center: (6, 6, 2),
),
]

BIN
assets/world/shrub/1.vox (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -1,9 +1,12 @@
pub mod scatter;
pub mod shrub;
pub mod spot;
pub mod tree;
pub mod wildlife;
pub use self::{scatter::apply_scatter_to, spot::apply_spots_to, tree::apply_trees_to};
pub use self::{
scatter::apply_scatter_to, shrub::apply_shrubs_to, spot::apply_spots_to, tree::apply_trees_to,
};
use crate::{
column::ColumnSample,

57
world/src/layer/shrub.rs Normal file
View File

@ -0,0 +1,57 @@
use crate::{
util::{seed_expan, RandomPerm, Sampler, StructureGen2d, UnitChooser},
Canvas,
};
use common::{
assets::AssetHandle,
terrain::structure::{Structure, StructuresGroup},
vol::ReadVol,
};
use hashbrown::HashMap;
use lazy_static::lazy_static;
use rand::prelude::*;
use rand_chacha::ChaChaRng;
use vek::*;
lazy_static! {
static ref SHRUBS: AssetHandle<StructuresGroup> = Structure::load_group("shrubs");
}
struct Shrub {
wpos: Vec3<i32>,
seed: u32,
}
pub fn apply_shrubs_to(canvas: &mut Canvas, rng: &mut impl Rng) {
let mut shrub_cache = HashMap::new();
let shrub_gen = StructureGen2d::new(canvas.index().seed, 8, 4);
let info = canvas.info();
canvas.foreach_col(|canvas, wpos2d, col| {
for (wpos, seed) in std::array::IntoIter::new(shrub_gen.get(wpos2d)) {
shrub_cache.entry(wpos).or_insert_with(|| {
let col = info.col_or_gen(wpos)?;
if RandomPerm::new(seed).chance(37, col.tree_density * 0.3) {
Some(Shrub {
wpos: wpos.with_z(col.alt as i32),
seed,
})
} else {
None
}
});
}
});
for shrub in shrub_cache.values().filter_map(|s| s.as_ref()) {
let mut rng = ChaChaRng::from_seed(seed_expan::rng_state(shrub.seed));
let units = UnitChooser::new(shrub.seed).get(shrub.seed).into();
let shrubs = SHRUBS.read();
let structure = shrubs.choose(&mut rng).unwrap();
canvas.blit_structure(shrub.wpos, structure, shrub.seed, units, true);
}
}

View File

@ -360,7 +360,7 @@ impl TreeConfig {
}
pub fn jungle(rng: &mut impl Rng, scale: f32) -> Self {
let scale = scale * (0.9 + rng.gen::<f32>().powi(4) * 1.0);
let scale = scale * (0.8 + rng.gen::<f32>() * 0.5);
let log_scale = 1.0 + scale.log2().max(0.0);
Self {
@ -469,14 +469,14 @@ impl TreeConfig {
branch_child_len: 0.75,
branch_child_radius: 0.75,
branch_child_radius_lerp: true,
leaf_radius: 2.0 * log_scale..2.1 * log_scale,
leaf_radius: 1.5 * log_scale..2.0 * log_scale,
leaf_radius_scaled: 0.0,
straightness: 0.3,
max_depth: 5,
splits: 3.5..4.25,
split_range: 0.5..1.25,
branch_len_bias: 0.0,
leaf_vertical_scale: 0.5,
leaf_vertical_scale: 0.65,
proportionality: 0.5,
inhabited: false,
hanging_sprites: &[(0.00007, SpriteKind::Beehive)],

View File

@ -347,6 +347,7 @@ impl World {
};
layer::apply_caves_to(&mut canvas, &mut dynamic_rng);
layer::apply_shrubs_to(&mut canvas, &mut dynamic_rng);
layer::apply_trees_to(&mut canvas, &mut dynamic_rng);
layer::apply_scatter_to(&mut canvas, &mut dynamic_rng);
layer::apply_paths_to(&mut canvas);