mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Interpolate fluid velocity updates to entities
This commit is contained in:
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user