added event translation
This commit is contained in:
90
src/main.rs
90
src/main.rs
@@ -36,7 +36,7 @@ use crate::drawables::sprite::Sprite;
|
||||
use crate::drawables::text::Text;
|
||||
use crate::util::load_raw;
|
||||
use crate::util::timer::Timer;
|
||||
use crate::util::tr_event::TrEvent;
|
||||
use crate::util::tr_event::{TrEventExtension, TrEvent};
|
||||
use crate::util::vertex::{TextureVertex3D, VertexTypeContainer};
|
||||
use crate::vkprocessor::VkProcessor;
|
||||
use crate::drawables::slider::Slider;
|
||||
@@ -53,7 +53,7 @@ use specs::prelude::*;
|
||||
use vulkano::swapchain::Surface;
|
||||
|
||||
|
||||
struct Draws(Box<dyn Drawable + Sync + Send>, Box<dyn Eventable<TrEvent> + Sync + Send>);
|
||||
struct Draws(Box<dyn Drawable + Sync + Send>, Box<dyn Eventable<TrEventExtension> + Sync + Send>);
|
||||
|
||||
impl Component for Draws {
|
||||
type Storage = VecStorage<Self>;
|
||||
@@ -125,7 +125,6 @@ impl<'a> System<'a> for RenderSystem {
|
||||
|
||||
for draw_data in (&draw).join() {
|
||||
let size = state.window_size.clone();
|
||||
|
||||
}
|
||||
|
||||
vk_processor.run(&state.surface.clone().unwrap(),
|
||||
@@ -145,13 +144,13 @@ impl<'a> System<'a> for EventSystem {
|
||||
);
|
||||
|
||||
fn run(&mut self, (mut draw, mut state, mut vk_processor): Self::SystemData) {
|
||||
|
||||
for draw_data in (&draw).join() {
|
||||
draw_data.1.notify()
|
||||
//draw_data.1.notify()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Eventt(u32);
|
||||
|
||||
pub fn main() {
|
||||
//hprof::start_frame();
|
||||
@@ -167,7 +166,7 @@ pub fn main() {
|
||||
println!("Debug callback: {:?}", msg.description);
|
||||
}).ok();
|
||||
|
||||
let mut events_loop = EventLoop::<TrEvent>::with_user_event();
|
||||
let mut events_loop = EventLoop::<TrEventExtension>::with_user_event();
|
||||
|
||||
let mut surface = WindowBuilder::new()
|
||||
.with_inner_size(LogicalSize::new(800, 800))
|
||||
@@ -223,6 +222,7 @@ pub fn main() {
|
||||
world.register::<Geom>();
|
||||
world.register::<Draws>();
|
||||
world.insert::<VkProcessor>(processor);
|
||||
world.insert::<Vec<TrEvent<TrEventExtension>>>(Vec::new());
|
||||
world.insert::<PersistentState>(PersistentState {
|
||||
surface: Some(surface.clone()),
|
||||
window_size: (0, 0),
|
||||
@@ -279,7 +279,7 @@ pub fn main() {
|
||||
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 {
|
||||
event_loop_proxy.send_event(TrEventExtension::GamepadEvent {
|
||||
gil_event: GilEvent { id, event, time }
|
||||
}).ok();
|
||||
}
|
||||
@@ -295,16 +295,18 @@ pub fn main() {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Events loop is borrowed from the surface
|
||||
events_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Poll;
|
||||
|
||||
|
||||
match event {
|
||||
Event::NewEvents(cause) => {
|
||||
if cause == StartCause::Init {
|
||||
world.write_resource::<PersistentState>()
|
||||
.window_size = surface.window().inner_size().into();
|
||||
} else {
|
||||
world.write_resource::<Vec<TrEvent<TrEventExtension>>>().clear();
|
||||
}
|
||||
}
|
||||
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
||||
@@ -316,37 +318,6 @@ pub fn main() {
|
||||
world.write_resource::<PersistentState>()
|
||||
.window_size = (new_size.width, new_size.height);
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::MouseInput {
|
||||
device_id, state, button, modifiers
|
||||
}, ..
|
||||
} => {}
|
||||
Event::UserEvent(TrEvent::KeyHeldEvent {}) => {}
|
||||
Event::UserEvent(TrEvent::MouseHeldEvent {}) => {}
|
||||
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => {}
|
||||
Event::DeviceEvent { device_id, event } => {
|
||||
match event {
|
||||
DeviceEvent::Key(keyboard_input) => {
|
||||
match keyboard_input.virtual_keycode.unwrap() {
|
||||
VirtualKeyCode::A => {
|
||||
if keyboard_input.state == ElementState::Pressed {}
|
||||
}
|
||||
VirtualKeyCode::S => {
|
||||
if keyboard_input.state == ElementState::Pressed {}
|
||||
}
|
||||
VirtualKeyCode::P => {
|
||||
if keyboard_input.state == ElementState::Pressed {
|
||||
let data = world.write_resource::<VkProcessor>().read_compute_buffer(compute_buffer.clone());
|
||||
image::save_buffer(&Path::new("image.png"), data.as_slice(), (image_data.1).0, (image_data.1).1, image::RGBA(8));
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Event::MainEventsCleared => {
|
||||
elapsed_time = timer.elap_time();
|
||||
delta_time = elapsed_time - current_time;
|
||||
@@ -357,16 +328,51 @@ pub fn main() {
|
||||
accumulator_time += delta_time;
|
||||
|
||||
// This dispatches all the systems in parallel (but blocking).
|
||||
world.write_resource::<PersistentState>().delta_time = delta_time;
|
||||
world.write_resource::<PersistentState>()
|
||||
.delta_time = delta_time;
|
||||
dispatcher.dispatch(&mut world);
|
||||
|
||||
// while (accumulator_time - step_size) >= step_size {
|
||||
// accumulator_time -= step_size;
|
||||
// }
|
||||
}
|
||||
_ => ()
|
||||
_ => {}
|
||||
}
|
||||
|
||||
world.write_resource::<Vec<TrEvent<TrEventExtension>>>().push(event.into());
|
||||
|
||||
//
|
||||
// match event {
|
||||
|
||||
// Event::UserEvent(TrEventExtension::KeyHeldEvent {}) => {}
|
||||
// Event::UserEvent(TrEventExtension::MouseHeldEvent {}) => {}
|
||||
// Event::UserEvent(TrEventExtension::GamepadEvent { gil_event }) => {}
|
||||
// Event::DeviceEvent { device_id, event } => {
|
||||
// match event {
|
||||
// DeviceEvent::Key(keyboard_input) => {
|
||||
// match keyboard_input.virtual_keycode.unwrap() {
|
||||
// VirtualKeyCode::A => {
|
||||
// if keyboard_input.state == ElementState::Pressed {}
|
||||
// }
|
||||
// VirtualKeyCode::S => {
|
||||
// if keyboard_input.state == ElementState::Pressed {}
|
||||
// }
|
||||
// VirtualKeyCode::P => {
|
||||
// if keyboard_input.state == ElementState::Pressed {
|
||||
// let data = world.write_resource::<VkProcessor>().read_compute_buffer(compute_buffer.clone());
|
||||
// image::save_buffer(&Path::new("image.png"), data.as_slice(), (image_data.1).0, (image_data.1).1, image::RGBA(8));
|
||||
// }
|
||||
// }
|
||||
// _ => ()
|
||||
// }
|
||||
// }
|
||||
// _ => {}
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
||||
// _ => ()
|
||||
// }
|
||||
|
||||
// bucket the events out, but not really
|
||||
// match
|
||||
// event {
|
||||
|
||||
Reference in New Issue
Block a user