From 30b6143703b32d4234e753abf24e2f8185b131bb Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 29 Mar 2022 22:42:14 -0500 Subject: [PATCH] Chunk Work --- src/chunk.rs | 44 +++++++++++++++++++++++++++++++++++++++++++- src/config.rs | 4 ++-- src/coordinates.rs | 6 ++++++ src/main.rs | 34 +++++++++++++++++++++++++--------- src/vertex.rs | 3 +++ src/voxel.rs | 2 ++ 6 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 src/vertex.rs diff --git a/src/chunk.rs b/src/chunk.rs index cb32796..86069bc 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -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 { + Vec::new() + } +} +use crate::coordinates::Coordinates; diff --git a/src/config.rs b/src/config.rs index 4957c1a..3f67c07 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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; diff --git a/src/coordinates.rs b/src/coordinates.rs index 93c0ff4..ef0d44d 100644 --- a/src/coordinates.rs +++ b/src/coordinates.rs @@ -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, +} diff --git a/src/main.rs b/src/main.rs index 1e829b6..486b991 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; + +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 }, ¶ms, ) .unwrap(); } - { // Water Stage + { + // Water Stage } target.finish().unwrap(); }); } - -mod teapot; - -pub type ShaderList = HashMap; diff --git a/src/vertex.rs b/src/vertex.rs new file mode 100644 index 0000000..07c120f --- /dev/null +++ b/src/vertex.rs @@ -0,0 +1,3 @@ +pub struct Vertex { + position: (f32, f32, f32), +} diff --git a/src/voxel.rs b/src/voxel.rs index ab03692..a401b35 100644 --- a/src/voxel.rs +++ b/src/voxel.rs @@ -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,