diff --git a/server/src/lib.rs b/server/src/lib.rs index 927edf7572..8d140a980d 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1339,7 +1339,10 @@ impl Server { let chunk_tx = self.chunk_tx.clone(); let world = self.world.clone(); self.thread_pool.execute(move || { - let _ = chunk_tx.send((key, world.generate_chunk(key, &cancel).map_err(|_| entity))); + let payload = world + .generate_chunk(key, || cancel.load(Ordering::Relaxed)) + .map_err(|_| entity); + let _ = chunk_tx.send((key, payload)); }); } diff --git a/world/src/lib.rs b/world/src/lib.rs index 65d929d9e1..a1a6ba4aa5 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -28,10 +28,7 @@ use common::{ vol::{ReadVol, RectVolSize, Vox, WriteVol}, }; use rand::Rng; -use std::{ - sync::atomic::{AtomicBool, Ordering}, - time::Duration, -}; +use std::time::Duration; use vek::*; #[derive(Debug)] @@ -71,7 +68,7 @@ impl World { pub fn generate_chunk( &self, chunk_pos: Vec2, - flag: &AtomicBool, + mut should_continue: impl FnMut() -> bool, ) -> Result<(TerrainChunk, ChunkSupplement), ()> { let air = Block::empty(); let stone = Block::new(BlockKind::Dense, Rgb::new(200, 220, 255)); @@ -108,7 +105,7 @@ 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) { + if should_continue() { return Err(()); }; let wpos2d = Vec2::new(x, y)