From f928970afdd0a083c9dc66062dc03b34a5646eb3 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 12 Feb 2024 23:53:14 +0100 Subject: [PATCH] rename `proces_glutin_events` to `process_winit_events` --- kubi/src/events.rs | 212 ++++++++++++++++++++++----------------------- kubi/src/lib.rs | 4 +- 2 files changed, 108 insertions(+), 108 deletions(-) diff --git a/kubi/src/events.rs b/kubi/src/events.rs index 637b5e3..fe03a7b 100644 --- a/kubi/src/events.rs +++ b/kubi/src/events.rs @@ -1,106 +1,106 @@ -use glam::UVec2; -use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView}; -use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch, RawKeyEvent, TouchPhase}; -use crate::rendering::Renderer; - -pub mod player_actions; - -#[derive(Component, Clone, Copy, Debug, Default)] -pub struct EventComponent; - -#[derive(Component, Clone, Copy, Debug, Default)] -pub struct OnBeforeExitEvent; - -#[derive(Component, Clone, Debug)] -pub struct InputDeviceEvent{ - pub device_id: DeviceId, - pub event: DeviceEvent -} - -#[derive(Component, Clone, Copy, Debug)] -#[repr(transparent)] -pub struct TouchEvent(pub Touch); - -#[derive(Component, Clone, Copy, Debug, Default)] -pub struct WindowResizedEvent(pub UVec2); - -pub fn process_glutin_events(world: &mut World, event: &Event<()>) { - #[allow(clippy::collapsible_match, clippy::single_match)] - match event { - Event::WindowEvent { window_id: _, event } => match event { - WindowEvent::Resized(size) => { - world.add_entity(( - EventComponent, - WindowResizedEvent(UVec2::new(size.width as _, size.height as _)) - )); - }, - - #[cfg(not(feature = "raw-evt"))] - WindowEvent::KeyboardInput { device_id, event, .. } => { - world.add_entity(( - EventComponent, - InputDeviceEvent { - device_id: *device_id, - event: DeviceEvent::Key(RawKeyEvent { - physical_key: event.physical_key, - state: event.state, - }) - } - )); - } - - WindowEvent::Touch(touch) => { - // if matches!(touch.phase, TouchPhase::Started | TouchPhase::Cancelled | TouchPhase::Ended) { - // println!("TOUCH ==================== {:#?}", touch); - // } else { - // println!("TOUCH MOVED {:?} {}", touch.phase, touch.id); - // } - world.add_entity(( - EventComponent, - TouchEvent(*touch) - )); - } - - _ => () - }, - - #[cfg(feature = "raw-evt")] - Event::DeviceEvent { device_id, event } => { - world.add_entity(( - EventComponent, - InputDeviceEvent { - device_id: *device_id, - event: event.clone() - } - )); - }, - - Event::LoopExiting => { - world.add_entity(( - EventComponent, - OnBeforeExitEvent - )); - }, - - _ => (), - } -} - -pub fn initial_resize_event( - mut storages: AllStoragesViewMut, -) { - let (w, h) = { - let renderer = storages.borrow::>>().unwrap(); - renderer.display.get_framebuffer_dimensions() - }; - storages.add_entity(( - EventComponent, - WindowResizedEvent(UVec2::new(w, h)) - )); -} - -pub fn clear_events( - mut all_storages: AllStoragesViewMut, -) { - all_storages.delete_any::>(); -} +use glam::UVec2; +use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView}; +use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch}; +use crate::rendering::Renderer; + +pub mod player_actions; + +#[derive(Component, Clone, Copy, Debug, Default)] +pub struct EventComponent; + +#[derive(Component, Clone, Copy, Debug, Default)] +pub struct OnBeforeExitEvent; + +#[derive(Component, Clone, Debug)] +pub struct InputDeviceEvent{ + pub device_id: DeviceId, + pub event: DeviceEvent +} + +#[derive(Component, Clone, Copy, Debug)] +#[repr(transparent)] +pub struct TouchEvent(pub Touch); + +#[derive(Component, Clone, Copy, Debug, Default)] +pub struct WindowResizedEvent(pub UVec2); + +pub fn process_winit_events(world: &mut World, event: &Event<()>) { + #[allow(clippy::collapsible_match, clippy::single_match)] + match event { + Event::WindowEvent { window_id: _, event } => match event { + WindowEvent::Resized(size) => { + world.add_entity(( + EventComponent, + WindowResizedEvent(UVec2::new(size.width as _, size.height as _)) + )); + }, + + #[cfg(not(feature = "raw-evt"))] + WindowEvent::KeyboardInput { device_id, event, .. } => { + world.add_entity(( + EventComponent, + InputDeviceEvent { + device_id: *device_id, + event: DeviceEvent::Key(RawKeyEvent { + physical_key: event.physical_key, + state: event.state, + }) + } + )); + } + + WindowEvent::Touch(touch) => { + // if matches!(touch.phase, TouchPhase::Started | TouchPhase::Cancelled | TouchPhase::Ended) { + // println!("TOUCH ==================== {:#?}", touch); + // } else { + // println!("TOUCH MOVED {:?} {}", touch.phase, touch.id); + // } + world.add_entity(( + EventComponent, + TouchEvent(*touch) + )); + } + + _ => () + }, + + #[cfg(feature = "raw-evt")] + Event::DeviceEvent { device_id, event } => { + world.add_entity(( + EventComponent, + InputDeviceEvent { + device_id: *device_id, + event: event.clone() + } + )); + }, + + Event::LoopExiting => { + world.add_entity(( + EventComponent, + OnBeforeExitEvent + )); + }, + + _ => (), + } +} + +pub fn initial_resize_event( + mut storages: AllStoragesViewMut, +) { + let (w, h) = { + let renderer = storages.borrow::>>().unwrap(); + renderer.display.get_framebuffer_dimensions() + }; + storages.add_entity(( + EventComponent, + WindowResizedEvent(UVec2::new(w, h)) + )); +} + +pub fn clear_events( + mut all_storages: AllStoragesViewMut, +) { + all_storages.delete_any::>(); +} diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index fc3e25c..eb0c821 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -51,7 +51,7 @@ use settings::{load_settings, GameSettings}; use camera::compute_cameras; use events::{ clear_events, - process_glutin_events, + process_winit_events, initial_resize_event, player_actions::generate_move_events, }; @@ -257,7 +257,7 @@ pub fn kubi_main( window_target.set_control_flow(ControlFlow::Poll); - process_glutin_events(&mut world, &event); + process_winit_events(&mut world, &event); #[allow(clippy::collapsible_match, clippy::single_match)] match event {