From 10f3950e8dc595f9c824b05b849be4488a915556 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 23 Mar 2024 10:25:42 +0000 Subject: [PATCH] Begin separating brickmap into brickworld module --- src/voxel/{ => brickworld}/brickmap.rs | 21 ++++++++++----------- src/voxel/brickworld/mod.rs | 3 +++ src/voxel/mod.rs | 2 +- src/voxel/voxel_renderer.rs | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-) rename src/voxel/{ => brickworld}/brickmap.rs (97%) create mode 100644 src/voxel/brickworld/mod.rs diff --git a/src/voxel/brickmap.rs b/src/voxel/brickworld/brickmap.rs similarity index 97% rename from src/voxel/brickmap.rs rename to src/voxel/brickworld/brickmap.rs index 51f51a5..3fcdce9 100644 --- a/src/voxel/brickmap.rs +++ b/src/voxel/brickworld/brickmap.rs @@ -1,6 +1,9 @@ use std::collections::HashSet; -use crate::{gfx, math}; +use crate::{ + gfx, math, + voxel::world::{Voxel, WorldManager}, +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] @@ -171,11 +174,7 @@ impl BrickmapManager { self.unpack_max_count } - pub fn process_feedback_buffer( - &mut self, - context: &gfx::Context, - world: &mut super::world::WorldManager, - ) { + pub fn process_feedback_buffer(&mut self, context: &gfx::Context, world: &mut WorldManager) { // Get request count let mut slice = self.feedback_result_buffer.slice(0..16); slice.map_async(wgpu::MapMode::Read, |_| {}); @@ -365,7 +364,7 @@ impl BrickmapManager { } fn cull_interior_voxels( - world: &mut super::world::WorldManager, + world: &mut WorldManager, grid_pos: glam::IVec3, ) -> ([u32; 16], Vec) { // This is the data we want to return @@ -399,11 +398,11 @@ impl BrickmapManager { for x in 0..8 { // Ignore non-solids let idx = x + y * 8 + z * 8 * 8; - let empty_voxel = super::world::Voxel::Empty; + let empty_voxel = Voxel::Empty; match center_block[idx] { - super::world::Voxel::Empty => continue, - super::world::Voxel::Color(r, g, b) => { + Voxel::Empty => continue, + Voxel::Color(r, g, b) => { // A voxel is on the surface if at least one of it's // cardinal neighbours is non-solid. neighbours[0] = if x == 7 { @@ -470,7 +469,7 @@ impl BrickmapManager { } fn grid_pos_to_world_pos( - world: &mut super::world::WorldManager, + world: &mut WorldManager, grid_pos: glam::IVec3, ) -> (glam::IVec3, glam::UVec3) { // We deal with dvecs here because we want a negative grid_pos to have floored diff --git a/src/voxel/brickworld/mod.rs b/src/voxel/brickworld/mod.rs new file mode 100644 index 0000000..caa798e --- /dev/null +++ b/src/voxel/brickworld/mod.rs @@ -0,0 +1,3 @@ +mod brickmap; + +pub use brickmap::BrickmapManager; diff --git a/src/voxel/mod.rs b/src/voxel/mod.rs index e106632..8067e4d 100644 --- a/src/voxel/mod.rs +++ b/src/voxel/mod.rs @@ -1,4 +1,4 @@ -pub mod brickmap; +pub mod brickworld; mod voxel_renderer; pub mod world; diff --git a/src/voxel/voxel_renderer.rs b/src/voxel/voxel_renderer.rs index 54228cd..778f140 100644 --- a/src/voxel/voxel_renderer.rs +++ b/src/voxel/voxel_renderer.rs @@ -9,7 +9,7 @@ pub struct VoxelRenderer { clear_color: wgpu::Color, render_texture: gfx::Texture, render_pipeline: wgpu::RenderPipeline, - brickmap_manager: super::brickmap::BrickmapManager, + brickmap_manager: super::brickworld::BrickmapManager, raycast_pipeline: wgpu::ComputePipeline, raycast_bind_group: wgpu::BindGroup, unpack_pipeline: wgpu::ComputePipeline, @@ -64,7 +64,7 @@ impl VoxelRenderer { }); log::info!("Creating brickmap manager..."); - let brickmap_manager = super::brickmap::BrickmapManager::new( + let brickmap_manager = super::brickworld::BrickmapManager::new( context, glam::uvec3(512, 64, 512), usize::pow(64, 3),