Implement clippy suggestions
This commit is contained in:
		
							parent
							
								
									a29b4979ef
								
							
						
					
					
						commit
						27b61c624d
					
				| 
						 | 
					@ -89,7 +89,7 @@ impl App {
 | 
				
			||||||
                } if window_id == self.window.id() => match event {
 | 
					                } if window_id == self.window.id() => match event {
 | 
				
			||||||
                    WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
 | 
					                    WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
 | 
				
			||||||
                    _ => {
 | 
					                    _ => {
 | 
				
			||||||
                        camera_controller.process_events(&event);
 | 
					                        camera_controller.process_events(event);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                Event::MainEventsCleared => {
 | 
					                Event::MainEventsCleared => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
/// Linear interpolation.
 | 
					/// Linear interpolation.
 | 
				
			||||||
#[inline]
 | 
					#[inline]
 | 
				
			||||||
pub fn lerp(a: f32, b: f32, w: f32) -> f32 {
 | 
					pub fn lerp(a: f32, b: f32, w: f32) -> f32 {
 | 
				
			||||||
    assert!(0.0 <= w && w <= 1.0);
 | 
					    assert!((0.0..=1.0).contains(&w));
 | 
				
			||||||
    a + (b - a) * w
 | 
					    a + (b - a) * w
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -89,7 +89,7 @@ impl<'a> BindGroupBuilder<'a> {
 | 
				
			||||||
            .device
 | 
					            .device
 | 
				
			||||||
            .create_bind_group(&wgpu::BindGroupDescriptor {
 | 
					            .create_bind_group(&wgpu::BindGroupDescriptor {
 | 
				
			||||||
                label: self.label,
 | 
					                label: self.label,
 | 
				
			||||||
                layout: &self.layout.unwrap(),
 | 
					                layout: self.layout.unwrap(),
 | 
				
			||||||
                entries: self.entries.as_slice(),
 | 
					                entries: self.entries.as_slice(),
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,14 +38,13 @@ pub struct BrickmapManager {
 | 
				
			||||||
// - Brickworld system
 | 
					// - Brickworld system
 | 
				
			||||||
impl BrickmapManager {
 | 
					impl BrickmapManager {
 | 
				
			||||||
    pub fn new(context: &render::Context) -> Self {
 | 
					    pub fn new(context: &render::Context) -> Self {
 | 
				
			||||||
        let mut state_uniform = WorldState::default();
 | 
					        let state_uniform = WorldState {
 | 
				
			||||||
        state_uniform.brickmap_cache_dims = [32, 32, 32];
 | 
					            brickmap_cache_dims: [32, 32, 32],
 | 
				
			||||||
 | 
					            ..Default::default()
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let mut brickmap_cache = Vec::<Brickmap>::with_capacity(usize::pow(32, 3));
 | 
					        let brickmap_cache = vec![Brickmap::default(); usize::pow(32, 3)];
 | 
				
			||||||
        brickmap_cache.resize(brickmap_cache.capacity(), Brickmap::default());
 | 
					        let brickgrid = vec![1u32; usize::pow(32, 3)];
 | 
				
			||||||
 | 
					 | 
				
			||||||
        let mut brickgrid = Vec::<u32>::with_capacity(usize::pow(32, 3));
 | 
					 | 
				
			||||||
        brickgrid.resize(brickgrid.capacity(), 1);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let device = &context.device;
 | 
					        let device = &context.device;
 | 
				
			||||||
        let state_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
 | 
					        let state_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
 | 
				
			||||||
| 
						 | 
					@ -67,9 +66,7 @@ impl BrickmapManager {
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let shading_table_allocator = ShadingTableAllocator::new(4, u32::pow(2, 24));
 | 
					        let shading_table_allocator = ShadingTableAllocator::new(4, u32::pow(2, 24));
 | 
				
			||||||
        let shading_table_element_count = shading_table_allocator.total_elements as usize;
 | 
					        let shading_table = vec![0u32; shading_table_allocator.total_elements as usize];
 | 
				
			||||||
        let mut shading_table = Vec::<u32>::with_capacity(shading_table_element_count);
 | 
					 | 
				
			||||||
        shading_table.resize(shading_table.capacity(), 0);
 | 
					 | 
				
			||||||
        let shading_table_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
 | 
					        let shading_table_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
 | 
				
			||||||
            label: None,
 | 
					            label: None,
 | 
				
			||||||
            contents: bytemuck::cast_slice(&shading_table),
 | 
					            contents: bytemuck::cast_slice(&shading_table),
 | 
				
			||||||
| 
						 | 
					@ -168,7 +165,7 @@ impl BrickmapManager {
 | 
				
			||||||
            assert_eq!(block.len(), 512);
 | 
					            assert_eq!(block.len(), 512);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Cull interior voxels
 | 
					            // Cull interior voxels
 | 
				
			||||||
            let mut bitmask_data = [0xFFFFFFFF as u32; 16];
 | 
					            let mut bitmask_data = [0xFFFFFFFF_u32; 16];
 | 
				
			||||||
            let mut albedo_data = Vec::<u32>::new();
 | 
					            let mut albedo_data = Vec::<u32>::new();
 | 
				
			||||||
            for z in 0..8 {
 | 
					            for z in 0..8 {
 | 
				
			||||||
                // Each z level contains two bitmask segments of voxels
 | 
					                // Each z level contains two bitmask segments of voxels
 | 
				
			||||||
| 
						 | 
					@ -185,17 +182,18 @@ impl BrickmapManager {
 | 
				
			||||||
                                // A voxel is on the surface if at least one of it's
 | 
					                                // A voxel is on the surface if at least one of it's
 | 
				
			||||||
                                // cardinal neighbours is non-solid. Also for simplicity
 | 
					                                // cardinal neighbours is non-solid. Also for simplicity
 | 
				
			||||||
                                // if it's on the edge of the chunk
 | 
					                                // if it's on the edge of the chunk
 | 
				
			||||||
                                let surface_voxel: bool;
 | 
					                                // TODO: Account for neighbours in other blocks
 | 
				
			||||||
                                if x == 0 || x == 7 || y == 0 || y == 7 || z == 0 || z == 7 {
 | 
					                                let surface_voxel =
 | 
				
			||||||
                                    surface_voxel = true;
 | 
					                                    if x == 0 || x == 7 || y == 0 || y == 7 || z == 0 || z == 7 {
 | 
				
			||||||
                                } else {
 | 
					                                        true
 | 
				
			||||||
                                    surface_voxel = !(block[idx + 1] == empty_voxel
 | 
					                                    } else {
 | 
				
			||||||
                                        && block[idx - 1] == empty_voxel
 | 
					                                        !(block[idx + 1] == empty_voxel
 | 
				
			||||||
                                        && block[idx + 8] == empty_voxel
 | 
					                                            && block[idx - 1] == empty_voxel
 | 
				
			||||||
                                        && block[idx - 8] == empty_voxel
 | 
					                                            && block[idx + 8] == empty_voxel
 | 
				
			||||||
                                        && block[idx + 64] == empty_voxel
 | 
					                                            && block[idx - 8] == empty_voxel
 | 
				
			||||||
                                        && block[idx - 64] == empty_voxel);
 | 
					                                            && block[idx + 64] == empty_voxel
 | 
				
			||||||
                                }
 | 
					                                            && block[idx - 64] == empty_voxel)
 | 
				
			||||||
 | 
					                                    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                // Set the appropriate bit in the z entry and add the
 | 
					                                // Set the appropriate bit in the z entry and add the
 | 
				
			||||||
                                // shading data
 | 
					                                // shading data
 | 
				
			||||||
| 
						 | 
					@ -211,7 +209,7 @@ impl BrickmapManager {
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                let offset = 2 * z as usize;
 | 
					                let offset = 2 * z;
 | 
				
			||||||
                bitmask_data[offset] = (entry & 0xFFFFFFFF).try_into().unwrap();
 | 
					                bitmask_data[offset] = (entry & 0xFFFFFFFF).try_into().unwrap();
 | 
				
			||||||
                bitmask_data[offset + 1] = ((entry >> 32) & 0xFFFFFFFF).try_into().unwrap();
 | 
					                bitmask_data[offset + 1] = ((entry >> 32) & 0xFFFFFFFF).try_into().unwrap();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -298,7 +296,7 @@ impl ShadingBucket {
 | 
				
			||||||
    fn contains_address(&self, address: u32) -> bool {
 | 
					    fn contains_address(&self, address: u32) -> bool {
 | 
				
			||||||
        let min = self.global_offset;
 | 
					        let min = self.global_offset;
 | 
				
			||||||
        let max = min + self.slot_count * self.slot_size;
 | 
					        let max = min + self.slot_count * self.slot_size;
 | 
				
			||||||
        return min <= address && address < max;
 | 
					        min <= address && address < max
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn try_alloc(&mut self) -> Option<u32> {
 | 
					    fn try_alloc(&mut self) -> Option<u32> {
 | 
				
			||||||
| 
						 | 
					@ -307,8 +305,7 @@ impl ShadingBucket {
 | 
				
			||||||
        self.used.push(bucket_index);
 | 
					        self.used.push(bucket_index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Convert the bucket index into a global address
 | 
					        // Convert the bucket index into a global address
 | 
				
			||||||
        let address = self.global_offset + bucket_index * self.slot_size;
 | 
					        Some(self.global_offset + bucket_index * self.slot_size)
 | 
				
			||||||
        return Some(address);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn try_dealloc(&mut self, address: u32) -> Result<(), &str> {
 | 
					    fn try_dealloc(&mut self, address: u32) -> Result<(), &str> {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ impl VoxelRenderer {
 | 
				
			||||||
                    | wgpu::TextureUsages::STORAGE_BINDING,
 | 
					                    | wgpu::TextureUsages::STORAGE_BINDING,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            .with_shader_visibility(wgpu::ShaderStages::FRAGMENT | wgpu::ShaderStages::COMPUTE)
 | 
					            .with_shader_visibility(wgpu::ShaderStages::FRAGMENT | wgpu::ShaderStages::COMPUTE)
 | 
				
			||||||
            .build(&context);
 | 
					            .build(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        log::info!("Creating render pipeline...");
 | 
					        log::info!("Creating render pipeline...");
 | 
				
			||||||
        let render_pipeline =
 | 
					        let render_pipeline =
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,7 +22,7 @@ impl Chunk {
 | 
				
			||||||
        assert_eq!(self.blocks.len(), 32768);
 | 
					        assert_eq!(self.blocks.len(), 32768);
 | 
				
			||||||
        let block = &mut self.blocks[block_idx];
 | 
					        let block = &mut self.blocks[block_idx];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if block.len() == 0 {
 | 
					        if block.is_empty() {
 | 
				
			||||||
            // 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