diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b36dd6..c61f291 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,10 +49,12 @@ - Upgraded `wgpu: 0.18 -> 0.19.3, winit: 0.28 -> 0.29, egui: 0.24 -> 0.26`. - Made `wgpu::PowerPreference` configurable & default to `None`, with the hope of fixing a potential issue where users have their dedicated GPU disabled on a dual GPU setup. -- Add option to override `max_texture_dimension_2d` in `GameConfig`, this is useful for games that want to support +- Added option to override `max_texture_dimension_2d` in `GameConfig`, this is useful for games that want to support resolutions higher than 4K. It's not entirely clear to me whether we can safely just raise this and still work on all machines, hence why it becomes an optional override. We're doing some more testing on this in our game, and if it'll be safe we'll also change the default. +- Added `mouse_input_this_frame()` and `mouse_moved_this_frame()` for determining whether the mouse had any input + in the current frame, or whether it was moved. # v0.3.0 diff --git a/comfy-core/src/camera.rs b/comfy-core/src/camera.rs index dc43262..e149dbe 100644 --- a/comfy-core/src/camera.rs +++ b/comfy-core/src/camera.rs @@ -44,6 +44,16 @@ pub fn screen_height() -> f32 { GLOBAL_STATE.borrow().screen_size.y } +/// Returns true if there was any mouse input during the current frame. +pub fn mouse_input_this_frame() -> bool { + GLOBAL_STATE.borrow().mouse_input_this_frame +} + +/// Returns true if the mouse was moved during the current frame. +pub fn mouse_moved_this_frame() -> bool { + GLOBAL_STATE.borrow().mouse_moved_this_frame +} + pub fn screenshake(timer: f32, amount: f32) { let mut camera = main_camera_mut(); diff --git a/comfy-core/src/global_state.rs b/comfy-core/src/global_state.rs index 72ae993..427fa61 100644 --- a/comfy-core/src/global_state.rs +++ b/comfy-core/src/global_state.rs @@ -49,7 +49,6 @@ pub fn inc_assets_loaded(newly_loaded_count: usize) { ASSETS_LOADED.fetch_add(newly_loaded_count, Ordering::SeqCst); } - pub fn frame_time() -> f32 { f32::from_bits(FRAME_TIME.load(Ordering::SeqCst)) } @@ -100,6 +99,9 @@ pub struct GlobalState { pub mouse_rel: IVec2, pub mouse_world: Vec2, + pub mouse_moved_this_frame: bool, + pub mouse_input_this_frame: bool, + pub mouse_locked: bool, pub cursor_hidden: bool, diff --git a/comfy/src/game_loop.rs b/comfy/src/game_loop.rs index 0968465..74aff27 100644 --- a/comfy/src/game_loop.rs +++ b/comfy/src/game_loop.rs @@ -188,6 +188,8 @@ pub async fn run_comfy_main_async( global_state.mouse_just_pressed.clear(); global_state.mouse_just_released.clear(); global_state.mouse_wheel = (0.0, 0.0); + global_state.mouse_input_this_frame = false; + global_state.mouse_moved_this_frame = false; engine .renderer @@ -251,11 +253,15 @@ pub async fn run_comfy_main_async( match event { WindowEvent::CursorMoved { position, .. } => { - GLOBAL_STATE.borrow_mut().mouse_position = + let mut global_state = GLOBAL_STATE.borrow_mut(); + + global_state.mouse_input_this_frame = true; + global_state.mouse_moved_this_frame = true; + global_state.mouse_position = vec2(position.x as f32, position.y as f32); } - WindowEvent::MouseInput { state, button, .. } => { + WindowEvent::MouseInput { state, button, .. } => {\ let quad_button = match button { winit::event::MouseButton::Left => { MouseButton::Left @@ -279,6 +285,8 @@ pub async fn run_comfy_main_async( let mut global_state = GLOBAL_STATE.borrow_mut(); + global_state.mouse_input_this_frame = true; + match state { ElementState::Pressed => { global_state @@ -305,6 +313,8 @@ pub async fn run_comfy_main_async( WindowEvent::MouseWheel { delta, .. } => { let mut global_state = GLOBAL_STATE.borrow_mut(); + global_state.mouse_input_this_frame = true; + match delta { MouseScrollDelta::LineDelta(x, y) => { global_state.mouse_wheel = (*x, *y);