need to add gamepad events
This commit is contained in:
@@ -18,6 +18,7 @@ vulkano-win = "0.19.0"
|
||||
#shade_runner = {version = "0.1.1", git = "https://github.com/MitchellHansen/shade_runner"}
|
||||
shade_runner = {path = "../shade_runner"}
|
||||
|
||||
gilrs = "0.7.2"
|
||||
cgmath = "0.17.0"
|
||||
simple-stopwatch="0.1.4"
|
||||
nalgebra = "0.18.0"
|
||||
|
||||
28
src/main.rs
28
src/main.rs
@@ -36,6 +36,7 @@ use crate::util::timer::Timer;
|
||||
use crate::util::vertex::{TextureVertex3D, VertexTypes};
|
||||
use crate::vkprocessor::VkProcessor;
|
||||
use std::path::Path;
|
||||
use gilrs::{Gilrs, Button, Event as GilEvent};
|
||||
|
||||
pub mod util;
|
||||
pub mod vkprocessor;
|
||||
@@ -145,16 +146,13 @@ pub fn main() {
|
||||
// accumulator_time -= step_size;
|
||||
// }
|
||||
|
||||
let mut gilrs = Gilrs::new().unwrap();
|
||||
// Iterate over all connected gamepads
|
||||
for (_id, gamepad) in gilrs.gamepads() {
|
||||
println!("{} is {:?}", gamepad.name(), gamepad.power_info());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let mut active_gamepad = None;
|
||||
|
||||
// Events loop is borrowed from the surface
|
||||
events_loop.run(move |event, _, control_flow| {
|
||||
@@ -183,6 +181,18 @@ pub fn main() {
|
||||
compu_frame);
|
||||
}
|
||||
|
||||
while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
|
||||
println!("{:?} New event from {}: {:?}", time, id, event);
|
||||
active_gamepad = Some(id);
|
||||
}
|
||||
|
||||
// You can also use cached gamepad state
|
||||
if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) {
|
||||
if gamepad.is_pressed(Button::South) {
|
||||
println!("Button South is pressed (XBox - A, PS - X)");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
|
||||
match keyboard_input.virtual_keycode.unwrap() {
|
||||
|
||||
@@ -5,6 +5,7 @@ use std::path::PathBuf;
|
||||
|
||||
pub mod timer;
|
||||
pub mod vertex;
|
||||
pub mod tr_event;
|
||||
|
||||
pub fn load_raw(filename: String) -> (Vec<u8>, (u32,u32)) {
|
||||
|
||||
|
||||
18
src/util/tr_event.rs
Normal file
18
src/util/tr_event.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use winit::window::WindowId;
|
||||
use winit::event::{WindowEvent, DeviceId, DeviceEvent};
|
||||
|
||||
enum TrEvent {
|
||||
|
||||
// WindowEvent {
|
||||
// window_id: WindowId,
|
||||
// event: WindowEvent<'a>,
|
||||
// },
|
||||
|
||||
/// Emitted when the OS sends an event to a device.
|
||||
DeviceEvent {
|
||||
device_id: DeviceId,
|
||||
event: DeviceEvent,
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user