skip drawing empty chunks

This commit is contained in:
griffi-gh 2023-01-26 03:54:41 +01:00
parent 941f563059
commit 9ed19bfc0e
2 changed files with 15 additions and 19 deletions

View file

@ -73,18 +73,20 @@ pub fn draw_world(
if let Some(key) = chunk.mesh_index { if let Some(key) = chunk.mesh_index {
let mesh = meshes.get(key).expect("Mesh index pointing to nothing"); let mesh = meshes.get(key).expect("Mesh index pointing to nothing");
let world_position = (position.as_vec3() * CHUNK_SIZE as f32).to_array(); let world_position = (position.as_vec3() * CHUNK_SIZE as f32).to_array();
target.0.draw( if mesh.index_buffer.len() > 0 { //maybe this is a bit hacky?
&mesh.vertex_buffer, target.0.draw(
&mesh.index_buffer, &mesh.vertex_buffer,
&program.0, &mesh.index_buffer,
&uniform! { &program.0,
position_offset: world_position, &uniform! {
view: view, position_offset: world_position,
perspective: perspective, view: view,
tex: texture_sampler perspective: perspective,
}, tex: texture_sampler
&draw_parameters },
).unwrap(); &draw_parameters
).unwrap();
}
} }
} }
} }

View file

@ -6,19 +6,13 @@ use super::{
pub fn generate_world(position: IVec3, _seed: u32) -> BlockData { pub fn generate_world(position: IVec3, _seed: u32) -> BlockData {
let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]); let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]);
//TODO actual world generation
if position.y == -1 { if position.y == -1 {
for x in 0..CHUNK_SIZE { for x in 0..CHUNK_SIZE {
for z in 0..CHUNK_SIZE { for z in 0..CHUNK_SIZE {
blocks[x][0][z] = Block::Grass; blocks[x][0][z] = Block::Grass;
} }
} }
} else {
blocks[0][0][0] = Block::Stone;
blocks[1][0][0] = Block::Stone;
blocks[0][1][0] = Block::Stone;
blocks[0][2][0] = Block::Stone;
blocks[0][0][1] = Block::Stone;
} }
//TODO actual world generation
blocks blocks
} }