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,6 +73,7 @@ pub fn draw_world(
if let Some(key) = chunk.mesh_index {
let mesh = meshes.get(key).expect("Mesh index pointing to nothing");
let world_position = (position.as_vec3() * CHUNK_SIZE as f32).to_array();
if mesh.index_buffer.len() > 0 { //maybe this is a bit hacky?
target.0.draw(
&mesh.vertex_buffer,
&mesh.index_buffer,
@ -88,3 +89,4 @@ pub fn draw_world(
}
}
}
}

View file

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