From e4d6d96afc58e1dcf1944157d95a81f07e153df2 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 25 Apr 2019 20:25:22 +0100 Subject: [PATCH] Remove post debugging Former-commit-id: 4a82bf8b6178fb88d5a6ea93706fb4e97ac2256d --- client/src/lib.rs | 6 +++--- common/src/net/post2.rs | 3 --- server/src/lib.rs | 20 +++++++++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index c68abb8083..6efe76ab0b 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -194,9 +194,9 @@ impl Client { // Remove chunks that are too far from the player let mut chunks_to_remove = Vec::new(); - self.state.terrain().iter().for_each(|(k, _)| { - if (chunk_pos - k).map(|e| e.abs()).reduce_max() > 3 { - chunks_to_remove.push(k); + self.state.terrain().iter().for_each(|(key, _)| { + if (chunk_pos - key).map(|e| e.abs()).reduce_max() > 3 { + chunks_to_remove.push(key); } }); for key in chunks_to_remove { diff --git a/common/src/net/post2.rs b/common/src/net/post2.rs index b654784ecc..ea41ad4516 100644 --- a/common/src/net/post2.rs +++ b/common/src/net/post2.rs @@ -212,7 +212,6 @@ impl PostBox { // Try sending bytes through the TCP stream for _ in 0..100 { - //println!("HERE! Outgoing len: {}", outgoing_chunks.len()); match outgoing_chunks.pop_front() { Some(mut chunk) => match stream.write(&chunk) { Ok(n) => if n == chunk.len() {}, @@ -227,7 +226,6 @@ impl PostBox { }, // Worker error Err(e) => { - println!("SEND ERROR: {:?}", e); recv_tx.send(Err(e.into())).unwrap(); break 'work; }, @@ -265,7 +263,6 @@ impl PostBox { match bincode::deserialize(&incoming_buf[8..len + 8]) { Ok(msg) => recv_tx.send(Ok(msg)).unwrap(), Err(err) => { - println!("Invalid message: {:?}", err); recv_tx.send(Err(err.into())).unwrap() }, } diff --git a/server/src/lib.rs b/server/src/lib.rs index 3dbc36e0b9..99efa95d4f 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -194,13 +194,15 @@ impl Server { &self.state.ecs().read_storage::(), &self.state.ecs().read_storage::(), ).join() { - // TODO: Distance check - // if self.state.terrain().key_pos(key) + let chunk_pos = self.state.terrain().pos_key(pos.0.map(|e| e as i32)); + let dist = (chunk_pos - key).map(|e| e.abs()).reduce_max(); - self.clients.notify(entity, ServerMsg::TerrainChunkUpdate { - key, - chunk: Box::new(chunk.clone()), - }); + if dist < 4 { + self.clients.notify(entity, ServerMsg::TerrainChunkUpdate { + key, + chunk: Box::new(chunk.clone()), + }); + } } self.state.insert_chunk(key, chunk); @@ -209,7 +211,7 @@ impl Server { // Remove chunks that are too far from players let mut chunks_to_remove = Vec::new(); - self.state.terrain().iter().for_each(|(k, _)| { + self.state.terrain().iter().for_each(|(key, _)| { let mut min_dist = i32::MAX; // For each player with a position, calculate the distance @@ -218,12 +220,12 @@ impl Server { &self.state.ecs().read_storage::(), ).join() { let chunk_pos = self.state.terrain().pos_key(pos.0.map(|e| e as i32)); - let dist = (chunk_pos - k).map(|e| e.abs()).reduce_max(); + let dist = (chunk_pos - key).map(|e| e.abs()).reduce_max(); min_dist = min_dist.min(dist); } if min_dist > 3 { - chunks_to_remove.push(k); + chunks_to_remove.push(key); } }); for key in chunks_to_remove {