Block struct
This commit is contained in:
@@ -1,9 +1,20 @@
|
||||
use std::convert::TryInto;
|
||||
use crate::renderer::buffers::{BLOCK_SIZE, BLOCK_TEX_SIZE, BLOCK_TEX_LEN, BLOCK_LEN};
|
||||
use crate::renderer::buffers::{BLOCK_SIZE, BLOCK_TEX_SIZE, BLOCK_TEX_LEN, BLOCK_LEN, BLOCK_ARR_LEN};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Block {
|
||||
pub data: [u8;BLOCK_LEN]
|
||||
}
|
||||
|
||||
impl Block {
|
||||
pub fn new() -> Self {
|
||||
Self { data: [0_u8;BLOCK_LEN] }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct Blocks {
|
||||
pub blocks: Box<[u8]>,
|
||||
pub blocks: Box<[Block]>,
|
||||
pub free_block: usize,
|
||||
texture: wgpu::Texture,
|
||||
pub bind_layout: wgpu::BindGroupLayout,
|
||||
@@ -72,8 +83,9 @@ impl Blocks {
|
||||
);
|
||||
|
||||
// Data
|
||||
let mut blocks = vec![0_u8; BLOCK_TEX_LEN].into_boxed_slice();
|
||||
blocks[0] = 1;
|
||||
let mut blocks = vec![Block::new(); BLOCK_ARR_LEN].into_boxed_slice();
|
||||
blocks[0].data[0] = 1;
|
||||
|
||||
println!("block buffer size: {} MB", BLOCK_TEX_LEN as f32 / 1024.0 / 1024.0);
|
||||
|
||||
// Done
|
||||
@@ -86,8 +98,7 @@ impl Blocks {
|
||||
*/
|
||||
pub fn write(&mut self, queue: &wgpu::Queue, block: usize) {
|
||||
// Get first block
|
||||
let block_offset = block*BLOCK_LEN;
|
||||
let block_bytes : [u8;BLOCK_LEN] = self.blocks[block_offset..block_offset+BLOCK_LEN].try_into().unwrap();
|
||||
let block_bytes : [u8;BLOCK_LEN] = self.blocks[block].data.try_into().unwrap();
|
||||
let block_size = wgpu::Extent3d{ width: BLOCK_SIZE as u32, height: BLOCK_SIZE as u32, depth: BLOCK_SIZE as u32 };
|
||||
|
||||
let y = (block%BLOCK_TEX_SIZE * BLOCK_SIZE) as u32;
|
||||
|
||||
@@ -8,6 +8,7 @@ pub const NODE_TEX_SIZE: usize = 48; // 32x32x32 nodes in texture
|
||||
|
||||
pub const NODE_TEX_LEN: usize = NODE_TEX_SIZE*NODE_TEX_SIZE*NODE_TEX_SIZE; // Number of u32 in node texture
|
||||
pub const BLOCK_LEN : usize = BLOCK_SIZE*BLOCK_SIZE*BLOCK_SIZE; // Number of u8 in one block
|
||||
pub const BLOCK_ARR_LEN: usize = BLOCK_TEX_SIZE*BLOCK_TEX_SIZE; // Number of blocks in texture
|
||||
pub const BLOCK_TEX_LEN: usize = BLOCK_TEX_SIZE*BLOCK_TEX_SIZE * BLOCK_LEN; // Number of u8 in block texture
|
||||
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ impl Level for Renderer {
|
||||
*/
|
||||
fn block_set_voxel(&mut self, brick_id:usize, x: usize, y: usize, z:usize, value: u8) {
|
||||
let voxel_id = x + buffers::BLOCK_SIZE * (y + buffers::BLOCK_SIZE * z);
|
||||
let brick_offset = brick_id * buffers::BLOCK_LEN;
|
||||
self.buffers.brick_buffer.blocks[brick_offset + voxel_id] = value;
|
||||
self.buffers.brick_buffer.blocks[brick_id].data[voxel_id] = value;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user