mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-24 04:48:21 -06:00
don't count discarded ops
This commit is contained in:
parent
816d2f6077
commit
1b85340d9c
|
@ -170,61 +170,69 @@ fn process_completed_tasks(
|
||||||
mut meshes: NonSendSync<UniqueViewMut<ChunkMeshStorage>>,
|
mut meshes: NonSendSync<UniqueViewMut<ChunkMeshStorage>>,
|
||||||
renderer: NonSendSync<UniqueView<Renderer>>
|
renderer: NonSendSync<UniqueView<Renderer>>
|
||||||
) {
|
) {
|
||||||
for _ in 0..MAX_CHUNK_OPS {
|
let mut ops: usize = 0;
|
||||||
if let Some(res) = task_manager.receive() {
|
while let Some(res) = task_manager.receive() {
|
||||||
match res {
|
match res {
|
||||||
ChunkTaskResponse::LoadedChunk { position, chunk_data } => {
|
ChunkTaskResponse::LoadedChunk { position, chunk_data } => {
|
||||||
//check if chunk exists
|
//check if chunk exists
|
||||||
let Some(chunk) = world.chunks.get_mut(&position) else {
|
let Some(chunk) = world.chunks.get_mut(&position) else {
|
||||||
log::warn!("blocks data discarded: chunk doesn't exist");
|
log::warn!("blocks data discarded: chunk doesn't exist");
|
||||||
return
|
return
|
||||||
};
|
};
|
||||||
|
|
||||||
//check if chunk still wants it
|
//check if chunk still wants it
|
||||||
if !matches!(chunk.desired_state, DesiredChunkState::Loaded | DesiredChunkState::Rendered) {
|
if !matches!(chunk.desired_state, DesiredChunkState::Loaded | DesiredChunkState::Rendered) {
|
||||||
log::warn!("block data discarded: state undesirable: {:?}", chunk.desired_state);
|
log::warn!("block data discarded: state undesirable: {:?}", chunk.desired_state);
|
||||||
return
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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