Slight refactor to Chunk get_block and gen_block

This commit is contained in:
Jarrod Doyle 2023-07-28 11:50:13 +01:00
parent 081ce7ec77
commit 7cdca0a406
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 9 additions and 9 deletions

View File

@ -16,24 +16,24 @@ pub struct Chunk {
impl Chunk {
fn get_block(&mut self, block_pos: glam::UVec3, chunk_dims: glam::UVec3) -> Vec<Voxel> {
let noise_dims = chunk_dims + glam::uvec3(1, 1, 1);
let block_idx = math::to_1d_index(block_pos, chunk_dims);
assert_eq!(
self.blocks.len(),
(chunk_dims.x * chunk_dims.y * chunk_dims.z) as usize
);
let block = &self.blocks[block_idx];
if !block.is_empty() {
block.to_owned()
} else {
self.gen_block(block_pos, block_idx, noise_dims);
self.blocks[block_idx].to_owned()
}
let block_idx = math::to_1d_index(block_pos, chunk_dims);
let mut block = &self.blocks[block_idx];
if block.is_empty() {
self.gen_block(block_pos, block_idx, chunk_dims);
block = &self.blocks[block_idx]
}
fn gen_block(&mut self, block_pos: glam::UVec3, block_idx: usize, noise_dims: glam::UVec3) {
block.to_owned()
}
fn gen_block(&mut self, block_pos: glam::UVec3, block_idx: usize, chunk_dims: glam::UVec3) {
let block = &mut self.blocks[block_idx];
let noise_dims = chunk_dims + glam::uvec3(1, 1, 1);
// Extract relevant noise values from the chunk
let mut noise_vals = Vec::new();