vox/src/chunk.rs

44 lines
1.3 KiB
Rust

use crate::{config::CHUNK_SIZE, vertex::Vertex, voxel::VoxelData};
/// “even-r” chunk.
#[derive(Debug, Copy, Clone, Default)]
pub struct Chunk {
inner_data: [[[VoxelData; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE],
pub chunk_position: Coordinates,
}
impl Chunk {
pub fn new() -> Self {
Self {
inner_data: [[[VoxelData::default(); CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE],
chunk_position: Coordinates::default(),
}
}
pub fn half_chunk_filled() -> Self {
let mut chunk = Self::new();
for x in 0..CHUNK_SIZE / 2 {
for y in 0..CHUNK_SIZE / 2 {
for z in 0..CHUNK_SIZE / 2 {
chunk.inner_data[x][y][z] = VoxelData {
id: 1,
light_level: VoxelData::default().light_level,
};
}
}
}
chunk
}
pub fn get_voxel(&self, x: usize, y: usize, z: usize) -> VoxelData {
self.inner_data[x][y][z]
}
pub fn set_voxel(&mut self, x: usize, y: usize, z: usize, voxel: VoxelData) {
self.inner_data[x][y][z] = voxel;
}
pub fn construct_vertexes(&self) -> Vec<Vertex> {
Vec::new()
}
}
use crate::coordinates::Coordinates;