Improved remeshing performance

This commit is contained in:
Joshua Barretto 2019-07-04 17:33:59 +01:00
parent 6709b18cb6
commit 51ad1f1995
3 changed files with 10 additions and 9 deletions

1
Cargo.lock generated
View File

@ -2665,6 +2665,7 @@ dependencies = [
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"frustum_query 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_device_gl 0.15.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_window_glutin 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -55,3 +55,4 @@ rand = "0.5"
frustum_query = "0.1.2"
rodio = { git = "https://github.com/desttinghim/rodio.git", rev = "dd93f905c1afefaac03c496a666ecab27d3e391b" }
crossbeam = "^0.7.1"
fxhash = "0.2"

View File

@ -9,7 +9,8 @@ use common::{
volumes::vol_map_2d::VolMap2dErr,
};
use frustum_query::frustum::Frustum;
use std::{collections::HashMap, i32, ops::Mul, sync::mpsc, time::Duration};
use std::{i32, ops::Mul, sync::mpsc, time::Duration};
use fxhash::FxHashMap;
use vek::*;
struct TerrainChunk {
@ -51,13 +52,13 @@ fn mesh_worker(
}
pub struct Terrain {
chunks: HashMap<Vec2<i32>, TerrainChunk>,
chunks: FxHashMap<Vec2<i32>, TerrainChunk>,
// The mpsc sender and receiver used for talking to meshing worker threads.
// We keep the sender component for no reason other than to clone it and send it to new workers.
mesh_send_tmp: mpsc::Sender<MeshWorkerResponse>,
mesh_recv: mpsc::Receiver<MeshWorkerResponse>,
mesh_todo: HashMap<Vec2<i32>, ChunkMeshState>,
mesh_todo: FxHashMap<Vec2<i32>, ChunkMeshState>,
}
impl Terrain {
@ -67,11 +68,10 @@ impl Terrain {
let (send, recv) = mpsc::channel();
Self {
chunks: HashMap::new(),
chunks: FxHashMap::default(),
mesh_send_tmp: send,
mesh_recv: recv,
mesh_todo: HashMap::new(),
mesh_todo: FxHashMap::default(),
}
}
@ -143,15 +143,14 @@ impl Terrain {
self.mesh_todo.remove(pos);
}
for todo in self
.mesh_todo
for todo in self.mesh_todo
.values_mut()
// Only spawn workers for meshing jobs without an active worker already.
.filter(|todo| {
todo.active_worker
.map(|worker_tick| worker_tick < todo.started_tick)
.unwrap_or(true)
})
.min_by_key(|todo| todo.active_worker.unwrap_or(0))
{
if client.thread_pool().queued_count() > 0 {
break;