From 6b8deab09456966391b66171978ebe7faceed6f5 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Fri, 27 Jan 2023 02:14:10 +0100 Subject: [PATCH] control --- src/world/tasks.rs | 5 ++++- src/world/worldgen.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/world/tasks.rs b/src/world/tasks.rs index 6570829..61a1c8d 100644 --- a/src/world/tasks.rs +++ b/src/world/tasks.rs @@ -1,6 +1,7 @@ use flume::{Sender, Receiver}; use glam::IVec3; use shipyard::Unique; +use rayon::{ThreadPool, ThreadPoolBuilder}; use super::{ chunk::BlockData, render::ChunkVertex, @@ -33,16 +34,18 @@ pub enum ChunkTaskResponse { #[derive(Unique)] pub struct ChunkTaskManager { channel: (Sender, Receiver), + pool: ThreadPool, } impl ChunkTaskManager { pub fn new() -> Self { Self { channel: flume::unbounded::(), //maybe put a bound or even bound(0)? + pool: ThreadPoolBuilder::new().num_threads(4).build().unwrap() } } pub fn spawn_task(&self, task: ChunkTask) { let sender = self.channel.0.clone(); - rayon::spawn(move || { + self.pool.spawn(move || { let _ = sender.send(match task { ChunkTask::GenerateMesh { position, data } => { let (vertices, indexes) = generate_mesh(data); diff --git a/src/world/worldgen.rs b/src/world/worldgen.rs index c40716e..deac50a 100644 --- a/src/world/worldgen.rs +++ b/src/world/worldgen.rs @@ -18,7 +18,7 @@ pub fn generate_world(chunk_position: IVec3, seed: u64) -> BlockData { for z in 0..CHUNK_SIZE { let position = ivec3(x as i32, y as i32, z as i32) + offset; let noise = noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32); - if noise > 0.8 { + if (0.7..0.8).contains(&noise) { blocks[x][y][z] = Block::Stone; } }