From 6fc7d2a9068af2ec5f0309d8b44529e99ea8cec4 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 8 Feb 2021 02:29:25 +0000 Subject: [PATCH] Faster More interesting giant trees, better oaks, hives on branches --- common/src/terrain/structure.rs | 1 + voxygen/src/scene/particle.rs | 2 +- voxygen/src/scene/terrain/watcher.rs | 7 ++++- world/src/all.rs | 2 +- world/src/block/mod.rs | 1 + world/src/layer/tree.rs | 38 ++++++++++++++++++---------- world/src/lib.rs | 2 +- world/src/sim/mod.rs | 4 ++- 8 files changed, 38 insertions(+), 19 deletions(-) diff --git a/common/src/terrain/structure.rs b/common/src/terrain/structure.rs index 4a9867474a..3db0b3b037 100644 --- a/common/src/terrain/structure.rs +++ b/common/src/terrain/structure.rs @@ -30,6 +30,7 @@ make_case_elim!( Hollow = 13, Liana = 14, Normal(color: Rgb) = 15, + Log = 16, } ); diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index efd3d3de8e..d7d1f658bf 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -571,7 +571,7 @@ impl ParticleMgr { cond: |_| true, }, BlockParticles { - blocks: |boi| &boi.reeds, + blocks: |boi| &boi.fireflies, range: 6, rate: 0.004, lifetime: 40.0, diff --git a/voxygen/src/scene/terrain/watcher.rs b/voxygen/src/scene/terrain/watcher.rs index 257e01c05e..2d68b512d5 100644 --- a/voxygen/src/scene/terrain/watcher.rs +++ b/voxygen/src/scene/terrain/watcher.rs @@ -15,6 +15,7 @@ pub struct BlocksOfInterest { pub smokers: Vec>, pub beehives: Vec>, pub reeds: Vec>, + pub fireflies: Vec>, pub flowers: Vec>, pub fire_bowls: Vec>, pub snow: Vec>, @@ -39,6 +40,7 @@ impl BlocksOfInterest { let mut smokers = Vec::new(); let mut beehives = Vec::new(); let mut reeds = Vec::new(); + let mut fireflies = Vec::new(); let mut flowers = Vec::new(); let mut interactables = Vec::new(); let mut lights = Vec::new(); @@ -94,10 +96,12 @@ impl BlocksOfInterest { Some(SpriteKind::Beehive) => beehives.push(pos), Some(SpriteKind::Reed) => { reeds.push(pos); + fireflies.push(pos); if thread_rng().gen_range(0..12) == 0 { - frogs.push(pos) + frogs.push(pos); } }, + Some(SpriteKind::CaveMushroom) => fireflies.push(pos), Some(SpriteKind::PinkFlower) => flowers.push(pos), Some(SpriteKind::PurpleFlower) => flowers.push(pos), Some(SpriteKind::RedFlower) => flowers.push(pos), @@ -123,6 +127,7 @@ impl BlocksOfInterest { smokers, beehives, reeds, + fireflies, flowers, interactables, lights, diff --git a/world/src/all.rs b/world/src/all.rs index 2630d78b05..ecd63e04b3 100644 --- a/world/src/all.rs +++ b/world/src/all.rs @@ -12,8 +12,8 @@ pub enum ForestKind { Pine, Birch, Mangrove, - Swamp, Giant, + Swamp, } pub struct Environment { diff --git a/world/src/block/mod.rs b/world/src/block/mod.rs index a7f3c4c156..cdc8d1e2ce 100644 --- a/world/src/block/mod.rs +++ b/world/src/block/mod.rs @@ -249,6 +249,7 @@ pub fn block_from_structure( Some(with_sprite(SpriteKind::Chest)) } }, + StructureBlock::Log => Some(Block::new(BlockKind::Wood, Rgb::new(60, 30, 0))), // We interpolate all these BlockKinds as needed. StructureBlock::TemperateLeaves | StructureBlock::PineLeaves diff --git a/world/src/layer/tree.rs b/world/src/layer/tree.rs index c1e178a188..becc22045a 100644 --- a/world/src/layer/tree.rs +++ b/world/src/layer/tree.rs @@ -9,7 +9,7 @@ use common::{ assets::AssetHandle, terrain::{ structure::{Structure, StructureBlock, StructuresGroup}, - Block, BlockKind, + Block, BlockKind, SpriteKind, }, vol::ReadVol, }; @@ -40,7 +40,7 @@ static UNIT_CHOOSER: UnitChooser = UnitChooser::new(0x700F4EC7); static QUIRKY_RAND: RandomPerm = RandomPerm::new(0xA634460F); #[allow(clippy::if_same_then_else)] -pub fn apply_trees_to(canvas: &mut Canvas) { +pub fn apply_trees_to(canvas: &mut Canvas, dynamic_rng: &mut impl Rng) { // TODO: Get rid of this enum TreeModel { Structure(Structure), @@ -167,6 +167,7 @@ pub fn apply_trees_to(canvas: &mut Canvas) { let mut is_top = true; let mut is_leaf_top = true; + let mut last_block = Block::empty(); for z in (bounds.min.z..bounds.max.z).rev() { let wpos = Vec3::new(wpos2d.x, wpos2d.y, tree.pos.z + z); let model_pos = Vec3::from( @@ -183,7 +184,7 @@ pub fn apply_trees_to(canvas: &mut Canvas) { TreeModel::Structure(s) => s.get(model_pos).ok().copied(), TreeModel::Procedural(t, leaf_block) => Some( match t.is_branch_or_leaves_at(model_pos.map(|e| e as f32 + 0.5)) { - (true, _) => StructureBlock::Normal(Rgb::new(60, 30, 0)), + (true, _) => StructureBlock::Log, (_, true) => *leaf_block, (_, _) => StructureBlock::None, }, @@ -200,8 +201,11 @@ pub fn apply_trees_to(canvas: &mut Canvas) { Block::air, ) .map(|block| { + // Add mushrooms to the tree + if last_block.is_air() && block.kind() == BlockKind::Wood && dynamic_rng.gen_range(0..48) == 0 { + canvas.set(wpos + Vec3::unit_z(), Block::air(SpriteKind::CaveMushroom)); // Add a snow covering to the block above under certain circumstances - if col.snow_cover + } else if col.snow_cover && ((block.kind() == BlockKind::Leaves && is_leaf_top) || (is_top && block.is_filled())) { @@ -213,9 +217,15 @@ pub fn apply_trees_to(canvas: &mut Canvas) { canvas.set(wpos, block); is_leaf_top = false; is_top = false; + last_block = block; }) .unwrap_or_else(|| { + if last_block.kind() == BlockKind::Wood && dynamic_rng.gen_range(0..512) == 0 { + canvas.set(wpos, Block::air(SpriteKind::Beehive)); + } + is_leaf_top = true; + last_block = Block::empty(); }); } } @@ -260,18 +270,18 @@ pub struct TreeConfig { impl TreeConfig { pub fn oak(rng: &mut impl Rng, scale: f32) -> Self { - let scale = scale * (1.0 + rng.gen::().powi(4)); + let scale = scale * (0.9 + rng.gen::().powi(4)); let log_scale = 1.0 + scale.log2().max(0.0); Self { trunk_len: 9.0 * scale, trunk_radius: 2.0 * scale, - branch_child_len: 0.8, + branch_child_len: 0.9, branch_child_radius: 0.75, leaf_radius: 2.5 * log_scale..3.25 * log_scale, - straightness: 0.5, - max_depth: (4.0 + log_scale) as usize, - splits: 2.0..3.0, + straightness: 0.45, + max_depth: 4, + splits: 2.25..3.25, split_range: 0.75..1.5, branch_len_bias: 0.0, leaf_vertical_scale: 1.0, @@ -308,11 +318,11 @@ impl TreeConfig { trunk_radius: 4.0 * scale, branch_child_len: 0.9, branch_child_radius: 0.7, - leaf_radius: 1.5 * log_scale..2.0 * log_scale, - straightness: 0.4, - max_depth: (6.0 + log_scale) as usize, - splits: 1.8..3.0, - split_range: 0.8..1.5, + leaf_radius: 2.25 * log_scale..3.5 * log_scale, + straightness: 0.5, + max_depth: (7.0 + log_scale) as usize, + splits: 1.5..2.75, + split_range: 1.0..1.1, branch_len_bias: 0.0, leaf_vertical_scale: 1.0, proportionality: 0.0, diff --git a/world/src/lib.rs b/world/src/lib.rs index 73dc97b95a..794948f663 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -286,7 +286,7 @@ impl World { chunk: &mut chunk, }; - layer::apply_trees_to(&mut canvas); + layer::apply_trees_to(&mut canvas, &mut dynamic_rng); layer::apply_scatter_to(&mut canvas, &mut dynamic_rng); layer::apply_caves_to(&mut canvas, &mut dynamic_rng); layer::apply_paths_to(&mut canvas); diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 7e10508125..51914c28d9 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -2026,10 +2026,12 @@ impl WorldSim { }); let giant_trees = std::array::IntoIter::new(self.gen_ctx.big_structure_gen.get(wpos)) + // Don't even consider trees if we aren't close + .filter(move |(pos, _)| pos.distance_squared(wpos) < 256i32.pow(2)) .map(move |(pos, seed)| TreeAttr { pos, seed, - scale: 5.0, + scale: 4.0, forest_kind: ForestKind::Giant, });