send WindRequest from client and receive WindUpdate

This commit is contained in:
Oresavna
2021-05-12 10:55:39 +02:00
committed by Ludvig Böklin
parent c885aa3607
commit 63f2105c84
3 changed files with 19 additions and 13 deletions

View File

@ -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(())

View File

@ -22,9 +22,9 @@ impl<'a> System<'a> for Sys {
fn run(_job: &mut Job<Self>, (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,

View File

@ -13,6 +13,11 @@ use common::{
//use common_state::State;
pub const DEFAULT_POS: Vec3<usize> = Vec3 { x: 0, y: 0, z: 0 };
pub const GRID_SIZE: Vec3<usize> = 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<Vec3<usize>> {
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
}