Scene terrain worker refactor

Simplify ChunkMeshState's active worker tracking to a bool,
as the tick value was never being used.
This commit is contained in:
Michael Droogleever Fortuyn
2020-09-19 16:13:29 +02:00
parent 6f2161c740
commit a3c4040063

View File

@ -64,7 +64,7 @@ pub struct TerrainChunkData {
struct ChunkMeshState { struct ChunkMeshState {
pos: Vec2<i32>, pos: Vec2<i32>,
started_tick: u64, started_tick: u64,
active_worker: Option<u64>, is_worker_active: bool,
} }
/// A type produced by mesh worker threads corresponding to the position and /// A type produced by mesh worker threads corresponding to the position and
@ -517,7 +517,7 @@ impl<V: RectRasterableVol> Terrain<V> {
self.mesh_todo.insert(pos, ChunkMeshState { self.mesh_todo.insert(pos, ChunkMeshState {
pos, pos,
started_tick: current_tick, started_tick: current_tick,
active_worker: None, is_worker_active: false,
}); });
} }
} }
@ -562,7 +562,7 @@ impl<V: RectRasterableVol> Terrain<V> {
self.mesh_todo.insert(neighbour_chunk_pos, ChunkMeshState { self.mesh_todo.insert(neighbour_chunk_pos, ChunkMeshState {
pos: neighbour_chunk_pos, pos: neighbour_chunk_pos,
started_tick: current_tick, started_tick: current_tick,
active_worker: None, is_worker_active: false,
}); });
} }
} }
@ -577,12 +577,8 @@ impl<V: RectRasterableVol> Terrain<V> {
for (todo, chunk) in self for (todo, chunk) in self
.mesh_todo .mesh_todo
.values_mut() .values_mut()
.filter(|todo| { .filter(|todo| !todo.is_worker_active)
todo.active_worker .min_by_key(|todo| todo.started_tick)
.map(|worker_tick| worker_tick < todo.started_tick)
.unwrap_or(true)
})
.min_by_key(|todo| todo.active_worker.unwrap_or(todo.started_tick))
// Find a reference to the actual `TerrainChunk` we're meshing // Find a reference to the actual `TerrainChunk` we're meshing
.and_then(|todo| { .and_then(|todo| {
let pos = todo.pos; let pos = todo.pos;
@ -658,7 +654,7 @@ impl<V: RectRasterableVol> Terrain<V> {
&sprite_config, &sprite_config,
)); ));
}); });
todo.active_worker = Some(todo.started_tick); todo.is_worker_active = true;
} }
drop(guard); drop(guard);