Extract chunk block generation out to it's own function
This commit is contained in:
		
							parent
							
								
									42fdf48660
								
							
						
					
					
						commit
						e1d621f573
					
				| 
						 | 
				
			
			@ -22,17 +22,26 @@ impl Chunk {
 | 
			
		|||
            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(pos, block_idx, noise_dims);
 | 
			
		||||
            self.blocks[block_idx].to_owned()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn gen_block(&mut self, block_pos: glam::UVec3, block_idx: usize, noise_dims: glam::UVec3) {
 | 
			
		||||
        let block = &mut self.blocks[block_idx];
 | 
			
		||||
 | 
			
		||||
        if block.is_empty() {
 | 
			
		||||
        // Extract relevant noise values from the chunk
 | 
			
		||||
        let mut noise_vals = Vec::new();
 | 
			
		||||
 | 
			
		||||
        let mut block_sign = 0.0;
 | 
			
		||||
        for z in 0..2 {
 | 
			
		||||
            for y in 0..2 {
 | 
			
		||||
                for x in 0..2 {
 | 
			
		||||
                        let noise_pos = glam::uvec3(x, y, z) + pos;
 | 
			
		||||
                    let noise_pos = glam::uvec3(x, y, z) + block_pos;
 | 
			
		||||
                    let noise_idx = math::to_1d_index(noise_pos, noise_dims);
 | 
			
		||||
                    let val = self.noise[noise_idx];
 | 
			
		||||
                    noise_vals.push(val);
 | 
			
		||||
| 
						 | 
				
			
			@ -70,9 +79,6 @@ impl Chunk {
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        block.to_owned()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Clone, Copy)]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue