diff --git a/server/src/lib.rs b/server/src/lib.rs index fc289373b0..2b905e6f18 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -35,7 +35,10 @@ use specs::{join::Join, world::EntityBuilder as EcsEntityBuilder, Builder, Entit use std::{ i32, net::SocketAddr, - sync::{Arc, atomic::{AtomicBool, Ordering}}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, time::{Duration, Instant}, }; use uvth::{ThreadPool, ThreadPoolBuilder}; @@ -68,8 +71,14 @@ pub struct Server { clients: Clients, thread_pool: ThreadPool, - chunk_tx: channel::Sender<(Vec2, Result<(TerrainChunk, ChunkSupplement), EcsEntity>)>, - chunk_rx: channel::Receiver<(Vec2, Result<(TerrainChunk, ChunkSupplement), EcsEntity>)>, + chunk_tx: channel::Sender<( + Vec2, + Result<(TerrainChunk, ChunkSupplement), EcsEntity> + )>, + chunk_rx: channel::Receiver<( + Vec2, + Result<(TerrainChunk, ChunkSupplement), EcsEntity> + )>, pending_chunks: HashMap, Arc>, server_settings: ServerSettings, @@ -565,8 +574,10 @@ impl Server { // Remove chunks that are too far from players. let mut chunks_to_remove = Vec::new(); - self.state.terrain() - .iter().map(|(k, _)| k) + self.state + .terrain() + .iter() + .map(|(k, _)| k) .chain(self.pending_chunks.keys().cloned()) .for_each(|chunk_key| { let mut should_drop = true; @@ -1019,7 +1030,7 @@ impl Server { chunk: Ok(Box::new(chunk.clone())), }) } - None => requested_chunks.push((entity, key)) + None => requested_chunks.push((entity, key)), } } ClientState::Pending => {} @@ -1318,7 +1329,11 @@ impl Server { } pub fn generate_chunk(&mut self, entity: EcsEntity, key: Vec2) { - let v = if let Entry::Vacant(v) = self.pending_chunks.entry(key) { v } else { return; }; + let v = if let Entry::Vacant(v) = self.pending_chunks.entry(key) { + v + } else { + return; + }; let cancel = Arc::new(AtomicBool::new(false)); v.insert(Arc::clone(&cancel)); let chunk_tx = self.chunk_tx.clone(); diff --git a/world/src/lib.rs b/world/src/lib.rs index 6da38f578e..6ecac0b33c 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -68,8 +68,10 @@ impl World { BlockGen::new(self, ColumnGen::new(&self.sim)) } - pub fn generate_chunk(&self, chunk_pos: Vec2, - flag: &AtomicBool) -> Result<(TerrainChunk, ChunkSupplement), ()> { + pub fn generate_chunk( + &self, + chunk_pos: Vec2, + flag: &AtomicBool) -> Result<(TerrainChunk, ChunkSupplement), ()> { let air = Block::empty(); let stone = Block::new(BlockKind::Dense, Rgb::new(200, 220, 255)); let water = Block::new(BlockKind::Water, Rgb::new(60, 90, 190)); @@ -105,7 +107,9 @@ impl World { let mut chunk = TerrainChunk::new(base_z, stone, air, meta); for x in 0..TerrainChunkSize::RECT_SIZE.x as i32 { for y in 0..TerrainChunkSize::RECT_SIZE.y as i32 { - if flag.load(Ordering::Relaxed) { return Err(()) }; + if flag.load(Ordering::Relaxed) { + return Err(()) + }; let wpos2d = Vec2::new(x, y) + Vec2::from(chunk_pos) * TerrainChunkSize::RECT_SIZE.map(|e| e as i32);