diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/src/main.rs b/src/main.rs index 7cac1f3..bb4cb27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,11 +81,10 @@ struct App { impl App { // called as often as possible // delta time is the real seconds elapsed since the last time this was called - fn update(&mut self, delta_time: f32) -> () { + fn update(&mut self, delta_time: f32) { // apply inputs - match &mut self.camera { - Some(camera) => camera.handle_camera_input(&self.input, delta_time), - _ => {} + if let Some(camera) = &mut self.camera { + camera.handle_camera_input(&self.input, delta_time) } // // --TEST DRAWING-- @@ -110,11 +109,10 @@ impl App { let mut cell = Cell::from_material(self.config.brush_material); // ensure we simulate on the first tick cell.flags = (self.sim_seqno as u8) & 0b1; - match &mut self.world { - Some(world) => world.set_cell_from_game_position( + if let Some(world) = &mut self.world { + world.set_cell_from_game_position( x, y, cell, false, // wake the chunk - ), - _ => {} + ) } } } @@ -125,20 +123,17 @@ impl App { // will be called before the render and before the physics update(s) // may be called multiple times if the sim time is behind // sim_delta_time is statically 1/SIM_FPS - fn sim_update(&mut self, sim_delta_time: f32) -> () { - match &mut self.world { - Some(world) => { - sim_tick(world, self.sim_seqno, self.config.use_threading); - self.sim_seqno += 1; - } - _ => {} + fn sim_update(&mut self, _sim_delta_time: f32) { + if let Some(world) = &mut self.world { + sim_tick(world, self.sim_seqno, self.config.use_threading); + self.sim_seqno += 1; } } // called PHYSICS_FPS times per second // will be called before the render // may be called multiple times if the physics time is behind // physics_delta_time is statically 1/PHYSICS_FPS - fn physics_update(&mut self, physics_delta_time: f32) -> () {} + fn physics_update(&mut self, _physics_delta_time: f32) {} } impl Default for App { @@ -216,7 +211,7 @@ impl ApplicationHandler for App { if let Some(renderer_state) = &mut self.renderer_state && let Some(window) = &mut self.window { - let egui_response = renderer_state.egui_state.on_window_event(&window, &event); + let egui_response = renderer_state.egui_state.on_window_event(window, &event); // if egui consumed the event, it means we shouldn't treat any e.g., mouse clicks if egui_response.consumed { return; @@ -245,21 +240,15 @@ impl ApplicationHandler for App { self.sim_paused = !self.sim_paused } } - KeyCode::KeyX => { - if pressed { - self.ignore_pause_next_tick = true - } - } + KeyCode::KeyX if pressed => self.ignore_pause_next_tick = true, _ => {} } } WindowEvent::CursorMoved { position, .. } => { self.input.last_mouse_pos_on_screen = Some((position.x as f32, position.y as f32)); - self.input.last_mouse_world_pos = if let Some(camera) = &mut self.camera { - Some(camera.screen_position_to_world(position.x as f32, position.y as f32)) - } else { - None - } + self.input.last_mouse_world_pos = self.camera.as_mut().map(|camera| { + camera.screen_position_to_world(position.x as f32, position.y as f32) + }) } WindowEvent::MouseInput { state, button, .. } => { if button == MouseButton::Left { @@ -351,7 +340,7 @@ impl ApplicationHandler for App { camera, &mut self.config, &self.diagnostics, - &mut self.input, + &self.input, ); } } |
