Chunk Work
This commit is contained in:
parent
d995d62b89
commit
b9a162c4a4
44
src/chunk.rs
44
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<Vertex> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
use crate::coordinates::Coordinates;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//! A few constants to make standardizing sizes easier.
|
//! A few constants to make standardizing sizes easier.
|
||||||
|
|
||||||
pub const CHUNK_RADIUS: u8 = 3;
|
pub const CHUNK_SIZE: usize = 32;
|
||||||
pub const CHUNK_HEIGHT: u8 = 4;
|
|
||||||
pub const PLAYER_HEIGHT: f64 = 1.7;
|
pub const PLAYER_HEIGHT: f64 = 1.7;
|
||||||
|
|
|
@ -119,3 +119,9 @@ impl Mul for Hex {
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::ops::{Add, Div, Mul, Sub};
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
|
#[derive(Debug, Copy, Clone, Default)]
|
||||||
|
pub struct Coordinates {
|
||||||
|
pub x: f32,
|
||||||
|
pub y: f32,
|
||||||
|
pub z: f32,
|
||||||
|
}
|
||||||
|
|
34
src/main.rs
34
src/main.rs
|
@ -13,8 +13,18 @@ pub mod chunk;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod coordinates;
|
pub mod coordinates;
|
||||||
pub mod textures;
|
pub mod textures;
|
||||||
|
pub mod vertex;
|
||||||
pub mod voxel;
|
pub mod voxel;
|
||||||
fn main() {
|
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 event_loop = glutin::event_loop::EventLoop::new();
|
||||||
let wb = glutin::window::WindowBuilder::new()
|
let wb = glutin::window::WindowBuilder::new()
|
||||||
.with_title("Voxel Engine")
|
.with_title("Voxel Engine")
|
||||||
|
@ -24,15 +34,24 @@ fn main() {
|
||||||
|
|
||||||
let display = glium::Display::new(wb, cb, &event_loop).unwrap();
|
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 vertex_shader_src = include_str!("../assets/shaders/teapot/teapot.vert");
|
||||||
let fragment_shader_src = include_str!("../assets/shaders/teapot/teapot.frag");
|
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)
|
glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None)
|
||||||
.unwrap();
|
.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| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
use glutin::event::Event::*;
|
use glutin::event::Event::*;
|
||||||
match event {
|
match event {
|
||||||
|
@ -124,20 +143,17 @@ fn main() {
|
||||||
.draw(
|
.draw(
|
||||||
(&positions, &normals),
|
(&positions, &normals),
|
||||||
&indices,
|
&indices,
|
||||||
&program,
|
&teapot_program,
|
||||||
&uniform! { matrix: matrix, u_light: light },
|
&uniform! { matrix: matrix, u_light: light },
|
||||||
¶ms,
|
¶ms,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Water Stage
|
{
|
||||||
|
// Water Stage
|
||||||
}
|
}
|
||||||
|
|
||||||
target.finish().unwrap();
|
target.finish().unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
mod teapot;
|
|
||||||
|
|
||||||
pub type ShaderList = HashMap<String, glium::Program>;
|
|
||||||
|
|
3
src/vertex.rs
Normal file
3
src/vertex.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub struct Vertex {
|
||||||
|
position: (f32, f32, f32),
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone, Default)]
|
||||||
pub struct Light {
|
pub struct Light {
|
||||||
pub red: u8,
|
pub red: u8,
|
||||||
pub green: u8,
|
pub green: u8,
|
||||||
|
@ -6,6 +7,7 @@ pub struct Light {
|
||||||
pub sun: u8,
|
pub sun: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, Default)]
|
||||||
pub struct VoxelData {
|
pub struct VoxelData {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub light_level: Light,
|
pub light_level: Light,
|
||||||
|
|
Loading…
Reference in a new issue