diff --git a/client/src/lib.rs b/client/src/lib.rs index 04672cd8b7..5ad6194e42 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1612,6 +1612,8 @@ impl Client { let now = Instant::now(); self.pending_chunks .retain(|_, created| now.duration_since(*created) < Duration::from_secs(3)); + + self.send_msg_err(ClientGeneral::WindRequest(pos))?; } // Send a ping to the server once every second @@ -1981,6 +1983,9 @@ impl Client { rich.economy = Some(economy); } }, + ServerGeneral::WindUpdate(vel) => { + println!("Windupdate {}", vel); + }, _ => unreachable!("Not a in_game message"), } Ok(()) diff --git a/server/src/sys/windsim.rs b/server/src/sys/windsim.rs index 9c45e5e9aa..497c0510fe 100644 --- a/server/src/sys/windsim.rs +++ b/server/src/sys/windsim.rs @@ -22,9 +22,9 @@ impl<'a> System<'a> for Sys { fn run(_job: &mut Job, (dt, mut windsim): Self::SystemData) { let wind_sources: Vec<(Pos, Vel)> = vec![( Pos(Vec3 { - x: 100.0, - y: 100.0, - z: 1.0, + x: 9999.0, + y: 9999.0, + z: 200.0, }), Vel(Vec3 { x: 100.0, diff --git a/server/src/windsim/mod.rs b/server/src/windsim/mod.rs index 96eec7d886..e60a58de07 100644 --- a/server/src/windsim/mod.rs +++ b/server/src/windsim/mod.rs @@ -13,6 +13,11 @@ use common::{ //use common_state::State; pub const DEFAULT_POS: Vec3 = Vec3 { x: 0, y: 0, z: 0 }; +pub const GRID_SIZE: Vec3 = Vec3 { + x: X_SIZE, + y: Y_SIZE, + z: Z_SIZE, +}; #[derive(Default)] pub struct WindSim { @@ -31,17 +36,13 @@ impl WindSim { /// Converts world positions, to 3D grid positions. /// Returns None if out of bounds, for example negative positions. pub fn world_to_grid(&self, pos: Pos) -> Option> { - if pos + let p = |pi, ci, gi| pi >= 0.0 && ci <= gi; + + let cell_pos = pos .0 - .map2(self.blocks_per_cell, |pi, si| { - pi >= 0.0 && pi <= (pi / si as f32) - }) - .reduce_and() - { - Some( - pos.0 - .map2(self.blocks_per_cell, |pi, si| pi as usize / si as usize), - ) + .map2(self.blocks_per_cell, |pi, si| pi as usize / si as usize); + if pos.0.map3(cell_pos, GRID_SIZE, p).reduce_and() { + Some(cell_pos) } else { None }