mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Basic printing
This commit is contained in:
parent
24f968d813
commit
a9b03bfd26
@ -88,6 +88,9 @@ pub struct Client {
|
|||||||
last_ping_delta: f64,
|
last_ping_delta: f64,
|
||||||
ping_deltas: VecDeque<f64>,
|
ping_deltas: VecDeque<f64>,
|
||||||
|
|
||||||
|
chunk_total: usize,
|
||||||
|
other_total: usize,
|
||||||
|
|
||||||
tick: u64,
|
tick: u64,
|
||||||
state: State,
|
state: State,
|
||||||
entity: EcsEntity,
|
entity: EcsEntity,
|
||||||
@ -128,7 +131,8 @@ impl Client {
|
|||||||
// Wait for initial sync
|
// Wait for initial sync
|
||||||
let (state, entity, server_info, world_map, recipe_book) = block_on(async {
|
let (state, entity, server_info, world_map, recipe_book) = block_on(async {
|
||||||
loop {
|
loop {
|
||||||
match stream.recv().await? {
|
let mut wire_size: usize = 0;
|
||||||
|
match stream.recv(&mut wire_size).await? {
|
||||||
ServerMsg::InitialSync {
|
ServerMsg::InitialSync {
|
||||||
entity_package,
|
entity_package,
|
||||||
server_info,
|
server_info,
|
||||||
@ -168,9 +172,14 @@ impl Client {
|
|||||||
let world_map = Arc::new(
|
let world_map = Arc::new(
|
||||||
image::DynamicImage::ImageRgba8({
|
image::DynamicImage::ImageRgba8({
|
||||||
// Should not fail if the dimensions are correct.
|
// Should not fail if the dimensions are correct.
|
||||||
let world_map =
|
let world_map = image::ImageBuffer::from_raw(
|
||||||
image::ImageBuffer::from_raw(map_size.x, map_size.y, world_map_raw);
|
map_size.x,
|
||||||
world_map.ok_or_else(|| Error::Other("Server sent a bad world map image".into()))?
|
map_size.y,
|
||||||
|
world_map_raw,
|
||||||
|
);
|
||||||
|
world_map.ok_or_else(|| {
|
||||||
|
Error::Other("Server sent a bad world map image".into())
|
||||||
|
})?
|
||||||
})
|
})
|
||||||
// Flip the image, since Voxygen uses an orientation where rotation from
|
// Flip the image, since Voxygen uses an orientation where rotation from
|
||||||
// positive x axis to positive y axis is counterclockwise around the z axis.
|
// positive x axis to positive y axis is counterclockwise around the z axis.
|
||||||
@ -222,6 +231,9 @@ impl Client {
|
|||||||
last_ping_delta: 0.0,
|
last_ping_delta: 0.0,
|
||||||
ping_deltas: VecDeque::new(),
|
ping_deltas: VecDeque::new(),
|
||||||
|
|
||||||
|
chunk_total: 0,
|
||||||
|
other_total: 0,
|
||||||
|
|
||||||
tick: 0,
|
tick: 0,
|
||||||
state,
|
state,
|
||||||
entity,
|
entity,
|
||||||
@ -264,7 +276,8 @@ impl Client {
|
|||||||
|
|
||||||
block_on(async {
|
block_on(async {
|
||||||
loop {
|
loop {
|
||||||
match self.singleton_stream.recv().await? {
|
let mut wire_size: usize = 0;
|
||||||
|
match self.singleton_stream.recv(&mut wire_size).await? {
|
||||||
ServerMsg::StateAnswer(Err((
|
ServerMsg::StateAnswer(Err((
|
||||||
RequestStateError::RegisterDenied(err),
|
RequestStateError::RegisterDenied(err),
|
||||||
state,
|
state,
|
||||||
@ -834,7 +847,9 @@ impl Client {
|
|||||||
cnt: &mut u64,
|
cnt: &mut u64,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
loop {
|
loop {
|
||||||
let msg = self.singleton_stream.recv().await?;
|
let mut wire_size: usize = 0;
|
||||||
|
let msg = self.singleton_stream.recv(&mut wire_size).await?;
|
||||||
|
self.other_total += wire_size;
|
||||||
*cnt += 1;
|
*cnt += 1;
|
||||||
match msg {
|
match msg {
|
||||||
ServerMsg::TooManyPlayers => {
|
ServerMsg::TooManyPlayers => {
|
||||||
@ -1000,6 +1015,12 @@ impl Client {
|
|||||||
frontend_events.push(Event::InventoryUpdated(event));
|
frontend_events.push(Event::InventoryUpdated(event));
|
||||||
},
|
},
|
||||||
ServerMsg::TerrainChunkUpdate { key, chunk } => {
|
ServerMsg::TerrainChunkUpdate { key, chunk } => {
|
||||||
|
self.other_total -= wire_size;
|
||||||
|
self.chunk_total += wire_size;
|
||||||
|
println!(
|
||||||
|
"Terrain total: {}\nOther total: {}",
|
||||||
|
self.chunk_total, self.other_total
|
||||||
|
);
|
||||||
if let Ok(chunk) = chunk {
|
if let Ok(chunk) = chunk {
|
||||||
self.state.insert_chunk(key, *chunk);
|
self.state.insert_chunk(key, *chunk);
|
||||||
}
|
}
|
||||||
|
@ -837,8 +837,11 @@ impl Stream {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn recv<M: DeserializeOwned>(&mut self) -> Result<M, StreamError> {
|
pub async fn recv<M: DeserializeOwned>(
|
||||||
Ok(message::deserialize(self.recv_raw().await?)?)
|
&mut self,
|
||||||
|
wire_size: &mut usize,
|
||||||
|
) -> Result<M, StreamError> {
|
||||||
|
Ok(message::deserialize(self.recv_raw().await?, wire_size)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// the equivalent like [`send_raw`] but for [`recv`], no [`bincode`] is
|
/// the equivalent like [`send_raw`] but for [`recv`], no [`bincode`] is
|
||||||
|
@ -43,12 +43,16 @@ pub(crate) fn serialize<M: Serialize>(message: &M) -> MessageBuffer {
|
|||||||
|
|
||||||
//pub(crate) fn deserialize<M: DeserializeOwned>(buffer: MessageBuffer) ->
|
//pub(crate) fn deserialize<M: DeserializeOwned>(buffer: MessageBuffer) ->
|
||||||
// std::Result<M, std::Box<bincode::error::bincode::ErrorKind>> {
|
// std::Result<M, std::Box<bincode::error::bincode::ErrorKind>> {
|
||||||
pub(crate) fn deserialize<M: DeserializeOwned>(buffer: MessageBuffer) -> bincode::Result<M> {
|
pub(crate) fn deserialize<M: DeserializeOwned>(
|
||||||
|
buffer: MessageBuffer,
|
||||||
|
wire_size: &mut usize,
|
||||||
|
) -> bincode::Result<M> {
|
||||||
let span = lz4_compress::decompress(&buffer.data)
|
let span = lz4_compress::decompress(&buffer.data)
|
||||||
.expect("lz4 decompression failed, failed to deserialze");
|
.expect("lz4 decompression failed, failed to deserialze");
|
||||||
//this might fail if you choose the wrong type for M. in that case probably X
|
//this might fail if you choose the wrong type for M. in that case probably X
|
||||||
// got transfered while you assume Y. probably this means your application
|
// got transfered while you assume Y. probably this means your application
|
||||||
// logic is wrong. E.g. You expect a String, but just get a u8.
|
// logic is wrong. E.g. You expect a String, but just get a u8.
|
||||||
|
*wire_size = buffer.data.len();
|
||||||
bincode::deserialize(span.as_slice())
|
bincode::deserialize(span.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ impl Client {
|
|||||||
|
|
||||||
pub async fn recv(&mut self) -> Result<ClientMsg, Error> {
|
pub async fn recv(&mut self) -> Result<ClientMsg, Error> {
|
||||||
if !self.network_error.load(Ordering::Relaxed) {
|
if !self.network_error.load(Ordering::Relaxed) {
|
||||||
match self.singleton_stream.recv().await {
|
let mut wire_size: usize = 0;
|
||||||
|
match self.singleton_stream.recv(&mut wire_size).await {
|
||||||
Ok(r) => Ok(r),
|
Ok(r) => Ok(r),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!(?e, "got a network error with client while recv");
|
debug!(?e, "got a network error with client while recv");
|
||||||
|
Loading…
Reference in New Issue
Block a user