mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-25 21:28:20 -06:00
rename proces_glutin_events
to process_winit_events
This commit is contained in:
parent
2ba011a89b
commit
f928970afd
|
@ -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::<NonSendSync<UniqueView<Renderer>>>().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::<SparseSet<EventComponent>>();
|
||||
}
|
||||
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::<NonSendSync<UniqueView<Renderer>>>().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::<SparseSet<EventComponent>>();
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue