summaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/mod.rs14
-rw-r--r--src/renderer/ui.rs35
2 files changed, 35 insertions, 14 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index fcc5d36..4499688 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -212,8 +212,8 @@ impl RendererState {
let mut renderer_chunks: Vec<RendererChunk> = Vec::new();
// match number of world chunks
// TODO refactor so that this implicit
- for _ in -10..10 {
- for _ in -10..10 {
+ for _ in -10..1 {
+ for _ in -100..100 {
let texture = device.create_texture(&wgpu::TextureDescriptor {
label: None,
mip_level_count: 1,
@@ -336,7 +336,7 @@ impl RendererState {
.resizable(false)
// TODO collapse button
.show_collapsible(ui, &mut true, |panel_ui| {
- draw_egui(panel_ui, config, camera, diagnostics, input)
+ draw_egui(panel_ui, config, camera, diagnostics, input, world)
});
});
@@ -449,9 +449,13 @@ impl RendererState {
render_pass.set_bind_group(0, &self.camera_uniform_bind_group, &[]);
+ let (xl, xu, yl, yu) = camera.viewport_bounds_world();
+ let ((cxl, cyl), _) = World::split_game_position(xl.floor() as i32, yl.floor() as i32);
+ let ((cxu, cyu), _) = World::split_game_position(xu.floor() as i32, yu.floor() as i32);
+
// TODO only visible chunks
- for cx in -10..10 {
- for cy in -10..10 {
+ for cx in cxl..=cxu {
+ for cy in cyl..=cyu {
if let Some(idx) = world.chunk_position_to_chunk_idx.get(&(cx, cy)) {
let render_chunk = &self.renderer_chunks[*idx];
render_pass.set_bind_group(1, &render_chunk.bind_group, &[]);
diff --git a/src/renderer/ui.rs b/src/renderer/ui.rs
index 87ab878..b4e6f74 100644
--- a/src/renderer/ui.rs
+++ b/src/renderer/ui.rs
@@ -1,6 +1,9 @@
use egui::{Color32, Stroke, Ui, epaint::CircleShape};
-use crate::{Camera, Config, Diagnostics, Input, sim::materials::MaterialId};
+use crate::{
+ Camera, Config, Diagnostics, Input,
+ sim::{materials::MaterialId, world::World},
+};
pub fn draw_egui<'a>(
ui: &mut Ui,
@@ -8,6 +11,7 @@ pub fn draw_egui<'a>(
camera: &mut Camera,
diagnostics: &Diagnostics,
input: &Input,
+ world: &World,
) {
puffin::profile_function!();
ui.heading("Config");
@@ -24,7 +28,7 @@ pub fn draw_egui<'a>(
.icon(move |ui, rect, _, _| {
ui.painter().add(egui::Shape::Circle(CircleShape {
center: rect.center(),
- radius: rect.width() / 2.5,
+ radius: rect.height() / 2.0,
stroke: Stroke::NONE,
fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2),
}));
@@ -54,11 +58,24 @@ pub fn draw_egui<'a>(
))
});
- input
- .last_mouse_pos_on_board
- .map(|p| ui.label(format!("Mouse (board): x,y=({x}, {y})", x = p.0, y = p.1,)));
-
- input
- .last_mouse_pos_on_board
- .map(|p| ui.label(format!("Mouse (chunk): x,y=({x}, {y})", x = p.0, y = p.1,)));
+ if let Some((x, y)) = input.last_mouse_pos_on_board {
+ ui.heading("Entity");
+ ui.label(format!("x,y=({x}, {y})"));
+ if let Some(cell) = world.get_cell_from_game_position(x, y) {
+ let material = cell.material.def();
+ let cell_label = ui.label(
+ egui::RichText::new(format!("Cell: {}", material.name)).color(Color32::LIGHT_BLUE),
+ );
+ ui.painter().add(egui::Shape::Circle(CircleShape {
+ center: cell_label.rect.right_center() + egui::vec2(10.0, 0.0),
+ radius: cell_label.rect.height() / 2.5,
+ stroke: Stroke::NONE,
+ fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2),
+ }));
+ ui.label(
+ egui::RichText::new(format!("Flags: {:b}", cell.flags)).color(Color32::YELLOW),
+ );
+ ui.label(egui::RichText::new(format!("Data: {:b}", cell.data)).color(Color32::RED));
+ }
+ }
}