Slight refactor to Chunk get_block and gen_block
This commit is contained in:
parent
081ce7ec77
commit
7cdca0a406
|
@ -16,24 +16,24 @@ pub struct Chunk {
|
||||||
|
|
||||||
impl Chunk {
|
impl Chunk {
|
||||||
fn get_block(&mut self, block_pos: glam::UVec3, chunk_dims: glam::UVec3) -> Vec<Voxel> {
|
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!(
|
assert_eq!(
|
||||||
self.blocks.len(),
|
self.blocks.len(),
|
||||||
(chunk_dims.x * chunk_dims.y * chunk_dims.z) as usize
|
(chunk_dims.x * chunk_dims.y * chunk_dims.z) as usize
|
||||||
);
|
);
|
||||||
|
|
||||||
let block = &self.blocks[block_idx];
|
let block_idx = math::to_1d_index(block_pos, chunk_dims);
|
||||||
if !block.is_empty() {
|
let mut block = &self.blocks[block_idx];
|
||||||
block.to_owned()
|
if block.is_empty() {
|
||||||
} else {
|
self.gen_block(block_pos, block_idx, chunk_dims);
|
||||||
self.gen_block(block_pos, block_idx, noise_dims);
|
block = &self.blocks[block_idx]
|
||||||
self.blocks[block_idx].to_owned()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
block.to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_block(&mut self, block_pos: glam::UVec3, block_idx: usize, noise_dims: glam::UVec3) {
|
fn gen_block(&mut self, block_pos: glam::UVec3, block_idx: usize, chunk_dims: glam::UVec3) {
|
||||||
let block = &mut self.blocks[block_idx];
|
let block = &mut self.blocks[block_idx];
|
||||||
|
let noise_dims = chunk_dims + glam::uvec3(1, 1, 1);
|
||||||
|
|
||||||
// Extract relevant noise values from the chunk
|
// Extract relevant noise values from the chunk
|
||||||
let mut noise_vals = Vec::new();
|
let mut noise_vals = Vec::new();
|
||||||
|
|
Loading…
Reference in New Issue