summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLizzy Fleckenstein <eliasfleckenstein@web.de>2023-05-24 03:19:52 +0200
committerLizzy Fleckenstein <eliasfleckenstein@web.de>2023-05-24 03:19:52 +0200
commit74092dfb6a0e06f59ec70b3a87b63a1ad8011640 (patch)
tree12cc7ef4303113d54b598d6b731478572e583684 /src
parent63d0c704e889f0b05f03f39903378324ca5b6431 (diff)
downloadmt_client-74092dfb6a0e06f59ec70b3a87b63a1ad8011640.tar.xz
Add visible/total blocks count to debug menu
Diffstat (limited to 'src')
-rw-r--r--src/gfx.rs2
-rw-r--r--src/gfx/debug_menu.rs14
-rw-r--r--src/gfx/map.rs32
3 files changed, 20 insertions, 28 deletions
diff --git a/src/gfx.rs b/src/gfx.rs
index 2c4a219..859540b 100644
--- a/src/gfx.rs
+++ b/src/gfx.rs
@@ -29,7 +29,7 @@ pub async fn run(
let mut gpu = gpu::Gpu::new(&window).await;
let mut map: Option<map::MapRender> = None;
let mut font = font::Font::new(&gpu);
- let mut debug_menu = debug_menu::DebugMenu::new();
+ let mut debug_menu = debug_menu::DebugMenu::default();
let mut media = media::MediaMgr::new();
let mut camera = camera::Camera::new(&gpu);
diff --git a/src/gfx/debug_menu.rs b/src/gfx/debug_menu.rs
index 4baf0f1..1f6ebf4 100644
--- a/src/gfx/debug_menu.rs
+++ b/src/gfx/debug_menu.rs
@@ -1,19 +1,15 @@
use super::{camera::Camera, font::Font};
use wgpu_glyph::{Section, Text};
+#[derive(Default)]
pub struct DebugMenu {
pub enabled: bool,
pub fps: usize,
+ pub blocks: usize,
+ pub blocks_visible: usize,
}
impl DebugMenu {
- pub fn new() -> Self {
- Self {
- enabled: false,
- fps: 0,
- }
- }
-
pub fn render(&self, bounds: (f32, f32), camera: &Camera, font: &mut Font) {
if !self.enabled {
return;
@@ -48,5 +44,9 @@ impl DebugMenu {
));
add_text(&format!("yaw: {:.1}°", (camera.rot.y.0 + 360.0) % 360.0));
add_text(&format!("pitch: {:.1}°", camera.rot.z.0));
+ add_text(&format!(
+ "blocks visible: {}/{}",
+ self.blocks_visible, self.blocks,
+ ));
}
}
diff --git a/src/gfx/map.rs b/src/gfx/map.rs
index 04865a6..a134467 100644
--- a/src/gfx/map.rs
+++ b/src/gfx/map.rs
@@ -148,16 +148,12 @@ impl MapRender {
pass.set_bind_group(0, &self.atlas, &[]);
pass.set_bind_group(1, &camera.uniform.bind_group, &[]);
- struct BlendEntry<'a> {
- dist: f32,
- index: usize,
- mesh: &'a BlockMesh,
- transform: &'a MatrixUniform,
- }
-
let mut blend = Vec::new();
- for (index, (&pos, model)) in self.block_models.iter().enumerate() {
+ debug_menu.blocks = self.block_models.len();
+ debug_menu.blocks_visible = 0;
+
+ for (&pos, model) in self.block_models.iter() {
if model.mesh.is_none() && model.mesh_blend.is_none() {
continue;
}
@@ -170,31 +166,27 @@ impl MapRender {
continue;
}
+ debug_menu.blocks_visible += 1;
+
if let Some(mesh) = &model.mesh {
mesh.render(pass, &model.transform);
}
if let Some(mesh) = &model.mesh_blend {
- blend.push(BlendEntry {
- index,
- dist: (camera.view * (fpos + one * 8.5).to_homogeneous())
+ blend.push((
+ (camera.view * (fpos + one * 8.5).to_homogeneous())
.truncate()
.magnitude(),
mesh,
- transform: &model.transform,
- });
+ &model.transform,
+ ));
}
}
- blend.sort_unstable_by(|a, b| {
- a.dist
- .partial_cmp(&b.dist)
- .unwrap_or(std::cmp::Ordering::Equal)
- .then_with(|| a.index.cmp(&b.index))
- });
+ blend.sort_unstable_by(|a, b| a.0.partial_cmp(&b.0).unwrap_or(std::cmp::Ordering::Equal));
for entry in blend {
- entry.mesh.render(pass, entry.transform);
+ entry.1.render(pass, entry.2);
}
}