|
|
|
@ -36,7 +36,8 @@ 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};
|
|
|
|
|
use gilrs::{Gilrs, Button, Event as GilEvent, GamepadId, Gamepad};
|
|
|
|
|
use crate::util::tr_event::TrEvent;
|
|
|
|
|
|
|
|
|
|
pub mod util;
|
|
|
|
|
pub mod vkprocessor;
|
|
|
|
@ -44,6 +45,36 @@ pub mod drawables;
|
|
|
|
|
pub mod canvas;
|
|
|
|
|
pub mod compute;
|
|
|
|
|
|
|
|
|
|
pub mod button_m {
|
|
|
|
|
use crate::drawables::rect::Rect;
|
|
|
|
|
use crate::drawables::sprite::Sprite;
|
|
|
|
|
use std::collections::HashSet;
|
|
|
|
|
use crate::canvas::canvas_frame::Drawable;
|
|
|
|
|
use crate::util::vertex::VertexTypes;
|
|
|
|
|
|
|
|
|
|
// Should I force these to be drawables
|
|
|
|
|
// or better, how do I force these to be drawables
|
|
|
|
|
enum GuiElements {
|
|
|
|
|
HANDLE(Rect),
|
|
|
|
|
GUIDE(Sprite)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Slider {
|
|
|
|
|
sprites: HashSet<GuiElements>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drawable for Slider {
|
|
|
|
|
fn get(&self) -> Vec<VertexTypes> {
|
|
|
|
|
|
|
|
|
|
self.sprites.into()
|
|
|
|
|
// self.sprites.iter().map(|v| {
|
|
|
|
|
//
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
pub fn main() {
|
|
|
|
|
hprof::start_frame();
|
|
|
|
|
|
|
|
|
@ -58,7 +89,7 @@ pub fn main() {
|
|
|
|
|
println!("Debug callback: {:?}", msg.description);
|
|
|
|
|
}).ok();
|
|
|
|
|
|
|
|
|
|
let mut events_loop = EventLoop::new();
|
|
|
|
|
let mut events_loop = EventLoop::<TrEvent>::with_user_event();
|
|
|
|
|
|
|
|
|
|
let mut surface = WindowBuilder::new()
|
|
|
|
|
.with_inner_size(LogicalSize::new(800, 800))
|
|
|
|
@ -69,7 +100,6 @@ pub fn main() {
|
|
|
|
|
{
|
|
|
|
|
let g = hprof::enter("vulkan preload");
|
|
|
|
|
processor.create_swapchain(instance.clone(), surface.clone());
|
|
|
|
|
|
|
|
|
|
processor.preload_kernels();
|
|
|
|
|
processor.preload_shaders();
|
|
|
|
|
processor.preload_textures();
|
|
|
|
@ -119,6 +149,8 @@ pub fn main() {
|
|
|
|
|
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
|
|
|
|
let rect = Rect::new((-0.5, -0.5), (0.5, 0.5), 1);
|
|
|
|
|
|
|
|
|
|
// how do i register a sprite to get events...
|
|
|
|
|
// explicit is much easier
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
@ -129,33 +161,47 @@ pub fn main() {
|
|
|
|
|
|
|
|
|
|
let l = hprof::enter("Loop");
|
|
|
|
|
|
|
|
|
|
// while let true = processor.is_open() {
|
|
|
|
|
//
|
|
|
|
|
// // Take care of our timing
|
|
|
|
|
// {
|
|
|
|
|
// elapsed_time = timer.elap_time();
|
|
|
|
|
// delta_time = elapsed_time - current_time;
|
|
|
|
|
// current_time = elapsed_time;
|
|
|
|
|
// if delta_time > 0.02 {
|
|
|
|
|
// delta_time = 0.02;
|
|
|
|
|
// }
|
|
|
|
|
// accumulator_time += delta_time;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// while (accumulator_time - step_size) >= step_size {
|
|
|
|
|
// 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 event_loop_proxy = events_loop.create_proxy();
|
|
|
|
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
|
|
|
|
let mut gilrs = Gilrs::new().unwrap();
|
|
|
|
|
// Iterate over all connected gamepads
|
|
|
|
|
let mut gamepad : Option<Gamepad> = None;
|
|
|
|
|
for (_id, gamepad_) in gilrs.gamepads() {
|
|
|
|
|
if gamepad_.name() == "PS4" {
|
|
|
|
|
gamepad = Some(gamepad_);
|
|
|
|
|
}
|
|
|
|
|
println!("{} is {:?} {:?}", gamepad_.name(), gamepad_.power_info(), gamepad_.id());
|
|
|
|
|
}
|
|
|
|
|
let mut active_gamepad = None;
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
|
|
|
|
|
let mut active_gamepad = None;
|
|
|
|
|
while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
|
|
|
|
|
println!("{:?} New event from {}: {:?}", time, id, event);
|
|
|
|
|
active_gamepad = Some(id);
|
|
|
|
|
event_loop_proxy.send_event(TrEvent::GamepadEvent {
|
|
|
|
|
gil_event: GilEvent {id, event, time}
|
|
|
|
|
}).ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// // 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)");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Events loop is borrowed from the surface
|
|
|
|
|
events_loop.run(move |event, _, control_flow| {
|
|
|
|
|
*control_flow = ControlFlow::Poll;
|
|
|
|
|
|
|
|
|
|
match event {
|
|
|
|
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
|
|
|
|
|
{
|
|
|
|
@ -164,7 +210,27 @@ pub fn main() {
|
|
|
|
|
Event::WindowEvent { event: WindowEvent::Resized(_), .. } => {
|
|
|
|
|
processor.swapchain_recreate_needed = true;
|
|
|
|
|
}
|
|
|
|
|
Event::UserEvent(TrEvent::KeyHeldEvent { }) => {
|
|
|
|
|
}
|
|
|
|
|
Event::MainEventsCleared => {
|
|
|
|
|
|
|
|
|
|
// while let true = processor.is_open() {
|
|
|
|
|
//
|
|
|
|
|
// // Take care of our timing
|
|
|
|
|
// {
|
|
|
|
|
// elapsed_time = timer.elap_time();
|
|
|
|
|
// delta_time = elapsed_time - current_time;
|
|
|
|
|
// current_time = elapsed_time;
|
|
|
|
|
// if delta_time > 0.02 {
|
|
|
|
|
// delta_time = 0.02;
|
|
|
|
|
// }
|
|
|
|
|
// accumulator_time += delta_time;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// while (accumulator_time - step_size) >= step_size {
|
|
|
|
|
// accumulator_time -= step_size;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
let mut canvas_frame = CanvasFrame::default();
|
|
|
|
|
canvas_frame.draw(&funky_sprite);
|
|
|
|
|
canvas_frame.draw(&text_sprite);
|
|
|
|
@ -181,18 +247,6 @@ 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() {
|
|
|
|
@ -210,13 +264,29 @@ pub fn main() {
|
|
|
|
|
_ => ()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => {
|
|
|
|
|
}
|
|
|
|
|
_ => ()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// bucket the events out, but not really
|
|
|
|
|
match event {
|
|
|
|
|
_ => {
|
|
|
|
|
funky_sprite.notify(&event);
|
|
|
|
|
}
|
|
|
|
|
Event::NewEvents(_) => {},
|
|
|
|
|
Event::WindowEvent { window_id, event } => {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
Event::DeviceEvent { device_id, event } => {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
Event::UserEvent(tr_event) => {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
Event::Suspended => {},
|
|
|
|
|
Event::Resumed => {},
|
|
|
|
|
Event::MainEventsCleared => {},
|
|
|
|
|
Event::RedrawRequested(_) => {},
|
|
|
|
|
Event::RedrawEventsCleared => {},
|
|
|
|
|
Event::LoopDestroyed => {},
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|