Interpolate fluid velocity updates to entities

This commit is contained in:
Ludvig Böklin
2021-06-03 14:02:34 +02:00
parent bd76bf823a
commit 3caea942e5
2 changed files with 11 additions and 11 deletions

View File

@ -1,5 +1,5 @@
#![allow(dead_code)]
use crate::windsim::WindSim;
use crate::windsim::{WindSim, TPS};
use common::{
comp::{Fluid, PhysicsState, Pos, Vel},
resources::DeltaTime,
@ -53,15 +53,16 @@ impl<'a> System<'a> for Sys {
windsim.tick(wind_sources, &dt);
for (pos, physics_state) in (&positions, &mut physics_states).join() {
physics_state.in_fluid = physics_state
.in_fluid
.filter(|fluid| !matches!(fluid, Fluid::Air { .. }))
.or_else(|| {
Some(Fluid::Air {
elevation: pos.0.z,
vel: Vel(windsim.get_velocity(*pos)),
})
if let Fluid::Air { vel, elevation } = physics_state.in_fluid.unwrap_or_default() {
physics_state.in_fluid = Some(Fluid::Air {
vel: Vel(Lerp::lerp(
vel.0,
windsim.get_velocity(*pos),
inline_tweak::tweak!(0.5) / TPS as f32,
)),
elevation,
});
}
}
}
}

View File

@ -10,7 +10,6 @@ use common::{
comp::{Pos, Vel},
resources::DeltaTime,
};
//use common_state::State;
pub const DEFAULT_POS: Vec3<usize> = Vec3 { x: 0, y: 0, z: 0 };
pub const GRID_SIZE: Vec3<usize> = Vec3 {
@ -18,7 +17,7 @@ pub const GRID_SIZE: Vec3<usize> = Vec3 {
y: Y_SIZE,
z: Z_SIZE,
};
const TPS: u32 = 5;
pub const TPS: u32 = 5;
#[derive(Default)]
pub struct WindSim {