mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
b1db5ef488
Rather than having a single Stream to handle ALL data, seperate into multiple streams: - Ping Stream, for seperate PINGS - Register Stream, only used till the client is registered, then no longer used! - General Stream, used for msg that can occur always - NotInGame Stream, used for everything NOT ingame, e.g. Character Screen - InGame Stream, used for all GAME data, players, terrain, entities, etc... This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet. This fixes also the ignoring messages problem we had, as we are not sending data to the register stream! This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
64 lines
2.1 KiB
Rust
64 lines
2.1 KiB
Rust
use super::SysTimer;
|
|
use crate::client::Client;
|
|
use common::{
|
|
comp::{Player, Pos},
|
|
msg::ServerInGameMsg,
|
|
span,
|
|
state::TerrainChanges,
|
|
terrain::TerrainGrid,
|
|
};
|
|
use specs::{Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage};
|
|
|
|
/// This systems sends new chunks to clients as well as changes to existing
|
|
/// chunks
|
|
pub struct Sys;
|
|
impl<'a> System<'a> for Sys {
|
|
#[allow(clippy::type_complexity)] // TODO: Pending review in #587
|
|
type SystemData = (
|
|
ReadExpect<'a, TerrainGrid>,
|
|
Read<'a, TerrainChanges>,
|
|
Write<'a, SysTimer<Self>>,
|
|
ReadStorage<'a, Pos>,
|
|
ReadStorage<'a, Player>,
|
|
WriteStorage<'a, Client>,
|
|
);
|
|
|
|
fn run(
|
|
&mut self,
|
|
(terrain, terrain_changes, mut timer, positions, players, mut clients): Self::SystemData,
|
|
) {
|
|
span!(_guard, "run", "terrain_sync::Sys::run");
|
|
timer.start();
|
|
|
|
// Sync changed chunks
|
|
'chunk: for chunk_key in &terrain_changes.modified_chunks {
|
|
for (player, pos, client) in (&players, &positions, &mut clients).join() {
|
|
if player
|
|
.view_distance
|
|
.map(|vd| super::terrain::chunk_in_vd(pos.0, *chunk_key, &terrain, vd))
|
|
.unwrap_or(false)
|
|
{
|
|
client.send_in_game(ServerInGameMsg::TerrainChunkUpdate {
|
|
key: *chunk_key,
|
|
chunk: Ok(Box::new(match terrain.get_key(*chunk_key) {
|
|
Some(chunk) => chunk.clone(),
|
|
None => break 'chunk,
|
|
})),
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
// TODO: Don't send all changed blocks to all clients
|
|
// Sync changed blocks
|
|
let msg = ServerInGameMsg::TerrainBlockUpdates(terrain_changes.modified_blocks.clone());
|
|
for (player, client) in (&players, &mut clients).join() {
|
|
if player.view_distance.is_some() {
|
|
client.send_in_game(msg.clone());
|
|
}
|
|
}
|
|
|
|
timer.end();
|
|
}
|
|
}
|