summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 3452065..640e5b9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,6 +5,7 @@ mod sim;
use futures::executor;
use fxhash::FxHashMap;
+use glam::Vec2;
use rand::random_range;
use std::{collections::VecDeque, sync::Arc, time::Instant};
use winit::{
@@ -20,7 +21,7 @@ use winit::{
use crate::{
camera::Camera,
- config::{PHYSICS_DELTA_TIME, PHYSICS_FPS, SIM_FPS, WINDOW_TITLE},
+ config::{CHUNK_SIZE, PHYSICS_DELTA_TIME, PHYSICS_FPS, SIM_FPS, WINDOW_TITLE},
renderer::RendererState,
sim::{
cell::{cell::Cell, materials::MaterialId},
@@ -45,8 +46,11 @@ struct Config {
struct Input {
last_mouse_pos_on_screen: Option<(f32, f32)>,
last_mouse_world_pos: Option<(f32, f32)>,
+ last_mouse_chunk_pos: Option<(i32, i32)>,
+ last_mouse_local_pos: Option<(u8, u8)>,
is_lmb_pressed: bool,
trigger_test_1: bool,
+ trigger_test_2: bool,
// keybindings
is_up_pressed: bool,
@@ -110,6 +114,18 @@ impl App {
rbsm.test_spawn_box(lm.0, lm.1, self.config.dropper_material);
}
+ if self.input.trigger_test_2
+ && let Some((cx, cy)) = self.input.last_mouse_chunk_pos
+ && let Some(world) = &self.world
+ && let Some(rbsm) = &mut self.rb_sim_manager
+ {
+ self.input.trigger_test_2 = false;
+ rbsm.test_add_collider_from_chunk(
+ Vec2::new((cx * CHUNK_SIZE) as f32, (cy * CHUNK_SIZE) as f32),
+ &world.chunks[*world.chunk_position_to_chunk_idx.get(&(cx, cy)).unwrap()],
+ );
+ }
+
// --TEST DRAWING--
if self.input.is_lmb_pressed
&& let Some(lm) = self.input.last_mouse_world_pos
@@ -201,8 +217,11 @@ impl Default for App {
input: Input {
last_mouse_pos_on_screen: None,
last_mouse_world_pos: None,
+ last_mouse_chunk_pos: None,
+ last_mouse_local_pos: None,
trigger_test_1: false,
+ trigger_test_2: false,
is_lmb_pressed: false,
is_up_pressed: false,
is_left_pressed: false,
@@ -328,15 +347,24 @@ impl ApplicationHandler for App {
}
KeyCode::Space if pressed => self.sim_paused = !self.sim_paused,
KeyCode::KeyX if pressed => self.ignore_pause_next_tick = true,
- KeyCode::KeyQ if pressed && !repeat => self.input.trigger_test_1 = true,
+ KeyCode::Digit1 if pressed && !repeat => self.input.trigger_test_1 = true,
+ KeyCode::Digit2 if pressed && !repeat => self.input.trigger_test_2 = 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 = self.camera.as_mut().map(|camera| {
- camera.screen_position_to_world(position.x as f32, position.y as f32)
- })
+
+ if let Some(camera) = &mut self.camera {
+ let world_pos =
+ camera.screen_position_to_world(position.x as f32, position.y as f32);
+
+ self.input.last_mouse_world_pos = Some(world_pos);
+ let ((cx, cy), (lx, ly)) =
+ World::split_game_position(world_pos.0 as i32, world_pos.1 as i32);
+ self.input.last_mouse_chunk_pos = Some((cx, cy));
+ self.input.last_mouse_local_pos = Some((lx, ly));
+ }
}
WindowEvent::MouseInput { state, button, .. } => {
if button == MouseButton::Left {