Chunk Work

This commit is contained in:
Able 2022-03-29 22:42:14 -05:00
parent d995d62b89
commit b9a162c4a4
6 changed files with 81 additions and 12 deletions

View file

@ -1 +1,43 @@
pub struct Chunk {}
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],
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;

View file

@ -1,5 +1,5 @@
//! A few constants to make standardizing sizes easier.
pub const CHUNK_RADIUS: u8 = 3;
pub const CHUNK_HEIGHT: u8 = 4;
pub const CHUNK_SIZE: usize = 32;
pub const PLAYER_HEIGHT: f64 = 1.7;

View file

@ -119,3 +119,9 @@ impl Mul for Hex {
}
use std::ops::{Add, Div, Mul, Sub};
#[derive(Debug, Copy, Clone, Default)]
pub struct Coordinates {
pub x: f32,
pub y: f32,
pub z: f32,
}

View file

@ -13,8 +13,18 @@ pub mod chunk;
pub mod config;
pub mod coordinates;
pub mod textures;
pub mod vertex;
pub mod voxel;
fn main() {
let chunk = chunk::Chunk::half_chunk_filled();
println!("{:?}", chunk);
}
mod teapot;
pub type ShaderList = HashMap<String, glium::Program>;
pub fn bruh() {
let event_loop = glutin::event_loop::EventLoop::new();
let wb = glutin::window::WindowBuilder::new()
.with_title("Voxel Engine")
@ -24,15 +34,24 @@ fn main() {
let display = glium::Display::new(wb, cb, &event_loop).unwrap();
// let mut shaders = HashMap::new();
let vertex_shader_src = include_str!("../assets/shaders/teapot/teapot.vert");
let fragment_shader_src = include_str!("../assets/shaders/teapot/teapot.frag");
let program =
let teapot_program =
glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None)
.unwrap();
let water_vertex_shader_src = include_str!("../assets/shaders/water/water.vert");
let water_fragment_shader_src = include_str!("../assets/shaders/water/water.frag");
let water_program = glium::Program::from_source(
&display,
water_vertex_shader_src,
water_fragment_shader_src,
None,
)
.unwrap();
event_loop.run(move |event, _, control_flow| {
use glutin::event::Event::*;
match event {
@ -124,20 +143,17 @@ fn main() {
.draw(
(&positions, &normals),
&indices,
&program,
&teapot_program,
&uniform! { matrix: matrix, u_light: light },
&params,
)
.unwrap();
}
{ // Water Stage
{
// Water Stage
}
target.finish().unwrap();
});
}
mod teapot;
pub type ShaderList = HashMap<String, glium::Program>;

3
src/vertex.rs Normal file
View file

@ -0,0 +1,3 @@
pub struct Vertex {
position: (f32, f32, f32),
}

View file

@ -1,4 +1,5 @@
#[repr(C)]
#[derive(Debug, Copy, Clone, Default)]
pub struct Light {
pub red: u8,
pub green: u8,
@ -6,6 +7,7 @@ pub struct Light {
pub sun: u8,
}
#[derive(Debug, Copy, Clone, Default)]
pub struct VoxelData {
pub id: u32,
pub light_level: Light,