mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 03:48:21 -06:00
don't count discarded ops
This commit is contained in:
parent
34fa47acbe
commit
df8640718d
|
@ -170,61 +170,69 @@ fn process_completed_tasks(
|
|||
mut meshes: NonSendSync<UniqueViewMut<ChunkMeshStorage>>,
|
||||
renderer: NonSendSync<UniqueView<Renderer>>
|
||||
) {
|
||||
for _ in 0..MAX_CHUNK_OPS {
|
||||
if let Some(res) = task_manager.receive() {
|
||||
match res {
|
||||
ChunkTaskResponse::LoadedChunk { position, chunk_data } => {
|
||||
//check if chunk exists
|
||||
let Some(chunk) = world.chunks.get_mut(&position) else {
|
||||
log::warn!("blocks data discarded: chunk doesn't exist");
|
||||
return
|
||||
};
|
||||
let mut ops: usize = 0;
|
||||
while let Some(res) = task_manager.receive() {
|
||||
match res {
|
||||
ChunkTaskResponse::LoadedChunk { position, chunk_data } => {
|
||||
//check if chunk exists
|
||||
let Some(chunk) = world.chunks.get_mut(&position) else {
|
||||
log::warn!("blocks data discarded: chunk doesn't exist");
|
||||
return
|
||||
};
|
||||
|
||||
//check if chunk still wants it
|
||||
if !matches!(chunk.desired_state, DesiredChunkState::Loaded | DesiredChunkState::Rendered) {
|
||||
log::warn!("block data discarded: state undesirable: {:?}", chunk.desired_state);
|
||||
return
|
||||
}
|
||||
|
||||
//set the block data
|
||||
chunk.block_data = Some(ChunkData {
|
||||
blocks: chunk_data
|
||||
});
|
||||
|
||||
//update chunk state
|
||||
chunk.current_state = CurrentChunkState::Loaded;
|
||||
},
|
||||
ChunkTaskResponse::GeneratedMesh { position, vertices, indexes } => {
|
||||
//check if chunk exists
|
||||
let Some(chunk) = world.chunks.get_mut(&position) else {
|
||||
log::warn!("mesh discarded: chunk doesn't exist");
|
||||
return
|
||||
};
|
||||
|
||||
//check if chunk still wants it
|
||||
if chunk.desired_state != DesiredChunkState::Rendered {
|
||||
log::warn!("mesh discarded: state undesirable: {:?}", chunk.desired_state);
|
||||
return
|
||||
}
|
||||
|
||||
//apply the mesh
|
||||
let vertex_buffer = VertexBuffer::new(&renderer.display, &vertices).unwrap();
|
||||
let index_buffer = IndexBuffer::new(&renderer.display, PrimitiveType::TrianglesList, &indexes).unwrap();
|
||||
let mesh = ChunkMesh {
|
||||
vertex_buffer,
|
||||
index_buffer,
|
||||
};
|
||||
if let Some(index) = chunk.mesh_index {
|
||||
meshes.update(index, mesh).expect("Mesh update failed");
|
||||
} else {
|
||||
let mesh_index = meshes.insert(mesh);
|
||||
chunk.mesh_index = Some(mesh_index);
|
||||
}
|
||||
|
||||
//update chunk state
|
||||
chunk.current_state = CurrentChunkState::Rendered;
|
||||
//check if chunk still wants it
|
||||
if !matches!(chunk.desired_state, DesiredChunkState::Loaded | DesiredChunkState::Rendered) {
|
||||
log::warn!("block data discarded: state undesirable: {:?}", chunk.desired_state);
|
||||
return
|
||||
}
|
||||
|
||||
//set the block data
|
||||
chunk.block_data = Some(ChunkData {
|
||||
blocks: chunk_data
|
||||
});
|
||||
|
||||
//update chunk state
|
||||
chunk.current_state = CurrentChunkState::Loaded;
|
||||
|
||||
//increase ops counter
|
||||
ops += 1;
|
||||
},
|
||||
ChunkTaskResponse::GeneratedMesh { position, vertices, indexes } => {
|
||||
//check if chunk exists
|
||||
let Some(chunk) = world.chunks.get_mut(&position) else {
|
||||
log::warn!("mesh discarded: chunk doesn't exist");
|
||||
return
|
||||
};
|
||||
|
||||
//check if chunk still wants it
|
||||
if chunk.desired_state != DesiredChunkState::Rendered {
|
||||
log::warn!("mesh discarded: state undesirable: {:?}", chunk.desired_state);
|
||||
return
|
||||
}
|
||||
|
||||
//apply the mesh
|
||||
let vertex_buffer = VertexBuffer::new(&renderer.display, &vertices).unwrap();
|
||||
let index_buffer = IndexBuffer::new(&renderer.display, PrimitiveType::TrianglesList, &indexes).unwrap();
|
||||
let mesh = ChunkMesh {
|
||||
vertex_buffer,
|
||||
index_buffer,
|
||||
};
|
||||
if let Some(index) = chunk.mesh_index {
|
||||
meshes.update(index, mesh).expect("Mesh update failed");
|
||||
} else {
|
||||
let mesh_index = meshes.insert(mesh);
|
||||
chunk.mesh_index = Some(mesh_index);
|
||||
}
|
||||
|
||||
//update chunk state
|
||||
chunk.current_state = CurrentChunkState::Rendered;
|
||||
|
||||
//increase ops counter
|
||||
ops += 1;
|
||||
}
|
||||
}
|
||||
if ops >= MAX_CHUNK_OPS {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue