mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-10 01:28:41 -06:00
wip
This commit is contained in:
parent
6b8deab094
commit
783b6a1f84
|
@ -131,7 +131,7 @@ fn start_required_tasks(
|
||||||
let chunk = world.chunks.get_mut(&position).unwrap();
|
let chunk = world.chunks.get_mut(&position).unwrap();
|
||||||
chunk.current_state = CurrentChunkState::Loading;
|
chunk.current_state = CurrentChunkState::Loading;
|
||||||
// ===========
|
// ===========
|
||||||
log::info!("Started loading chunk {position}");
|
//log::trace!("Started loading chunk {position}");
|
||||||
},
|
},
|
||||||
DesiredChunkState::Rendered if chunk.current_state == CurrentChunkState::Loaded => {
|
DesiredChunkState::Rendered if chunk.current_state == CurrentChunkState::Loaded => {
|
||||||
//get needed data
|
//get needed data
|
||||||
|
@ -147,7 +147,7 @@ fn start_required_tasks(
|
||||||
let chunk = world.chunks.get_mut(&position).unwrap();
|
let chunk = world.chunks.get_mut(&position).unwrap();
|
||||||
chunk.current_state = CurrentChunkState::CalculatingMesh;
|
chunk.current_state = CurrentChunkState::CalculatingMesh;
|
||||||
// ===========
|
// ===========
|
||||||
log::info!("Started generating mesh for chunk {position}");
|
//log::trace!("Started generating mesh for chunk {position}");
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use glam::{vec3a, Vec3A, Vec4Swizzles, Vec3};
|
||||||
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter};
|
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter};
|
||||||
use glium::{
|
use glium::{
|
||||||
implement_vertex, uniform,
|
implement_vertex, uniform,
|
||||||
|
@ -68,25 +69,35 @@ pub fn draw_world(
|
||||||
});
|
});
|
||||||
let view = camera.view_matrix.to_cols_array_2d();
|
let view = camera.view_matrix.to_cols_array_2d();
|
||||||
let perspective = camera.perspective_matrix.to_cols_array_2d();
|
let perspective = camera.perspective_matrix.to_cols_array_2d();
|
||||||
|
let camera_mat = camera.perspective_matrix * camera.view_matrix;
|
||||||
|
|
||||||
for (&position, chunk) in &chunks.chunks {
|
for (&position, chunk) in &chunks.chunks {
|
||||||
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_vec3a() * CHUNK_SIZE as f32;
|
||||||
if mesh.index_buffer.len() > 0 { //maybe this is a bit hacky?
|
if mesh.index_buffer.len() == 0 {
|
||||||
target.0.draw(
|
continue
|
||||||
&mesh.vertex_buffer,
|
|
||||||
&mesh.index_buffer,
|
|
||||||
&program.0,
|
|
||||||
&uniform! {
|
|
||||||
position_offset: world_position,
|
|
||||||
view: view,
|
|
||||||
perspective: perspective,
|
|
||||||
tex: texture_sampler
|
|
||||||
},
|
|
||||||
&draw_parameters
|
|
||||||
).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//basic culling
|
||||||
|
// let chunk_center = world_position + Vec3A::splat(CHUNK_SIZE as f32) * 0.5;
|
||||||
|
// let cull_point = camera_mat * chunk_center.extend(1.);
|
||||||
|
// if (cull_point.xyz() / cull_point.w).abs().cmpgt(Vec3::splat(1.)).any() {
|
||||||
|
// continue
|
||||||
|
// }
|
||||||
|
|
||||||
|
target.0.draw(
|
||||||
|
&mesh.vertex_buffer,
|
||||||
|
&mesh.index_buffer,
|
||||||
|
&program.0,
|
||||||
|
&uniform! {
|
||||||
|
position_offset: world_position.to_array(),
|
||||||
|
view: view,
|
||||||
|
perspective: perspective,
|
||||||
|
tex: texture_sampler
|
||||||
|
},
|
||||||
|
&draw_parameters
|
||||||
|
).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,17 +13,26 @@ pub fn generate_world(chunk_position: IVec3, seed: u64) -> 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]);
|
||||||
|
|
||||||
for x in 0..CHUNK_SIZE {
|
blocks[0][0][0] = Block::Stone;
|
||||||
for y in 0..CHUNK_SIZE {
|
blocks[0][CHUNK_SIZE - 1][0] = Block::Stone;
|
||||||
for z in 0..CHUNK_SIZE {
|
blocks[CHUNK_SIZE - 1][0][0] = Block::Stone;
|
||||||
let position = ivec3(x as i32, y as i32, z as i32) + offset;
|
blocks[CHUNK_SIZE - 1][CHUNK_SIZE - 1][0] = Block::Stone;
|
||||||
let noise = noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32);
|
blocks[0][0][CHUNK_SIZE - 1] = Block::Stone;
|
||||||
if (0.7..0.8).contains(&noise) {
|
blocks[0][CHUNK_SIZE - 1][CHUNK_SIZE - 1] = Block::Stone;
|
||||||
blocks[x][y][z] = Block::Stone;
|
blocks[CHUNK_SIZE - 1][0][CHUNK_SIZE - 1] = Block::Stone;
|
||||||
}
|
blocks[CHUNK_SIZE - 1][CHUNK_SIZE - 1][CHUNK_SIZE - 1] = Block::Stone;
|
||||||
}
|
|
||||||
}
|
// for x in 0..CHUNK_SIZE {
|
||||||
}
|
// for y in 0..CHUNK_SIZE {
|
||||||
|
// for z in 0..CHUNK_SIZE {
|
||||||
|
// let position = ivec3(x as i32, y as i32, z as i32) + offset;
|
||||||
|
// let noise = noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32);
|
||||||
|
// if (0.7..0.8).contains(&noise) {
|
||||||
|
// blocks[x][y][z] = Block::Stone;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
blocks
|
blocks
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue