Begin separating brickmap into brickworld module

This commit is contained in:
Jarrod Doyle 2024-03-23 10:25:42 +00:00
parent c0a859b180
commit 10f3950e8d
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
4 changed files with 16 additions and 14 deletions

View File

@ -1,6 +1,9 @@
use std::collections::HashSet; use std::collections::HashSet;
use crate::{gfx, math}; use crate::{
gfx, math,
voxel::world::{Voxel, WorldManager},
};
#[repr(C)] #[repr(C)]
#[derive(Debug, Default, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] #[derive(Debug, Default, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
@ -171,11 +174,7 @@ impl BrickmapManager {
self.unpack_max_count self.unpack_max_count
} }
pub fn process_feedback_buffer( pub fn process_feedback_buffer(&mut self, context: &gfx::Context, world: &mut WorldManager) {
&mut self,
context: &gfx::Context,
world: &mut super::world::WorldManager,
) {
// Get request count // Get request count
let mut slice = self.feedback_result_buffer.slice(0..16); let mut slice = self.feedback_result_buffer.slice(0..16);
slice.map_async(wgpu::MapMode::Read, |_| {}); slice.map_async(wgpu::MapMode::Read, |_| {});
@ -365,7 +364,7 @@ impl BrickmapManager {
} }
fn cull_interior_voxels( fn cull_interior_voxels(
world: &mut super::world::WorldManager, world: &mut WorldManager,
grid_pos: glam::IVec3, grid_pos: glam::IVec3,
) -> ([u32; 16], Vec<u32>) { ) -> ([u32; 16], Vec<u32>) {
// This is the data we want to return // This is the data we want to return
@ -399,11 +398,11 @@ impl BrickmapManager {
for x in 0..8 { for x in 0..8 {
// Ignore non-solids // Ignore non-solids
let idx = x + y * 8 + z * 8 * 8; let idx = x + y * 8 + z * 8 * 8;
let empty_voxel = super::world::Voxel::Empty; let empty_voxel = Voxel::Empty;
match center_block[idx] { match center_block[idx] {
super::world::Voxel::Empty => continue, Voxel::Empty => continue,
super::world::Voxel::Color(r, g, b) => { Voxel::Color(r, g, b) => {
// 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. // cardinal neighbours is non-solid.
neighbours[0] = if x == 7 { neighbours[0] = if x == 7 {
@ -470,7 +469,7 @@ impl BrickmapManager {
} }
fn grid_pos_to_world_pos( fn grid_pos_to_world_pos(
world: &mut super::world::WorldManager, world: &mut WorldManager,
grid_pos: glam::IVec3, grid_pos: glam::IVec3,
) -> (glam::IVec3, glam::UVec3) { ) -> (glam::IVec3, glam::UVec3) {
// We deal with dvecs here because we want a negative grid_pos to have floored // We deal with dvecs here because we want a negative grid_pos to have floored

View File

@ -0,0 +1,3 @@
mod brickmap;
pub use brickmap::BrickmapManager;

View File

@ -1,4 +1,4 @@
pub mod brickmap; pub mod brickworld;
mod voxel_renderer; mod voxel_renderer;
pub mod world; pub mod world;

View File

@ -9,7 +9,7 @@ pub struct VoxelRenderer {
clear_color: wgpu::Color, clear_color: wgpu::Color,
render_texture: gfx::Texture, render_texture: gfx::Texture,
render_pipeline: wgpu::RenderPipeline, render_pipeline: wgpu::RenderPipeline,
brickmap_manager: super::brickmap::BrickmapManager, brickmap_manager: super::brickworld::BrickmapManager,
raycast_pipeline: wgpu::ComputePipeline, raycast_pipeline: wgpu::ComputePipeline,
raycast_bind_group: wgpu::BindGroup, raycast_bind_group: wgpu::BindGroup,
unpack_pipeline: wgpu::ComputePipeline, unpack_pipeline: wgpu::ComputePipeline,
@ -64,7 +64,7 @@ impl VoxelRenderer {
}); });
log::info!("Creating brickmap manager..."); log::info!("Creating brickmap manager...");
let brickmap_manager = super::brickmap::BrickmapManager::new( let brickmap_manager = super::brickworld::BrickmapManager::new(
context, context,
glam::uvec3(512, 64, 512), glam::uvec3(512, 64, 512),
usize::pow(64, 3), usize::pow(64, 3),