mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add WindUpdate and WindRequest messages
This commit is contained in:
parent
b971e46753
commit
c885aa3607
@ -802,6 +802,7 @@ impl Client {
|
|||||||
| ClientGeneral::RequestSiteInfo(_)
|
| ClientGeneral::RequestSiteInfo(_)
|
||||||
| ClientGeneral::UnlockSkillGroup(_)
|
| ClientGeneral::UnlockSkillGroup(_)
|
||||||
| ClientGeneral::RequestPlayerPhysics { .. }
|
| ClientGeneral::RequestPlayerPhysics { .. }
|
||||||
|
| ClientGeneral::WindRequest(_)
|
||||||
| ClientGeneral::RequestLossyTerrainCompression { .. } => {
|
| ClientGeneral::RequestLossyTerrainCompression { .. } => {
|
||||||
&mut self.in_game_stream
|
&mut self.in_game_stream
|
||||||
},
|
},
|
||||||
|
@ -88,6 +88,7 @@ pub enum ClientGeneral {
|
|||||||
RequestLossyTerrainCompression {
|
RequestLossyTerrainCompression {
|
||||||
lossy_terrain_compression: bool,
|
lossy_terrain_compression: bool,
|
||||||
},
|
},
|
||||||
|
WindRequest(comp::Pos),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientMsg {
|
impl ClientMsg {
|
||||||
@ -126,9 +127,11 @@ impl ClientMsg {
|
|||||||
| ClientGeneral::RequestSiteInfo(_)
|
| ClientGeneral::RequestSiteInfo(_)
|
||||||
| ClientGeneral::UnlockSkillGroup(_)
|
| ClientGeneral::UnlockSkillGroup(_)
|
||||||
| ClientGeneral::RequestPlayerPhysics { .. }
|
| ClientGeneral::RequestPlayerPhysics { .. }
|
||||||
|
| ClientGeneral::WindRequest(_)
|
||||||
| ClientGeneral::RequestLossyTerrainCompression { .. } => {
|
| ClientGeneral::RequestLossyTerrainCompression { .. } => {
|
||||||
c_type == ClientType::Game && presence.is_some()
|
c_type == ClientType::Game && presence.is_some()
|
||||||
},
|
},
|
||||||
|
|
||||||
//Always possible
|
//Always possible
|
||||||
ClientGeneral::ChatMsg(_)
|
ClientGeneral::ChatMsg(_)
|
||||||
| ClientGeneral::Command(_, _)
|
| ClientGeneral::Command(_, _)
|
||||||
|
@ -160,6 +160,8 @@ pub enum ServerGeneral {
|
|||||||
chunk: Result<SerializedTerrainChunk, ()>,
|
chunk: Result<SerializedTerrainChunk, ()>,
|
||||||
},
|
},
|
||||||
TerrainBlockUpdates(CompressedData<HashMap<Vec3<i32>, Block>>),
|
TerrainBlockUpdates(CompressedData<HashMap<Vec3<i32>, Block>>),
|
||||||
|
// Windupdates from the WindGrid on server
|
||||||
|
WindUpdate(Vec3<f32>),
|
||||||
// Always possible
|
// Always possible
|
||||||
PlayerListUpdate(PlayerListUpdate),
|
PlayerListUpdate(PlayerListUpdate),
|
||||||
/// A message to go into the client chat box. The client is responsible for
|
/// A message to go into the client chat box. The client is responsible for
|
||||||
@ -282,6 +284,7 @@ impl ServerMsg {
|
|||||||
| ServerGeneral::InventoryUpdate(_, _)
|
| ServerGeneral::InventoryUpdate(_, _)
|
||||||
| ServerGeneral::TerrainChunkUpdate { .. }
|
| ServerGeneral::TerrainChunkUpdate { .. }
|
||||||
| ServerGeneral::TerrainBlockUpdates(_)
|
| ServerGeneral::TerrainBlockUpdates(_)
|
||||||
|
| ServerGeneral::WindUpdate(_)
|
||||||
| ServerGeneral::SetViewDistance(_)
|
| ServerGeneral::SetViewDistance(_)
|
||||||
| ServerGeneral::Outcomes(_)
|
| ServerGeneral::Outcomes(_)
|
||||||
| ServerGeneral::Knockback(_)
|
| ServerGeneral::Knockback(_)
|
||||||
|
@ -109,6 +109,7 @@ impl Client {
|
|||||||
| ServerGeneral::Outcomes(_)
|
| ServerGeneral::Outcomes(_)
|
||||||
| ServerGeneral::Knockback(_)
|
| ServerGeneral::Knockback(_)
|
||||||
| ServerGeneral::UpdatePendingTrade(_, _, _)
|
| ServerGeneral::UpdatePendingTrade(_, _, _)
|
||||||
|
| ServerGeneral::WindUpdate(_)
|
||||||
| ServerGeneral::FinishedTrade(_) => {
|
| ServerGeneral::FinishedTrade(_) => {
|
||||||
self.in_game_stream.lock().unwrap().send(g)
|
self.in_game_stream.lock().unwrap().send(g)
|
||||||
},
|
},
|
||||||
@ -180,6 +181,7 @@ impl Client {
|
|||||||
| ServerGeneral::Knockback(_)
|
| ServerGeneral::Knockback(_)
|
||||||
| ServerGeneral::SiteEconomy(_)
|
| ServerGeneral::SiteEconomy(_)
|
||||||
| ServerGeneral::UpdatePendingTrade(_, _, _)
|
| ServerGeneral::UpdatePendingTrade(_, _, _)
|
||||||
|
| ServerGeneral::WindUpdate(_)
|
||||||
| ServerGeneral::FinishedTrade(_) => {
|
| ServerGeneral::FinishedTrade(_) => {
|
||||||
PreparedMsg::new(2, &g, &self.in_game_stream_params)
|
PreparedMsg::new(2, &g, &self.in_game_stream_params)
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{client::Client, presence::Presence, Settings};
|
use crate::{client::Client, presence::Presence, windsim::WindSim, Settings};
|
||||||
use common::{
|
use common::{
|
||||||
comp::{
|
comp::{
|
||||||
Admin, CanBuild, ControlEvent, Controller, ForceUpdate, Health, Ori, Player, Pos, SkillSet,
|
Admin, CanBuild, ControlEvent, Controller, ForceUpdate, Health, Ori, Player, Pos, SkillSet,
|
||||||
@ -38,6 +38,7 @@ impl Sys {
|
|||||||
player_physics_settings: &mut Write<'_, PlayerPhysicsSettings>,
|
player_physics_settings: &mut Write<'_, PlayerPhysicsSettings>,
|
||||||
maybe_player: &Option<&Player>,
|
maybe_player: &Option<&Player>,
|
||||||
maybe_admin: &Option<&Admin>,
|
maybe_admin: &Option<&Admin>,
|
||||||
|
wind_sim: &Read<'_, WindSim>,
|
||||||
msg: ClientGeneral,
|
msg: ClientGeneral,
|
||||||
) -> Result<(), crate::error::Error> {
|
) -> Result<(), crate::error::Error> {
|
||||||
let presence = match maybe_presence {
|
let presence = match maybe_presence {
|
||||||
@ -258,6 +259,9 @@ impl Sys {
|
|||||||
} => {
|
} => {
|
||||||
presence.lossy_terrain_compression = lossy_terrain_compression;
|
presence.lossy_terrain_compression = lossy_terrain_compression;
|
||||||
},
|
},
|
||||||
|
ClientGeneral::WindRequest(pos) => {
|
||||||
|
client.send(ServerGeneral::WindUpdate(wind_sim.get_velocity(pos)))?;
|
||||||
|
},
|
||||||
_ => tracing::error!("not a client_in_game msg"),
|
_ => tracing::error!("not a client_in_game msg"),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -289,6 +293,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
Write<'a, PlayerPhysicsSettings>,
|
Write<'a, PlayerPhysicsSettings>,
|
||||||
ReadStorage<'a, Player>,
|
ReadStorage<'a, Player>,
|
||||||
ReadStorage<'a, Admin>,
|
ReadStorage<'a, Admin>,
|
||||||
|
Read<'a, WindSim>,
|
||||||
);
|
);
|
||||||
|
|
||||||
const NAME: &'static str = "msg::in_game";
|
const NAME: &'static str = "msg::in_game";
|
||||||
@ -317,6 +322,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
mut player_physics_settings,
|
mut player_physics_settings,
|
||||||
players,
|
players,
|
||||||
admins,
|
admins,
|
||||||
|
wind_sim,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
let mut server_emitter = server_event_bus.emitter();
|
let mut server_emitter = server_event_bus.emitter();
|
||||||
@ -351,6 +357,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
&mut player_physics_settings,
|
&mut player_physics_settings,
|
||||||
&player,
|
&player,
|
||||||
&maybe_admin,
|
&maybe_admin,
|
||||||
|
&wind_sim,
|
||||||
msg,
|
msg,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use super::types::*;
|
use super::wind_grid::*;
|
||||||
/// Macro for indexing into a 1D array using 3D coordinates.
|
/// Macro for indexing into a 1D array using 3D coordinates.
|
||||||
macro_rules! IX {
|
macro_rules! IX {
|
||||||
( $x: expr, $y: expr, $z: expr ) => {{ $x as usize + (X_SIZE + 2) * ($y as usize + (Y_SIZE + 2) * $z as usize) }};
|
( $x: expr, $y: expr, $z: expr ) => {{ $x as usize + (X_SIZE + 2) * ($y as usize + (Y_SIZE + 2) * $z as usize) }};
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
pub mod fluid;
|
pub mod fluid;
|
||||||
mod types;
|
mod wind_grid;
|
||||||
use common::{terrain::TerrainChunkSize, vol::RectVolSize};
|
use common::{terrain::TerrainChunkSize, vol::RectVolSize};
|
||||||
pub use fluid::step_fluid;
|
pub use fluid::step_fluid;
|
||||||
use types::{WindGrid, X_SIZE, Y_SIZE, Z_SIZE};
|
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
use wind_grid::{WindGrid, X_SIZE, Y_SIZE, Z_SIZE};
|
||||||
|
|
||||||
use common::{
|
use common::{
|
||||||
comp::{Pos, Vel},
|
comp::{Pos, Vel},
|
||||||
@ -12,6 +12,8 @@ use common::{
|
|||||||
};
|
};
|
||||||
//use common_state::State;
|
//use common_state::State;
|
||||||
|
|
||||||
|
pub const DEFAULT_POS: Vec3<usize> = Vec3 { x: 0, y: 0, z: 0 };
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct WindSim {
|
pub struct WindSim {
|
||||||
grid: WindGrid,
|
grid: WindGrid,
|
||||||
@ -45,9 +47,17 @@ impl WindSim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes a world position and returns a world velocity
|
||||||
|
pub fn get_velocity(&self, pos: Pos) -> Vec3<f32> {
|
||||||
|
let cell_pos = self.world_to_grid(pos).unwrap_or(DEFAULT_POS);
|
||||||
|
let cell_vel = self.grid.get_velocity(cell_pos);
|
||||||
|
cell_vel.map2(self.blocks_per_cell, |vi, si| vi * si as f32)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abstraction for running the simulation
|
||||||
pub fn tick(&mut self, sources: Vec<(Pos, Vel)>, dt: &DeltaTime) {
|
pub fn tick(&mut self, sources: Vec<(Pos, Vel)>, dt: &DeltaTime) {
|
||||||
for (pos, vel) in sources {
|
for (pos, vel) in sources {
|
||||||
let cell_pos = self.world_to_grid(pos).unwrap_or(Vec3{x:0, y:0, z:0});
|
let cell_pos = self.world_to_grid(pos).unwrap_or(DEFAULT_POS);
|
||||||
let cell_vel = vel.0.map2(self.blocks_per_cell, |vi, si| vi / si as f32);
|
let cell_vel = vel.0.map2(self.blocks_per_cell, |vi, si| vi / si as f32);
|
||||||
self.grid.add_velocity_source(cell_pos, cell_vel)
|
self.grid.add_velocity_source(cell_pos, cell_vel)
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ impl WindGrid {
|
|||||||
x + (X_SIZE + 2) * (y + (Y_SIZE + 2) * z)
|
x + (X_SIZE + 2) * (y + (Y_SIZE + 2) * z)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes 3D grid position (not a world position)
|
// Takes 3D grid position (not a world position) returns grid velocity
|
||||||
pub fn get_velocity(&self, pos: Vec3<usize>) -> Vec3<f32> {
|
pub fn get_velocity(&self, pos: Vec3<usize>) -> Vec3<f32> {
|
||||||
let index = Self::get_index(pos.x, pos.y, pos.z);
|
let index = Self::get_index(pos.x, pos.y, pos.z);
|
||||||
let x = self.x_vel[index] as f32;
|
let x = self.x_vel[index] as f32;
|
Loading…
Reference in New Issue
Block a user