move temp and humidity out of array, introduce different smoke types

This commit is contained in:
Christof Petig 2022-05-29 19:37:10 +02:00
parent bf3eef6e1a
commit 3cc88f9b1d
3 changed files with 48 additions and 37 deletions

View File

@ -5,6 +5,7 @@ use crate::{
pipelines::particle::ParticleMode, Instances, Light, Model, ParticleDrawer, pipelines::particle::ParticleMode, Instances, Light, Model, ParticleDrawer,
ParticleInstance, ParticleVertex, Renderer, ParticleInstance, ParticleVertex, Renderer,
}, },
scene::terrain::FireplaceType,
}; };
use common::{ use common::{
assets::{AssetExt, DotVoxAsset}, assets::{AssetExt, DotVoxAsset},
@ -1249,7 +1250,7 @@ impl ParticleMgr {
} }
// smoke is more complex as it comes with varying rate and color // smoke is more complex as it comes with varying rate and color
{ {
struct FirePlaceProperties { struct SmokeProperties {
position: Vec3<i32>, position: Vec3<i32>,
strength: f32, strength: f32,
dry_chance: f32, dry_chance: f32,
@ -1268,28 +1269,39 @@ impl ParticleMgr {
terrain.get(chunk_pos).map(|chunk_data| { terrain.get(chunk_pos).map(|chunk_data| {
let blocks = &chunk_data.blocks_of_interest.smokers; let blocks = &chunk_data.blocks_of_interest.smokers;
let mut smoke_properties: Vec<FirePlaceProperties> = Vec::new(); let mut smoke_properties: Vec<SmokeProperties> = Vec::new();
let block_pos = let block_pos =
Vec3::from(chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32)); Vec3::from(chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32));
let mut sum = 0.0_f32; let mut sum = 0.0_f32;
for smoker in blocks.iter() { for smoker in blocks.iter() {
let position = block_pos + smoker.position; 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, position,
smoker.temperature, strength,
time_of_day, dry_chance,
);
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
},
}); });
} }
let avg_particles = dt * sum as f32 * rate; let avg_particles = dt * sum as f32 * rate;

View File

@ -1,6 +1,6 @@
mod watcher; mod watcher;
pub use self::watcher::{BlocksOfInterest, Interaction}; pub use self::watcher::{BlocksOfInterest, FireplaceType, Interaction};
use crate::{ use crate::{
mesh::{ mesh::{

View File

@ -12,20 +12,18 @@ pub enum Interaction {
Mine, Mine,
} }
pub struct FireplaceProperties { pub enum FireplaceType {
pub position: Vec3<i32>, House,
pub humidity: f32, Workshop, // this also includes witch hut
pub temperature: f32,
} }
impl FireplaceProperties { pub struct SmokerProperties {
fn new(position: Vec3<i32>, humidity: f32, temperature: f32) -> Self { pub position: Vec3<i32>,
Self { pub kind: FireplaceType,
position, }
humidity,
temperature, impl SmokerProperties {
} fn new(position: Vec3<i32>, kind: FireplaceType) -> Self { Self { position, kind } }
}
} }
#[derive(Default)] #[derive(Default)]
@ -36,7 +34,7 @@ pub struct BlocksOfInterest {
pub slow_river: Vec<Vec3<i32>>, pub slow_river: Vec<Vec3<i32>>,
pub fast_river: Vec<Vec3<i32>>, pub fast_river: Vec<Vec3<i32>>,
pub fires: Vec<Vec3<i32>>, pub fires: Vec<Vec3<i32>>,
pub smokers: Vec<FireplaceProperties>, pub smokers: Vec<SmokerProperties>,
pub beehives: Vec<Vec3<i32>>, pub beehives: Vec<Vec3<i32>>,
pub reeds: Vec<Vec3<i32>>, pub reeds: Vec<Vec3<i32>>,
pub fireflies: Vec<Vec3<i32>>, pub fireflies: Vec<Vec3<i32>>,
@ -52,6 +50,9 @@ pub struct BlocksOfInterest {
// area for optimization // area for optimization
pub interactables: Vec<(Vec3<i32>, Interaction)>, pub interactables: Vec<(Vec3<i32>, Interaction)>,
pub lights: Vec<(Vec3<i32>, u8)>, pub lights: Vec<(Vec3<i32>, u8)>,
// needed for biome specific smoke variations
pub temperature: f32,
pub humidity: f32,
} }
impl BlocksOfInterest { impl BlocksOfInterest {
@ -105,11 +106,7 @@ impl BlocksOfInterest {
_ => match block.get_sprite() { _ => match block.get_sprite() {
Some(SpriteKind::Ember) => { Some(SpriteKind::Ember) => {
fires.push(pos); fires.push(pos);
smokers.push(FireplaceProperties::new( smokers.push(SmokerProperties::new(pos, FireplaceType::House));
pos,
chunk.meta().humidity(),
chunk.meta().temp(),
));
}, },
// Offset positions to account for block height. // Offset positions to account for block height.
// TODO: Is this a good idea? // TODO: Is this a good idea?
@ -137,7 +134,7 @@ impl BlocksOfInterest {
interactables.push((pos, Interaction::Craft(CraftingTab::All))) interactables.push((pos, Interaction::Craft(CraftingTab::All)))
}, },
Some(SpriteKind::SmokeDummy) => { Some(SpriteKind::SmokeDummy) => {
smokers.push(FireplaceProperties::new(pos, 0.0, -1.0)); smokers.push(SmokerProperties::new(pos, FireplaceType::Workshop));
}, },
Some(SpriteKind::Forge) => interactables Some(SpriteKind::Forge) => interactables
.push((pos, Interaction::Craft(CraftingTab::ProcessedMaterial))), .push((pos, Interaction::Craft(CraftingTab::ProcessedMaterial))),
@ -195,6 +192,8 @@ impl BlocksOfInterest {
frogs, frogs,
interactables, interactables,
lights, lights,
temperature: chunk.meta().temp(),
humidity: chunk.meta().humidity(),
} }
} }
} }