how do I make eventing extensible without cluttering this file with standalone functions

a-star
mitchellhansen 4 years ago
parent 84999130bb
commit aaef25f710

@ -0,0 +1,64 @@
use std::sync::Arc;
use specs::{Component, Entities, Join, System, VecStorage, Write, WriteStorage};
use vulkano::swapchain::Surface;
use winit::window::Window;
use crate::canvas::canvas_frame::CanvasFrame;
use crate::canvas::compu_frame::CompuFrame;
use crate::PersistentState;
use crate::render_system::Position;
use crate::util::tr_event::{TrEvent, TrEventExtension, TrWindowEvent};
use crate::vkprocessor::VkProcessor;
use winit::event::ElementState;
#[derive(Debug, Clone)]
pub struct Evented {
pub subscribed: fn(event: TrEvent<TrEventExtension>) -> bool,
}
impl Component for Evented {
type Storage = VecStorage<Self>;
}
pub struct EventSystem;
impl<'a> System<'a> for EventSystem {
type SystemData = (
Entities<'a>,
WriteStorage<'a, Position>,
WriteStorage<'a, Evented>,
Write<'a, PersistentState>,
Write<'a, VkProcessor>,
Write<'a, Vec<TrEvent<TrEventExtension>>>
);
fn run(&mut self, (
entity,
mut position_list,
mut evented_list,
mut state,
mut vk_processor,
event_stack
): Self::SystemData) {
for (position, evented) in (&mut position_list, &evented_list).join() {
for event in &*event_stack {
match event {
TrEvent::WindowEvent { window_id, event } => {
match event {
TrWindowEvent::MouseInput { device_id, state, button, modifiers } => {
if *state == ElementState::Pressed {
position.x += 100.0;
}
},
_ => {}
}
}
_ => {}
}
}
}
for (entity, evented) in (&*entity, &mut evented_list).join() {}
}
}

@ -46,6 +46,7 @@ use crate::util::tr_event::{TrEvent, TrEventExtension};
use crate::util::vertex::{TextureVertex3D, VertexTypeContainer};
use crate::vkprocessor::VkProcessor;
use crate::compu_system::{CompuSystem, Compu};
use crate::event_system::{EventSystem, Evented};
pub mod util;
pub mod vkprocessor;
@ -53,15 +54,7 @@ pub mod drawables;
pub mod canvas;
pub mod render_system;
pub mod compu_system;
#[derive(Debug, Clone)]
pub struct Evented {
subscribed: fn(event: TrEvent<TrEventExtension>),
}
impl Component for Evented {
type Storage = VecStorage<Self>;
}
pub mod event_system;
#[derive(Default)]
pub struct PersistentState {
@ -72,25 +65,6 @@ pub struct PersistentState {
compu_frame: CompuFrame,
}
struct EventSystem;
impl<'a> System<'a> for EventSystem {
type SystemData = (
Entities<'a>,
WriteStorage<'a, Evented>,
Write<'a, PersistentState>,
Write<'a, VkProcessor>,
Write<'a, Vec<TrEvent<TrEventExtension>>>
);
fn run(&mut self, (entity, mut evented_list, mut state, mut vk_processor, event_stack): Self::SystemData) {
for (entity, evented) in (&*entity, &mut evented_list).join() {
}
}
}
pub fn main() {
//hprof::start_frame();
//let g = hprof::enter("vulkan preload");
@ -152,6 +126,7 @@ pub fn main() {
processor.get_texture_handle(String::from("sfml.png")).unwrap();
let mut world = World::new();
world.register::<Evented>();
world.register::<Compu>();
world.register::<Position>();
world.register::<Geometry>();
@ -175,14 +150,14 @@ pub fn main() {
.with(Images { images: vec![compu_image], image_resolutions: vec![image_dimensions_u] })
.build();
world.create_entity()// just a drawable
world.create_entity()
.with(Evented { subscribed: |event| {true} })
.with(Position { x: 0.0, y: 0.0, z: 0 })
.with(Geometry { size_x: 300.0, size_y: 300.0, rotation: 0.0 })
.with(Textures { textures: vec![funky_handle] })
.build();
// call the run method for the following systems & deps
let mut dispatcher = DispatcherBuilder::new()
// .with(SysA, "sys_a", &[])

Loading…
Cancel
Save