From 7cee43b32d2897a7c35f8e695c4d2b4e43432567 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sat, 2 Jul 2022 22:36:56 +0100 Subject: [PATCH] Added egui plot showing the count of chunks pending meshing --- voxygen/egui/src/lib.rs | 44 ++++++++++++++++++++++++++++++------ voxygen/src/scene/terrain.rs | 12 +++++++++- voxygen/src/session/mod.rs | 11 +++++---- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/voxygen/egui/src/lib.rs b/voxygen/egui/src/lib.rs index c309887c80..c5b7743681 100644 --- a/voxygen/egui/src/lib.rs +++ b/voxygen/egui/src/lib.rs @@ -82,6 +82,7 @@ impl AdminCommandState { pub struct EguiDebugInfo { pub frame_time: Duration, pub ping_ms: f64, + pub mesh_todo: usize, } pub struct EguiInnerState { @@ -90,6 +91,7 @@ pub struct EguiInnerState { max_entity_distance: f32, selected_entity_cylinder_height: f32, frame_times: Vec, + mesh_todos: Vec, windows: EguiWindows, } @@ -112,6 +114,7 @@ impl Default for EguiInnerState { max_entity_distance: 100000.0, selected_entity_cylinder_height: 10.0, frame_times: Vec::new(), + mesh_todos: Vec::new(), windows: EguiWindows::default(), } } @@ -233,6 +236,11 @@ pub fn maintain_egui_inner( if egui_state.frame_times.len() > 250 { egui_state.frame_times.remove(0); } + + egui_state.mesh_todos.push(debug_info.mesh_todo); + if egui_state.mesh_todos.len() > 2000 { + egui_state.mesh_todos.remove(0); + } }; let start_pos = Pos2 { x: 300.0, y: 0.0 }; @@ -293,14 +301,36 @@ pub fn maintain_egui_inner( .default_width(200.0) .default_height(200.0) .show(ctx, |ui| { - let plot = Plot::new("Frame Time").curve(Curve::from_values_iter( - egui_state - .frame_times - .iter() - .enumerate() - .map(|(i, x)| Value::new(i as f64, *x)), - )); + let plot = Plot::new("Frame Time") + .curve(Curve::from_values_iter( + egui_state + .frame_times + .iter() + .enumerate() + .map(|(i, x)| Value::new(i as f64, *x)), + )) + .height(50.0); ui.add(plot); + + ui.add_space(20.0); + + ui.label(format!( + "Pending Meshing: {}", + &egui_state.mesh_todos.last().unwrap_or(&0usize) + )); + let mesh_todo_plot = Plot::new("Chunks Pending Meshing") + .curve( + Curve::from_values_iter( + egui_state + .mesh_todos + .iter() + .enumerate() + .map(|(i, x)| Value::new(i as f64, (*x) as f64)), + ) + .color(Color32::from_rgb(45, 91, 215)), + ) + .height(200.0); + ui.add(mesh_todo_plot); }); if windows.ecs_entities { diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index a54b7db911..3c9b55739d 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -360,6 +360,10 @@ pub struct Terrain { phantom: PhantomData, } +impl Terrain { + pub fn chunks_pending_meshing_count(&self) -> usize { self.mesh_todo.iter().len() } +} + impl TerrainChunkData { pub fn can_shadow_sun(&self) -> bool { self.visible.is_visible() || self.can_shadow_sun } } @@ -951,7 +955,13 @@ impl Terrain { .filter(|todo| !todo.is_worker_active) // TODO: BinaryHeap .collect::>(); - todo.sort_unstable_by_key(|todo| ((todo.pos.as_::() * TerrainChunk::RECT_SIZE.as_::()).distance_squared(mesh_focus_pos), todo.started_tick)); + todo.sort_unstable_by_key(|todo| { + ( + (todo.pos.as_::() * TerrainChunk::RECT_SIZE.as_::()) + .distance_squared(mesh_focus_pos), + todo.started_tick, + ) + }); for (todo, chunk) in todo.into_iter() .filter(|todo| !todo.is_worker_active) diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 235a52cd23..c6c667e1fc 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -1103,13 +1103,16 @@ impl PlayState for SessionState { // Maintain egui (debug interface) #[cfg(feature = "egui-ui")] if global_state.settings.interface.egui_enabled() { + let debug_info = debug_info.map(|debug_info| EguiDebugInfo { + frame_time: debug_info.frame_time, + ping_ms: debug_info.ping_ms, + mesh_todo: self.scene.terrain().chunks_pending_meshing_count(), + }); + let settings_change = global_state.egui_state.maintain( &mut self.client.borrow_mut(), &mut self.scene, - debug_info.map(|debug_info| EguiDebugInfo { - frame_time: debug_info.frame_time, - ping_ms: debug_info.ping_ms, - }), + debug_info, &global_state.settings, );