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,
|
||||
ping_deltas: VecDeque<f64>,
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -837,8 +837,11 @@ impl Stream {
|
||||
/// # }
|
||||
/// ```
|
||||
#[inline]
|
||||
pub async fn recv<M: DeserializeOwned>(&mut self) -> Result<M, StreamError> {
|
||||
Ok(message::deserialize(self.recv_raw().await?)?)
|
||||
pub async fn recv<M: DeserializeOwned>(
|
||||
&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
|
||||
|
@ -43,12 +43,16 @@ pub(crate) fn serialize<M: Serialize>(message: &M) -> MessageBuffer {
|
||||
|
||||
//pub(crate) fn deserialize<M: DeserializeOwned>(buffer: MessageBuffer) ->
|
||||
// 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)
|
||||
.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())
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,8 @@ impl Client {
|
||||
|
||||
pub async fn recv(&mut self) -> Result<ClientMsg, Error> {
|
||||
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");
|
||||
|
Loading…
Reference in New Issue
Block a user