From 3caea942e5321003584072f7fe1dfa7a330f0876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20B=C3=B6klin?= Date: Thu, 3 Jun 2021 14:02:34 +0200 Subject: [PATCH] Interpolate fluid velocity updates to entities --- server/src/sys/windsim.rs | 19 ++++++++++--------- server/src/windsim/mod.rs | 3 +-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server/src/sys/windsim.rs b/server/src/sys/windsim.rs index dd44550260..b3e62178ee 100644 --- a/server/src/sys/windsim.rs +++ b/server/src/sys/windsim.rs @@ -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, }); + } } } } diff --git a/server/src/windsim/mod.rs b/server/src/windsim/mod.rs index c4d4a63006..74938ff9bd 100644 --- a/server/src/windsim/mod.rs +++ b/server/src/windsim/mod.rs @@ -10,7 +10,6 @@ use common::{ comp::{Pos, Vel}, resources::DeltaTime, }; -//use common_state::State; pub const DEFAULT_POS: Vec3 = Vec3 { x: 0, y: 0, z: 0 }; pub const GRID_SIZE: Vec3 = Vec3 { @@ -18,7 +17,7 @@ pub const GRID_SIZE: Vec3 = Vec3 { y: Y_SIZE, z: Z_SIZE, }; -const TPS: u32 = 5; +pub const TPS: u32 = 5; #[derive(Default)] pub struct WindSim {