Addressing code review.

This commit is contained in:
Joshua Yanovski 2019-09-16 15:11:47 +02:00
parent 20f57cf7f3
commit 9ba64ca57f
2 changed files with 7 additions and 7 deletions

View File

@ -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));
});
}

View File

@ -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<i32>,
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)