brainstorming on how to bucket and hand out events

master
mitchellhansen 4 years ago
parent 2ea20c4c0a
commit 0caa685b23

@ -10,20 +10,24 @@ extern crate nalgebra as na;
extern crate rand; extern crate rand;
extern crate time; extern crate time;
use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use gilrs::{Button, Event as GilEvent, Gamepad, GamepadId, Gilrs};
use vulkano::instance::debug::DebugCallback; use vulkano::instance::debug::DebugCallback;
use vulkano::instance::Instance; use vulkano::instance::Instance;
use vulkano::sync; use vulkano::sync;
use vulkano::sync::GpuFuture; use vulkano::sync::GpuFuture;
use vulkano_win::VkSurfaceBuild; use vulkano_win::VkSurfaceBuild;
use winit::dpi::LogicalSize; use winit::dpi::LogicalSize;
use winit::event::{DeviceEvent, ElementState, Event, VirtualKeyCode, WindowEvent, MouseButton}; use winit::event::{DeviceEvent, ElementState, Event, MouseButton, VirtualKeyCode, WindowEvent};
use winit::event_loop::{EventLoop, ControlFlow, EventLoopProxy}; use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
use winit::platform::unix::WindowBuilderExtUnix; use winit::platform::unix::WindowBuilderExtUnix;
use winit::window::WindowBuilder; use winit::window::WindowBuilder;
use crate::button_m::Slider;
use crate::canvas::canvas_frame::{CanvasFrame, Drawable, Eventable}; use crate::canvas::canvas_frame::{CanvasFrame, Drawable, Eventable};
use crate::canvas::canvas_state::CanvasState;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasTextureHandle, Handle}; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasTextureHandle, Handle};
use crate::compute::compu_frame::CompuFrame; use crate::compute::compu_frame::CompuFrame;
use crate::compute::managed::handles::{CompuBufferHandle, CompuKernelHandle}; use crate::compute::managed::handles::{CompuBufferHandle, CompuKernelHandle};
@ -33,13 +37,9 @@ use crate::drawables::sprite::Sprite;
use crate::drawables::text::Text; use crate::drawables::text::Text;
use crate::util::load_raw; use crate::util::load_raw;
use crate::util::timer::Timer; use crate::util::timer::Timer;
use crate::util::tr_event::TrEvent;
use crate::util::vertex::{TextureVertex3D, VertexType}; use crate::util::vertex::{TextureVertex3D, VertexType};
use crate::vkprocessor::VkProcessor; use crate::vkprocessor::VkProcessor;
use std::path::Path;
use gilrs::{Gilrs, Button, Event as GilEvent, GamepadId, Gamepad};
use crate::util::tr_event::TrEvent;
use crate::button_m::Slider;
use crate::canvas::canvas_state::CanvasState;
pub mod util; pub mod util;
pub mod vkprocessor; pub mod vkprocessor;
@ -48,16 +48,18 @@ pub mod canvas;
pub mod compute; pub mod compute;
pub mod button_m { pub mod button_m {
use crate::drawables::rect::Rect;
use crate::drawables::sprite::Sprite;
use std::collections::HashSet; use std::collections::HashSet;
use winit::event::Event;
use crate::canvas::canvas_frame::{Drawable, Eventable}; use crate::canvas::canvas_frame::{Drawable, Eventable};
use crate::drawables::rect::Rect;
use crate::drawables::sprite::Sprite;
use crate::util::vertex::VertexType; use crate::util::vertex::VertexType;
use winit::event::Event;
pub struct Slider { pub struct Slider {
handle : Rect, handle: Rect,
guide : Vec<Rect>, guide: Vec<Rect>,
scaler: u32, scaler: u32,
position: (f32, f32), position: (f32, f32),
@ -66,7 +68,7 @@ pub mod button_m {
} }
impl Slider { impl Slider {
pub fn new(size: (f32, f32), position : (f32, f32), value: u16) -> Slider { pub fn new(size: (f32, f32), position: (f32, f32), value: u16) -> Slider {
// render the guide first // render the guide first
@ -89,7 +91,7 @@ pub mod button_m {
scaler: 255, scaler: 255,
position, position,
size, size,
value value,
} }
} }
} }
@ -109,8 +111,8 @@ pub mod button_m {
unimplemented!() unimplemented!()
} }
} }
} }
pub fn main() { pub fn main() {
hprof::start_frame(); hprof::start_frame();
@ -185,13 +187,13 @@ pub fn main() {
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone()); let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
let slider = button_m::Slider::new((0.3, 0.04), (-0.5,-0.3), 30000); let slider = button_m::Slider::new((0.3, 0.04), (-0.5, -0.3), 30000);
// how do i register a sprite to get events... // how do i register a sprite to get events...
// explicit is much easier // explicit is much easieri.lo
//let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone()); //let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
// let text_sprite = Text::new((-0.1, -0.1), (10.0, 10.0), 1); // let text_sprite = Text::new((-0.1, -0.1), (10.0, 10.0), 1);
//let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0)); //let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
drop(q2); drop(q2);
@ -202,10 +204,9 @@ pub fn main() {
let event_loop_proxy = events_loop.create_proxy(); let event_loop_proxy = events_loop.create_proxy();
std::thread::spawn(move || { std::thread::spawn(move || {
let mut gilrs = Gilrs::new().unwrap(); let mut gilrs = Gilrs::new().unwrap();
// Iterate over all connected gamepads // Iterate over all connected gamepads
let mut gamepad : Option<Gamepad> = None; let mut gamepad: Option<Gamepad> = None;
for (_id, gamepad_) in gilrs.gamepads() { for (_id, gamepad_) in gilrs.gamepads() {
if gamepad_.name() == "PS4" { if gamepad_.name() == "PS4" {
gamepad = Some(gamepad_); gamepad = Some(gamepad_);
@ -215,12 +216,11 @@ pub fn main() {
let mut active_gamepad = None; let mut active_gamepad = None;
loop { loop {
while let Some(GilEvent { id, event, time }) = gilrs.next_event() { while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
println!("{:?} New event from {}: {:?}", time, id, event); println!("{:?} New event from {}: {:?}", time, id, event);
active_gamepad = Some(id); active_gamepad = Some(id);
event_loop_proxy.send_event(TrEvent::GamepadEvent { event_loop_proxy.send_event(TrEvent::GamepadEvent {
gil_event: GilEvent {id, event, time} gil_event: GilEvent { id, event, time }
}).ok(); }).ok();
} }
@ -232,10 +232,11 @@ pub fn main() {
// } // }
std::thread::sleep(std::time::Duration::from_millis(50)); std::thread::sleep(std::time::Duration::from_millis(50));
} }
}); });
let mut event_stack = Vec::new();
// Events loop is borrowed from the surface // Events loop is borrowed from the surface
events_loop.run(move |event, _, control_flow| { events_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll; *control_flow = ControlFlow::Poll;
@ -243,28 +244,32 @@ pub fn main() {
let mut previous_canvas = CanvasFrame::default(); let mut previous_canvas = CanvasFrame::default();
match event { match event {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
{ *control_flow = ControlFlow::Exit
*control_flow = ControlFlow::Exit }
}
Event::WindowEvent { event: WindowEvent::Resized(_), .. } => { Event::WindowEvent { event: WindowEvent::Resized(_), .. } => {
processor.swapchain_recreate_needed = true; processor.swapchain_recreate_needed = true;
} }
Event::UserEvent(TrEvent::KeyHeldEvent { }) => { Event::WindowEvent {
} event: WindowEvent::MouseInput {
Event::UserEvent(TrEvent::MouseHeldEvent { }) => { device_id, state, button, modifiers
} }, ..
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => { } => {
event_stack.push(event.clone());
} }
Event::UserEvent(TrEvent::KeyHeldEvent {}) => {}
Event::UserEvent(TrEvent::MouseHeldEvent {}) => {}
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => {}
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => { Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
event_stack.push(event);
match keyboard_input.virtual_keycode.unwrap() { match keyboard_input.virtual_keycode.unwrap() {
VirtualKeyCode::A => { VirtualKeyCode::A => {
if keyboard_input.state == ElementState::Pressed { if keyboard_input.state == ElementState::Pressed {
// processor.save_edges_image(); // processor.save_edges_image();
} }
}, }
VirtualKeyCode::P => { VirtualKeyCode::P => {
if keyboard_input.state == ElementState::Pressed { if keyboard_input.state == ElementState::Pressed {
let data = processor.read_compute_buffer(compute_buffer.clone()); let data = processor.read_compute_buffer(compute_buffer.clone());
@ -309,29 +314,22 @@ pub fn main() {
canvas_frame, canvas_frame,
compu_frame); compu_frame);
} }
} }
_ => () _ => ()
} }
// bucket the events out, but not really // bucket the events out, but not really
match event { match event {
Event::NewEvents(_) => {}, Event::NewEvents(_) => {}
Event::WindowEvent { window_id, event } => { Event::WindowEvent { window_id, event } => {}
Event::DeviceEvent { device_id, event } => {}
}, Event::UserEvent(tr_event) => {}
Event::DeviceEvent { device_id, event } => { Event::Suspended => {}
Event::Resumed => {}
}, Event::MainEventsCleared => {}
Event::UserEvent(tr_event) => { Event::RedrawRequested(_) => {}
Event::RedrawEventsCleared => {}
}, Event::LoopDestroyed => {}
Event::Suspended => {},
Event::Resumed => {},
Event::MainEventsCleared => {},
Event::RedrawRequested(_) => {},
Event::RedrawEventsCleared => {},
Event::LoopDestroyed => {},
} }
}); });
@ -342,18 +340,13 @@ pub fn main() {
} }
pub fn click_test(event_loop_proxy: EventLoopProxy<TrEvent>, canvas_state: &CanvasState) {
// for i in canvas_state. {
pub fn click_test(event_loop_proxy : EventLoopProxy<TrEvent>, canvas_state: &CanvasState) { // event_loop_proxy.send_event(TrEvent::MouseClickEvent {
// position: (0.0, 0.0),
for i in canvas_state. { // button: MouseButton::Left,
// }).ok();
event_loop_proxy.send_event(TrEvent::MouseClickEvent { // }
position: (0.0, 0.0),
button: MouseButton::Left
}).ok();
}
} }

Loading…
Cancel
Save