diff --git a/comfy-core/src/global_state.rs b/comfy-core/src/global_state.rs index 72ae993..deba109 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)) } @@ -103,6 +102,8 @@ pub struct GlobalState { pub mouse_locked: bool, pub cursor_hidden: bool, + pub touch_locations: HashMap, + pub egui_scale_factor: f32, pub frame: u32, diff --git a/comfy-core/src/input.rs b/comfy-core/src/input.rs index 4062532..0a4ad7c 100644 --- a/comfy-core/src/input.rs +++ b/comfy-core/src/input.rs @@ -36,6 +36,10 @@ pub fn is_key_down(keycode: KeyCode) -> bool { GLOBAL_STATE.borrow().pressed.contains(&keycode) } +pub fn get_touch_locations() -> Vec { + GLOBAL_STATE.borrow().touch_locations.clone().into_values().collect() +} + #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub enum MouseButton { Left, diff --git a/comfy-wgpu/src/device.rs b/comfy-wgpu/src/device.rs index b44fcb2..0bdbcb5 100644 --- a/comfy-wgpu/src/device.rs +++ b/comfy-wgpu/src/device.rs @@ -94,8 +94,7 @@ pub async fn create_graphics_context(window: &Window) -> GraphicsContext { }; #[cfg(not(target_arch = "wasm32"))] - let surface_usage = - wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC; + let surface_usage = wgpu::TextureUsages::RENDER_ATTACHMENT; #[cfg(target_arch = "wasm32")] let surface_usage = wgpu::TextureUsages::RENDER_ATTACHMENT; diff --git a/comfy/src/game_loop.rs b/comfy/src/game_loop.rs index 0550883..929faa7 100644 --- a/comfy/src/game_loop.rs +++ b/comfy/src/game_loop.rs @@ -181,7 +181,6 @@ pub async fn run_comfy_main_async( .set_cursor_visible(!global_state.cursor_hidden); } - set_frame_time(frame_start.elapsed().as_secs_f32()); inc_frame_num(); @@ -230,6 +229,31 @@ pub async fn run_comfy_main_async( } } + WindowEvent::Touch(touch_event) => { + match touch_event.phase { + winit::event::TouchPhase::Started + | winit::event::TouchPhase::Moved => { + GLOBAL_STATE + .borrow_mut() + .touch_locations + .insert( + touch_event.id, + Vec2 { + x: touch_event.location.x as f32, + y: touch_event.location.y as f32, + }, + ); + } + winit::event::TouchPhase::Ended + | winit::event::TouchPhase::Cancelled => { + GLOBAL_STATE + .borrow_mut() + .touch_locations + .remove(&touch_event.id); + } + } + } + WindowEvent::CursorMoved { position, .. } => { GLOBAL_STATE.borrow_mut().mouse_position = vec2(position.x as f32, position.y as f32); @@ -290,8 +314,8 @@ pub async fn run_comfy_main_async( } WindowEvent::Resized(physical_size) => { - if physical_size.width > min_resolution.0 && - physical_size.height > min_resolution.1 + if physical_size.width > min_resolution.0 + && physical_size.height > min_resolution.1 { engine.resize(uvec2( physical_size.width,