diff --git a/client/src/lib.rs b/client/src/lib.rs index 1603618a92..7b6f85e3c3 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -88,6 +88,9 @@ pub struct Client { last_ping_delta: f64, ping_deltas: VecDeque, + chunk_total: usize, + other_total: usize, + tick: u64, state: State, entity: EcsEntity, @@ -128,7 +131,8 @@ impl Client { // Wait for initial sync let (state, entity, server_info, world_map, recipe_book) = block_on(async { loop { - match stream.recv().await? { + let mut wire_size: usize = 0; + match stream.recv(&mut wire_size).await? { ServerMsg::InitialSync { entity_package, server_info, @@ -168,13 +172,18 @@ impl Client { let world_map = Arc::new( image::DynamicImage::ImageRgba8({ // Should not fail if the dimensions are correct. - let world_map = - image::ImageBuffer::from_raw(map_size.x, map_size.y, world_map_raw); - world_map.ok_or_else(|| Error::Other("Server sent a bad world map image".into()))? + let world_map = image::ImageBuffer::from_raw( + map_size.x, + 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 - // positive x axis to positive y axis is counterclockwise around the z axis. - .flipv(), + // Flip the image, since Voxygen uses an orientation where rotation from + // positive x axis to positive y axis is counterclockwise around the z axis. + .flipv(), ); debug!("Done preparing image..."); @@ -222,6 +231,9 @@ impl Client { last_ping_delta: 0.0, ping_deltas: VecDeque::new(), + chunk_total: 0, + other_total: 0, + tick: 0, state, entity, @@ -264,7 +276,8 @@ impl Client { block_on(async { 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(( RequestStateError::RegisterDenied(err), state, @@ -834,7 +847,9 @@ impl Client { cnt: &mut u64, ) -> Result<(), Error> { 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; match msg { ServerMsg::TooManyPlayers => { @@ -1000,6 +1015,12 @@ impl Client { frontend_events.push(Event::InventoryUpdated(event)); }, 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 { self.state.insert_chunk(key, *chunk); } diff --git a/network/src/api.rs b/network/src/api.rs index 33ce2de6ad..01f2d7aeae 100644 --- a/network/src/api.rs +++ b/network/src/api.rs @@ -837,8 +837,11 @@ impl Stream { /// # } /// ``` #[inline] - pub async fn recv(&mut self) -> Result { - Ok(message::deserialize(self.recv_raw().await?)?) + pub async fn recv( + &mut self, + wire_size: &mut usize, + ) -> Result { + Ok(message::deserialize(self.recv_raw().await?, wire_size)?) } /// the equivalent like [`send_raw`] but for [`recv`], no [`bincode`] is diff --git a/network/src/message.rs b/network/src/message.rs index 03626f22d3..73a82dcb65 100644 --- a/network/src/message.rs +++ b/network/src/message.rs @@ -43,12 +43,16 @@ pub(crate) fn serialize(message: &M) -> MessageBuffer { //pub(crate) fn deserialize(buffer: MessageBuffer) -> // std::Result> { -pub(crate) fn deserialize(buffer: MessageBuffer) -> bincode::Result { +pub(crate) fn deserialize( + buffer: MessageBuffer, + wire_size: &mut usize, +) -> bincode::Result { let span = lz4_compress::decompress(&buffer.data) .expect("lz4 decompression failed, failed to deserialze"); //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 // logic is wrong. E.g. You expect a String, but just get a u8. + *wire_size = buffer.data.len(); bincode::deserialize(span.as_slice()) } diff --git a/server/src/client.rs b/server/src/client.rs index 95e6d96b91..6876c44799 100644 --- a/server/src/client.rs +++ b/server/src/client.rs @@ -36,7 +36,8 @@ impl Client { pub async fn recv(&mut self) -> Result { 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), Err(e) => { debug!(?e, "got a network error with client while recv");