rename proces_glutin_events to process_winit_events

This commit is contained in:
griffi-gh 2024-02-12 23:53:14 +01:00
parent 2ba011a89b
commit f928970afd
2 changed files with 108 additions and 108 deletions

View file

@ -1,106 +1,106 @@
use glam::UVec2; use glam::UVec2;
use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView}; use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView};
use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch, RawKeyEvent, TouchPhase}; use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch};
use crate::rendering::Renderer; use crate::rendering::Renderer;
pub mod player_actions; pub mod player_actions;
#[derive(Component, Clone, Copy, Debug, Default)] #[derive(Component, Clone, Copy, Debug, Default)]
pub struct EventComponent; pub struct EventComponent;
#[derive(Component, Clone, Copy, Debug, Default)] #[derive(Component, Clone, Copy, Debug, Default)]
pub struct OnBeforeExitEvent; pub struct OnBeforeExitEvent;
#[derive(Component, Clone, Debug)] #[derive(Component, Clone, Debug)]
pub struct InputDeviceEvent{ pub struct InputDeviceEvent{
pub device_id: DeviceId, pub device_id: DeviceId,
pub event: DeviceEvent pub event: DeviceEvent
} }
#[derive(Component, Clone, Copy, Debug)] #[derive(Component, Clone, Copy, Debug)]
#[repr(transparent)] #[repr(transparent)]
pub struct TouchEvent(pub Touch); pub struct TouchEvent(pub Touch);
#[derive(Component, Clone, Copy, Debug, Default)] #[derive(Component, Clone, Copy, Debug, Default)]
pub struct WindowResizedEvent(pub UVec2); pub struct WindowResizedEvent(pub UVec2);
pub fn process_glutin_events(world: &mut World, event: &Event<()>) { pub fn process_winit_events(world: &mut World, event: &Event<()>) {
#[allow(clippy::collapsible_match, clippy::single_match)] #[allow(clippy::collapsible_match, clippy::single_match)]
match event { match event {
Event::WindowEvent { window_id: _, event } => match event { Event::WindowEvent { window_id: _, event } => match event {
WindowEvent::Resized(size) => { WindowEvent::Resized(size) => {
world.add_entity(( world.add_entity((
EventComponent, EventComponent,
WindowResizedEvent(UVec2::new(size.width as _, size.height as _)) WindowResizedEvent(UVec2::new(size.width as _, size.height as _))
)); ));
}, },
#[cfg(not(feature = "raw-evt"))] #[cfg(not(feature = "raw-evt"))]
WindowEvent::KeyboardInput { device_id, event, .. } => { WindowEvent::KeyboardInput { device_id, event, .. } => {
world.add_entity(( world.add_entity((
EventComponent, EventComponent,
InputDeviceEvent { InputDeviceEvent {
device_id: *device_id, device_id: *device_id,
event: DeviceEvent::Key(RawKeyEvent { event: DeviceEvent::Key(RawKeyEvent {
physical_key: event.physical_key, physical_key: event.physical_key,
state: event.state, state: event.state,
}) })
} }
)); ));
} }
WindowEvent::Touch(touch) => { WindowEvent::Touch(touch) => {
// if matches!(touch.phase, TouchPhase::Started | TouchPhase::Cancelled | TouchPhase::Ended) { // if matches!(touch.phase, TouchPhase::Started | TouchPhase::Cancelled | TouchPhase::Ended) {
// println!("TOUCH ==================== {:#?}", touch); // println!("TOUCH ==================== {:#?}", touch);
// } else { // } else {
// println!("TOUCH MOVED {:?} {}", touch.phase, touch.id); // println!("TOUCH MOVED {:?} {}", touch.phase, touch.id);
// } // }
world.add_entity(( world.add_entity((
EventComponent, EventComponent,
TouchEvent(*touch) TouchEvent(*touch)
)); ));
} }
_ => () _ => ()
}, },
#[cfg(feature = "raw-evt")] #[cfg(feature = "raw-evt")]
Event::DeviceEvent { device_id, event } => { Event::DeviceEvent { device_id, event } => {
world.add_entity(( world.add_entity((
EventComponent, EventComponent,
InputDeviceEvent { InputDeviceEvent {
device_id: *device_id, device_id: *device_id,
event: event.clone() event: event.clone()
} }
)); ));
}, },
Event::LoopExiting => { Event::LoopExiting => {
world.add_entity(( world.add_entity((
EventComponent, EventComponent,
OnBeforeExitEvent OnBeforeExitEvent
)); ));
}, },
_ => (), _ => (),
} }
} }
pub fn initial_resize_event( pub fn initial_resize_event(
mut storages: AllStoragesViewMut, mut storages: AllStoragesViewMut,
) { ) {
let (w, h) = { let (w, h) = {
let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap(); let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
renderer.display.get_framebuffer_dimensions() renderer.display.get_framebuffer_dimensions()
}; };
storages.add_entity(( storages.add_entity((
EventComponent, EventComponent,
WindowResizedEvent(UVec2::new(w, h)) WindowResizedEvent(UVec2::new(w, h))
)); ));
} }
pub fn clear_events( pub fn clear_events(
mut all_storages: AllStoragesViewMut, mut all_storages: AllStoragesViewMut,
) { ) {
all_storages.delete_any::<SparseSet<EventComponent>>(); all_storages.delete_any::<SparseSet<EventComponent>>();
} }

View file

@ -51,7 +51,7 @@ use settings::{load_settings, GameSettings};
use camera::compute_cameras; use camera::compute_cameras;
use events::{ use events::{
clear_events, clear_events,
process_glutin_events, process_winit_events,
initial_resize_event, initial_resize_event,
player_actions::generate_move_events, player_actions::generate_move_events,
}; };
@ -257,7 +257,7 @@ pub fn kubi_main(
window_target.set_control_flow(ControlFlow::Poll); 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)] #[allow(clippy::collapsible_match, clippy::single_match)]
match event { match event {