humidity + clean up

This commit is contained in:
Christof Petig 2022-05-25 22:43:16 +02:00
parent 92ab095480
commit dd28dc81be
2 changed files with 22 additions and 41 deletions

View File

@ -1250,22 +1250,6 @@ impl ParticleMgr {
}
// smoke is more complex as it comes with varying rate and color
{
// fn create_smoke(
// position: Vec3<i32>,
// temperature: f32,
// humidity: f32,
// time_of_day: f32,
// ) -> FireplaceProperties {
// let mut rng2 = ChaCha8Rng::from_seed(seed_from_pos(pos));
// let strength_mod = (0.5_f32 - temperature).max(0.0); // -0.5 (desert) to
// 1.5 (ice) let strength =
// rng2.gen_range((5.0 * strength_mod)..(100.0 * strength_mod).max(1.0))
// as u8; let dryness = (biome_dryness(chunk.meta().biome()) +
// rng2.gen_range(-20..20)) .min(255)
// .max(0) as u8;
// // tracing::trace!(?pos, ?strength, ?dryness);
// FireplaceProperties::new(pos, dryness, strength)
// }
struct FirePlaceProperties {
position: Vec3<i32>,
strength: f32,
@ -1280,7 +1264,6 @@ impl ParticleMgr {
.get_time_of_day()
.rem_euclid(24.0 * 60.0 * 60.0) as f32;
// mode: ParticleMode::CampfireSmoke,
for offset in Spiral2d::new().take((range * 2 + 1).pow(2)) {
let chunk_pos = player_chunk + offset;
@ -1295,19 +1278,21 @@ impl ParticleMgr {
let prop = crate::scene::smoke_cycle::smoke_at_time(
position,
smoker.temperature,
smoker.humidity,
time_of_day,
);
sum += prop.0;
smoke_properties.push(FirePlaceProperties {
position,
strength: prop.0,
dry_chance: 0.5,
dry_chance: if prop.1 {
// fire started, dark smoke
0.8 - smoker.humidity
} else {
// fire continues, light smoke
1.2 - smoker.humidity
},
});
}
// let sum = blocks
// .iter()
// .fold(0u32, |sum, smoker| sum + smoker.strength as u32);
let avg_particles = dt * sum as f32 * rate;
let particle_count = avg_particles.trunc() as usize

View File

@ -82,13 +82,14 @@ fn create_timing(rng: &mut ChaCha8Rng) -> FireplaceTiming {
}
}
fn create_climate(temperature: f32, _humidity: f32) -> FireplaceClimate {
// temp -1…1, humidity 0…1
fn create_climate(temperature: f32) -> FireplaceClimate {
// temp -1…1
let daily_strength =
(SMOKE_MAX_TEMPERATURE - temperature).min(SMOKE_MAX_TEMP_VALUE) * SMOKE_TEMP_MULTIPLIER;
// when is breakfast down to daily strength
// daily_strength ==
// SMOKE_BREAKFAST_STRENGTH*(1.0-(t-breakfast)/SMOKE_BREAKFAST_HALF_DURATION)
//
// (t-breakfast) = (1.0 -
// daily_strength/SMOKE_BREAKFAST_STRENGTH)*SMOKE_BREAKFAST_HALF_DURATION
let day_start = (SMOKE_BREAKFAST_STRENGTH - daily_strength.max(0.0))
@ -104,15 +105,10 @@ fn create_climate(temperature: f32, _humidity: f32) -> FireplaceClimate {
pub type Increasing = bool;
pub fn smoke_at_time(
position: Vec3<i32>,
temperature: f32,
humidity: f32,
time_of_day: f32,
) -> (f32, Increasing) {
pub fn smoke_at_time(position: Vec3<i32>, temperature: f32, time_of_day: f32) -> (f32, Increasing) {
let mut pseudorandom = ChaCha8Rng::from_seed(seed_from_pos(position));
let timing = create_timing(&mut pseudorandom);
let climate = create_climate(temperature, humidity);
let climate = create_climate(temperature);
let after_breakfast = time_of_day - timing.breakfast;
if after_breakfast < -SMOKE_BREAKFAST_HALF_DURATION {
/* night */
@ -167,12 +163,12 @@ pub fn smoke_at_time(
mod tests {
use super::*;
fn test_conditions(position: Vec3<i32>, temperature: f32, humidity: f32) {
fn test_conditions(position: Vec3<i32>, temperature: f32) {
print!("{} T{:.1} ", position, temperature);
let mut pseudorandom = ChaCha8Rng::from_seed(seed_from_pos(position));
if true {
let timing = create_timing(&mut pseudorandom);
let climate = create_climate(temperature, humidity);
let climate = create_climate(temperature);
print!(
"B{:.1}+{:.1} D{:.1}-{:.1} C{:.0} S{:.0} ",
timing.breakfast / 3600.0,
@ -187,10 +183,10 @@ mod tests {
print!(" {}:", i);
for j in 0..6 {
let time_of_day = 60.0 * 60.0 * (i as f32) + 60.0 * 10.0 * (j as f32);
let res = smoke_at_time(position, temperature, humidity, time_of_day);
let res = smoke_at_time(position, temperature, time_of_day);
print!("{:.0}{} ", res.0, if res.1 { "^" } else { "" },);
assert!(res.0>=0.0);
assert!(res.0<=SMOKE_DINNER_STRENGTH);
assert!(res.0 >= 0.0);
assert!(res.0 <= SMOKE_DINNER_STRENGTH);
}
}
println!();
@ -198,10 +194,10 @@ mod tests {
#[test]
fn test_smoke() {
test_conditions(Vec3::new(25_i32, 11, 33), -1.0, 0.5);
test_conditions(Vec3::new(22_i32, 11, 33), -0.5, 0.5);
test_conditions(Vec3::new(27_i32, 11, 33), 0.0, 0.5);
test_conditions(Vec3::new(24_i32, 11, 33), 0.5, 0.5);
test_conditions(Vec3::new(26_i32, 11, 33), 1.0, 0.5);
test_conditions(Vec3::new(25_i32, 11, 33), -1.0);
test_conditions(Vec3::new(22_i32, 11, 33), -0.5);
test_conditions(Vec3::new(27_i32, 11, 33), 0.0);
test_conditions(Vec3::new(24_i32, 11, 33), 0.5);
test_conditions(Vec3::new(26_i32, 11, 33), 1.0);
}
}