From 3cc88f9b1d29e79b19470586ac6c2ce7aeb413c1 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sun, 29 May 2022 19:37:10 +0200 Subject: [PATCH] move temp and humidity out of array, introduce different smoke types --- voxygen/src/scene/particle.rs | 46 ++++++++++++++++++---------- voxygen/src/scene/terrain.rs | 2 +- voxygen/src/scene/terrain/watcher.rs | 37 +++++++++++----------- 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index e0c8cde6ca..aafb60ade3 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -5,6 +5,7 @@ use crate::{ pipelines::particle::ParticleMode, Instances, Light, Model, ParticleDrawer, ParticleInstance, ParticleVertex, Renderer, }, + scene::terrain::FireplaceType, }; use common::{ assets::{AssetExt, DotVoxAsset}, @@ -1249,7 +1250,7 @@ impl ParticleMgr { } // smoke is more complex as it comes with varying rate and color { - struct FirePlaceProperties { + struct SmokeProperties { position: Vec3, strength: f32, dry_chance: f32, @@ -1268,28 +1269,39 @@ impl ParticleMgr { terrain.get(chunk_pos).map(|chunk_data| { let blocks = &chunk_data.blocks_of_interest.smokers; - let mut smoke_properties: Vec = Vec::new(); + let mut smoke_properties: Vec = Vec::new(); let block_pos = Vec3::from(chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32)); let mut sum = 0.0_f32; for smoker in blocks.iter() { let position = block_pos + smoker.position; - let prop = crate::scene::smoke_cycle::smoke_at_time( + let (strength, dry_chance) = { + match smoker.kind { + FireplaceType::House => { + let prop = crate::scene::smoke_cycle::smoke_at_time( + position, + chunk_data.blocks_of_interest.temperature, + time_of_day, + ); + ( + prop.0, + if prop.1 { + // fire started, dark smoke + 0.8 - chunk_data.blocks_of_interest.humidity + } else { + // fire continues, light smoke + 1.2 - chunk_data.blocks_of_interest.humidity + }, + ) + }, + FireplaceType::Workshop => (128.0, 1.0), + } + }; + sum += strength; + smoke_properties.push(SmokeProperties { position, - smoker.temperature, - time_of_day, - ); - sum += prop.0; - smoke_properties.push(FirePlaceProperties { - position, - strength: prop.0, - dry_chance: if prop.1 { - // fire started, dark smoke - 0.8 - smoker.humidity - } else { - // fire continues, light smoke - 1.2 - smoker.humidity - }, + strength, + dry_chance, }); } let avg_particles = dt * sum as f32 * rate; diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index f735b5cbd7..e6504646a5 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -1,6 +1,6 @@ mod watcher; -pub use self::watcher::{BlocksOfInterest, Interaction}; +pub use self::watcher::{BlocksOfInterest, FireplaceType, Interaction}; use crate::{ mesh::{ diff --git a/voxygen/src/scene/terrain/watcher.rs b/voxygen/src/scene/terrain/watcher.rs index 2374b71e31..0ca420bef8 100644 --- a/voxygen/src/scene/terrain/watcher.rs +++ b/voxygen/src/scene/terrain/watcher.rs @@ -12,20 +12,18 @@ pub enum Interaction { Mine, } -pub struct FireplaceProperties { - pub position: Vec3, - pub humidity: f32, - pub temperature: f32, +pub enum FireplaceType { + House, + Workshop, // this also includes witch hut } -impl FireplaceProperties { - fn new(position: Vec3, humidity: f32, temperature: f32) -> Self { - Self { - position, - humidity, - temperature, - } - } +pub struct SmokerProperties { + pub position: Vec3, + pub kind: FireplaceType, +} + +impl SmokerProperties { + fn new(position: Vec3, kind: FireplaceType) -> Self { Self { position, kind } } } #[derive(Default)] @@ -36,7 +34,7 @@ pub struct BlocksOfInterest { pub slow_river: Vec>, pub fast_river: Vec>, pub fires: Vec>, - pub smokers: Vec, + pub smokers: Vec, pub beehives: Vec>, pub reeds: Vec>, pub fireflies: Vec>, @@ -52,6 +50,9 @@ pub struct BlocksOfInterest { // area for optimization pub interactables: Vec<(Vec3, Interaction)>, pub lights: Vec<(Vec3, u8)>, + // needed for biome specific smoke variations + pub temperature: f32, + pub humidity: f32, } impl BlocksOfInterest { @@ -105,11 +106,7 @@ impl BlocksOfInterest { _ => match block.get_sprite() { Some(SpriteKind::Ember) => { fires.push(pos); - smokers.push(FireplaceProperties::new( - pos, - chunk.meta().humidity(), - chunk.meta().temp(), - )); + smokers.push(SmokerProperties::new(pos, FireplaceType::House)); }, // Offset positions to account for block height. // TODO: Is this a good idea? @@ -137,7 +134,7 @@ impl BlocksOfInterest { interactables.push((pos, Interaction::Craft(CraftingTab::All))) }, Some(SpriteKind::SmokeDummy) => { - smokers.push(FireplaceProperties::new(pos, 0.0, -1.0)); + smokers.push(SmokerProperties::new(pos, FireplaceType::Workshop)); }, Some(SpriteKind::Forge) => interactables .push((pos, Interaction::Craft(CraftingTab::ProcessedMaterial))), @@ -195,6 +192,8 @@ impl BlocksOfInterest { frogs, interactables, lights, + temperature: chunk.meta().temp(), + humidity: chunk.meta().humidity(), } } }