From da45c5a7dbb017c8e579d0ab66a2259a70b28f40 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 23 Aug 2026 14:33:23 -0700 Subject: input manager --- src/renderer/mod.rs | 12 +++----- src/renderer/ui.rs | 85 +++++++++++++++++++++++++++++------------------------ 2 files changed, 50 insertions(+), 47 deletions(-) (limited to 'src/renderer') diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 54a6667..b37dc09 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -6,7 +6,7 @@ use fxhash::FxHashMap; use winit::window::Window; use crate::{ - Config, Diagnostics, Input, + Config, Diagnostics, InputManager, camera::Camera, config::{CELLS_IN_CHUNK, CHUNK_SIZE}, content::materials::MaterialId, @@ -578,7 +578,7 @@ impl RendererState { camera: &mut Camera, config: &mut Config, diagnostics: &Diagnostics, - input: &Input, + input_manager: &InputManager, ) { puffin::profile_function!(); @@ -626,7 +626,7 @@ impl RendererState { .resizable(false) // TODO collapse button .show_collapsible(ui, &mut true, |panel_ui| { - draw_egui(panel_ui, config, camera, diagnostics, input, sim) + draw_egui(panel_ui, config, camera, diagnostics, input_manager, sim) }); }); @@ -747,11 +747,7 @@ impl RendererState { for (id, slot) in &self.renderer_rb_entities { if let Some(entity) = sim.entities.get(id) && let Some(cells) = &entity.data.cells - && let Some((pos, (cos, sin))) = entity.data.transform(&SimCtx { - cell_manager: &mut sim.cell_manager, - particle_manager: &mut sim.particle_manager, - rb_manager: &mut sim.rb_manager, - }) + && let Some((pos, (cos, sin))) = entity.data._transform(&sim.rb_manager) { instances.push(RendererInstance { centre: pos.to_array(), diff --git a/src/renderer/ui.rs b/src/renderer/ui.rs index a7395a0..46fb853 100644 --- a/src/renderer/ui.rs +++ b/src/renderer/ui.rs @@ -1,8 +1,9 @@ use egui::{Color32, Stroke, Ui, epaint::CircleShape}; use crate::{ - Camera, Config, Diagnostics, Input, + Camera, Config, Diagnostics, content::materials::MaterialId, + input::InputManager, sim::{rb_manager::DebugRenderMode, sim_manager::SimManager}, }; @@ -20,7 +21,7 @@ pub fn draw_egui<'a>( config: &mut Config, camera: &mut Camera, diagnostics: &Diagnostics, - input: &Input, + input_manager: &InputManager, sim: &SimManager, ) { puffin::profile_function!(); @@ -104,44 +105,50 @@ pub fn draw_egui<'a>( ui.add(egui::Slider::new(&mut camera.zoom, 0.0..=10.0).text("Zoom")); ui.heading("Input"); - input - .last_mouse_world_pos - .map(|p| ui.label(format!("Mouse (world): x,y=({x}, {y})", x = p.0, y = p.1,))); - - if let Some(p) = input.last_mouse_chunk_pos { - ui.label(format!("Mouse (chunk): x,y=({x}, {y})", x = p.0, y = p.1,)); - if let Some(&chunk) = sim.cell_manager.chunk_position_to_chunk_idx.get(&p) { - ui.label(format!( - "Sleeping={}", - sim.cell_manager.chunks[chunk].sleeping - )); - } + ui.label(format!( + "Mouse (world): x,y=({x}, {y})", + x = input_manager.world_mouse_pos.x, + y = input_manager.world_mouse_pos.y + )); + + ui.label(format!( + "Mouse (chunk): x,y=({x}, {y})", + x = input_manager.chunk_mouse_pos.x, + y = input_manager.chunk_mouse_pos.y + )); + + if let Some(&chunk) = sim.cell_manager.chunk_position_to_chunk_idx.get(&( + input_manager.chunk_mouse_pos.x, + input_manager.chunk_mouse_pos.y, + )) { + ui.label(format!( + "Sleeping={}", + sim.cell_manager.chunks[chunk].sleeping + )); } - input - .last_mouse_local_pos - .map(|p| ui.label(format!("Mouse (local): x,y=({x}, {y})", x = p.0, y = p.1,))); - - if let Some((x, y)) = input.last_mouse_world_pos { - ui.heading("Entity"); - if let Some(cell) = sim - .cell_manager - .get_cell_from_game_position(x.round() as i32, y.round() as i32) - { - 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)); - } + ui.label(format!( + "Mouse (local): x,y=({x}, {y})", + x = input_manager.local_mouse_pos.x, + y = input_manager.local_mouse_pos.y + )); + + ui.heading("Entity"); + if let Some(cell) = sim.cell_manager.get_cell_from_game_position( + input_manager.world_mouse_pos.x.round() as i32, + input_manager.world_mouse_pos.y.round() as i32, + ) { + 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)); } } -- cgit v1.3.1