this is a week or so worth of brainstorming. Looking at pulling everything sprite related into it's own little struct. And also doing a message everything arch

a-star
mitchellhansen 4 years ago
parent a42d23e5f9
commit 369a305817

@ -31,3 +31,23 @@ So for a sprite, which is a generic texture and position/size combo
Images are similar, but instead of a "sprite" I made a computsprite because that's the only thing that uses them. Images are similar, but instead of a "sprite" I made a computsprite because that's the only thing that uses them.
Now if I had to shove these into a component / a set of components... I could have a component of the vertex type even? Now if I had to shove these into a component / a set of components... I could have a component of the vertex type even?
===== Sep 2020 =====
Lets think about this for a minute...
* We have components which are purely data...
* But can also have structs that impl functionality
* The data can be contained within traits. But it has to do all IO through the trait interface. ALL
* Problem, for example I have primitives like textured sprites, and also complex widgets which also have additional IO they they need. Like text input or buttons. I suppose This could all be made message based. So when the text input receives a focus, and then key presses it would update. When the enter key is pressed it could create a customer event for which another component is the listener...
* Maybe this is the way to go... Have some generic structure that has a render(params), notify(event), update(delta) -> VEvent
* So if I had a textbox sprite it could notify(key events) render
* We can split up components in order to have sharable sets of data for shared functionality. e.g rendering
[[paste]]
So that article more or less talked about what I was thinking with the ECS. But they didn't really go into the separation of components.

@ -0,0 +1,40 @@
Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.4
Creation-Date: 2020-09-09T22:41:18-07:00
====== paste ======
Created Wednesday 09 September 2020
// If I were to have multiple systems
/*
One for rendering
One for updating
One for eventing
Rendering is easy enough. It needs all the components necessary in order
to generate the vertices. This includes the position, size, and vertex generator
Updating can probably be multiple types, I imagine something that implemented an Updatable
trait could then be used.
So the big problem here is that I have two traits that I want to expose, BUT
I have to put the concrete value in both containers... I don't think this is something
that specs will like since it wants to be the only owner. No use in RefCell'ing it
because that's just stupid
What if I turn this on it's head and really embrace the systems. So for example I could have
the User system. Ooof this is a big question actually...
// Components that want to be updated
Move
// want to be drawn
Drawable
Geom
Notifyable
*/

File diff suppressed because one or more lines are too long

@ -6,31 +6,35 @@ use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle}; use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
use vulkano::pipeline::vertex::Vertex; use vulkano::pipeline::vertex::Vertex;
use std::any::Any; use std::any::Any;
use crate::{VertexTypeContainer, Move, Geom}; use crate::{VertexTypeContainer};
use winit::event::Event; use winit::event::Event;
use crate::util::tr_event::TrEvent; use crate::util::tr_event::{TrEvent, TrUIEvent};
use crate::drawables::sprite::{Velocity, Geometry};
/// Trait which may be inherited by objects that wish to be drawn to the screen /// Trait which may be inherited by objects that wish to be drawn to the screen
pub trait Drawable { pub trait Drawable {
fn get(&self,
window_size: (u32, u32), // Render expects the implementer to create custom render logic based on interior data within
position: (f32, f32), // the struct. This data as of right now, will *only* be mutatable via events & update
rotation: f32, fn render(&self,
size: (f32, f32), window_size: (u32, u32),
depth: f32, position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer>; ) -> Vec<VertexTypeContainer>;
}
/// Trait which may be inherited by objects that wish to receive events // Update simply passes the delta time. The implementor doesn't necessarily need to use delta_time
pub trait Eventable<T> { // or even add anything other than a Vec::new() to the function.
fn notify(&mut self, event: &TrEvent<T>) -> (); fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>>;
}
/// Trait which may be inherited by objects that wish to be updated // Notify is where custom events created in other parts of the system will be ingested. It
pub trait Updatable { // might be a good idea in the future to have some of pre-function-call filtering so we
fn update(&mut self, delta_time: f32) -> (); // don't have as many notifies that just immediately reject.
fn notify<Y, T>(&self, tr_event : Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>>;
} }
/// Accumulator for Vectors of VertexTypes /// Accumulator for Vectors of VertexTypes
#[derive(Default)] #[derive(Default)]
pub struct CanvasFrame { pub struct CanvasFrame {
@ -54,8 +58,8 @@ impl CanvasFrame {
} }
/// Push this drawable onto the back of the accumulator /// Push this drawable onto the back of the accumulator
pub fn draw(&mut self, drawable: &dyn Drawable, mv: Move, geom: Geom) { pub fn draw(&mut self, drawable: &dyn Drawable, mv: Velocity, geom: Geometry) {
for i in drawable.get( for i in drawable.render(
self.window_size, self.window_size,
(mv.pos_x, mv.pos_y), (mv.pos_x, mv.pos_y),
geom.rotation, geom.rotation,

@ -4,7 +4,7 @@ use crate::canvas::managed::handles::{CompuKernelHandle};
use crate::drawables::compu_sprite::CompuSprite; use crate::drawables::compu_sprite::CompuSprite;
use crate::canvas::canvas_frame::Drawable; use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::VertexTypeContainer; use crate::util::vertex::VertexTypeContainer;
use crate::{Move, Geom}; use crate::drawables::sprite::{Velocity, Geometry};
#[derive(Default)] #[derive(Default)]
pub struct CompuFrame { pub struct CompuFrame {
@ -58,10 +58,10 @@ impl CompuFrame {
buffer: Arc<CompuBufferHandle>, buffer: Arc<CompuBufferHandle>,
kernel: Arc<CompuKernelHandle>, kernel: Arc<CompuKernelHandle>,
sprite: &CompuSprite, sprite: &CompuSprite,
mv: Move, mv: Velocity,
geom: Geom, geom: Geometry,
) { ) {
let compu_sprites = sprite.get( let compu_sprites = sprite.render(
self.window_size, self.window_size,
(mv.pos_x, mv.pos_y), (mv.pos_x, mv.pos_y),
geom.rotation, geom.rotation,

@ -2,6 +2,7 @@ use std::sync::Arc;
use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle}; use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle};
use crate::canvas::canvas_frame::Drawable; use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::{VertexTypeContainer, ImageVertex3D}; use crate::util::vertex::{VertexTypeContainer, ImageVertex3D};
use crate::util::tr_event::{TrUIEvent, TrEvent};
pub struct CompuSprite { pub struct CompuSprite {
@ -53,13 +54,21 @@ impl CompuSprite {
} }
impl Drawable for CompuSprite { impl Drawable for CompuSprite {
fn get(&self, fn render(&self,
window_size: (u32, u32), window_size: (u32, u32),
position: (f32, f32), position: (f32, f32),
rotation: f32, rotation: f32,
size: (f32, f32), size: (f32, f32),
depth: f32, depth: f32,
) -> Vec<VertexTypeContainer> { ) -> Vec<VertexTypeContainer> {
vec![self.verts.clone()] vec![self.verts.clone()]
} }
fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
Vec::new()
}
fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
Vec::new()
}
} }

@ -4,6 +4,7 @@ use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, Canva
use crate::canvas::canvas_frame::{Drawable}; use crate::canvas::canvas_frame::{Drawable};
use crate::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D, ColorVertex3D}; use crate::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D, ColorVertex3D};
use crate::drawables::sprite::Sprite; use crate::drawables::sprite::Sprite;
use crate::util::tr_event::{TrUIEvent, TrEvent};
/// Convex multi verticy polygon /// Convex multi verticy polygon
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -61,16 +62,23 @@ impl Polygon {
} }
} }
impl Drawable for Polygon { impl Drawable for Polygon {
fn get(&self, fn render(&self,
window_size: (u32, u32), window_size: (u32, u32),
position: (f32, f32), position: (f32, f32),
rotation: f32, rotation: f32,
size: (f32, f32), size: (f32, f32),
depth: f32, depth: f32,
) -> Vec<VertexTypeContainer> { ) -> Vec<VertexTypeContainer> {
vec![self.verts.clone()] vec![self.verts.clone()]
} }
fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
Vec::new()
}
fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
Vec::new()
}
} }

@ -1,5 +1,6 @@
use crate::canvas::canvas_frame::Drawable; use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::{VertexTypeContainer, ColorVertex3D}; use crate::util::vertex::{VertexTypeContainer, ColorVertex3D};
use crate::util::tr_event::{TrUIEvent, TrEvent};
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -73,12 +74,12 @@ impl Rect {
} }
impl Drawable for Rect { impl Drawable for Rect {
fn get(&self, fn render(&self,
window_size: (u32, u32), window_size: (u32, u32),
position: (f32, f32), position: (f32, f32),
rotation: f32, rotation: f32,
size: (f32, f32), size: (f32, f32),
depth: f32, depth: f32,
) -> Vec<VertexTypeContainer> { ) -> Vec<VertexTypeContainer> {
vec![ vec![
VertexTypeContainer::ColorType( VertexTypeContainer::ColorType(
@ -86,4 +87,12 @@ impl Drawable for Rect {
) )
] ]
} }
fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
Vec::new()
}
fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
Vec::new()
}
} }

@ -2,11 +2,11 @@ use std::collections::HashSet;
use winit::event::{Event, ElementState, MouseButton}; use winit::event::{Event, ElementState, MouseButton};
use crate::canvas::canvas_frame::{Drawable, Eventable}; use crate::canvas::canvas_frame::{Drawable};
use crate::drawables::rect::Rect; use crate::drawables::rect::Rect;
use crate::drawables::sprite::Sprite; use crate::drawables::sprite::Sprite;
use crate::util::vertex::VertexTypeContainer; use crate::util::vertex::VertexTypeContainer;
use crate::util::tr_event::{TrEvent, TrWindowEvent}; use crate::util::tr_event::{TrEvent, TrWindowEvent, TrUIEvent};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Slider { pub struct Slider {
@ -67,14 +67,14 @@ impl Slider {
} }
impl Drawable for Slider { impl Drawable for Slider {
fn get(&self, fn render(&self,
window_size: (u32, u32), window_size: (u32, u32),
position: (f32, f32), position: (f32, f32),
rotation: f32, rotation: f32,
size: (f32, f32), size: (f32, f32),
depth: f32, depth: f32,
) -> Vec<VertexTypeContainer> { ) -> Vec<VertexTypeContainer> {
let mut vertices = self.handle.get( let mut vertices = self.handle.render(
window_size, window_size,
position, position,
rotation, rotation,
@ -84,30 +84,32 @@ impl Drawable for Slider {
vertices.extend_from_slice( vertices.extend_from_slice(
self.guide.iter() self.guide.iter()
.map(|x| x.get(window_size, .map(|x| x.render(window_size,
position, position,
rotation, rotation,
size, size,
depth, depth,
)).flatten() )).flatten()
.collect::<Vec<VertexTypeContainer>>() .collect::<Vec<VertexTypeContainer>>()
.as_slice() .as_slice()
); );
vertices.extend_from_slice( vertices.extend_from_slice(
self.guide[0].get(window_size, self.guide[0].render(window_size,
position, position,
rotation, rotation,
size, size,
depth, depth,
).as_slice()); ).as_slice());
vertices vertices
} }
}
impl<T> Eventable<T> for Slider { fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
fn notify(&mut self, event: &TrEvent<T>) -> () { Vec::new()
match event { }
fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
match tr_event {
TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => { TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
@ -124,6 +126,6 @@ impl<T> Eventable<T> for Slider {
} }
_ => {} _ => {}
} }
Vec::new()
} }
} }

@ -1,15 +1,31 @@
use std::sync::Arc; use std::sync::Arc;
use crate::canvas::*; use crate::canvas::*;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle}; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
use crate::canvas::canvas_frame::{Drawable, Eventable, Updatable}; use crate::canvas::canvas_frame::{Drawable};
use crate::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D}; use crate::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D};
use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent}; use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent};
use crate::util::tr_event::{TrEvent, TrWindowEvent}; use crate::util::tr_event::{TrEvent, TrWindowEvent, TrUIEvent};
pub struct Geometry {
pos_x: f32,
pos_y: f32,
size_x: f32,
size_y: f32,
rotation: f32,
depth: f32,
}
pub struct Velocity {
vel_x: f32,
vel_y: f32,
vel_r: f32,
}
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Sprite { pub struct Sprite {
texture_handle: Arc<CanvasTextureHandle>, texture_handle: Arc<CanvasTextureHandle>,
geometry: Geometry,
velocity: Velocity,
} }
/// Container class which implements drawable. /// Container class which implements drawable.
@ -62,18 +78,31 @@ impl Sprite {
pub fn new(texture_handle: Arc<CanvasTextureHandle>) -> Sprite { pub fn new(texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
Sprite { Sprite {
texture_handle: texture_handle.clone(), texture_handle: texture_handle.clone(),
geometry: Geometry {
pos_x: 0.0,
pos_y: 0.0,
size_x: 0.0,
size_y: 0.0,
rotation: 0.0,
depth: 0.0
},
velocity: Velocity {
vel_x: 0.0,
vel_y: 0.0,
vel_r: 0.0
}
} }
} }
} }
impl Drawable for Sprite { impl Drawable for Sprite {
fn get(&self, fn render(&self,
window_size: (u32, u32), window_size: (u32, u32),
position: (f32, f32), position: (f32, f32),
rotation: f32, rotation: f32,
size: (f32, f32), size: (f32, f32),
depth: f32, depth: f32,
) -> Vec<VertexTypeContainer> { ) -> Vec<VertexTypeContainer> {
let normalized_depth = (depth / 255.0); let normalized_depth = (depth / 255.0);
@ -83,11 +112,13 @@ impl Drawable for Sprite {
self.texture_handle.clone()) self.texture_handle.clone())
] ]
} }
}
impl<T> Eventable<T> for Sprite { fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
fn notify(&mut self, event: &TrEvent<T>) -> () { Vec::new()
match event { }
fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
match tr_event {
TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => { TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button { match button {
MouseButton::Left => { MouseButton::Left => {
@ -100,9 +131,6 @@ impl<T> Eventable<T> for Sprite {
} }
_ => {} _ => {}
} }
Vec::new()
} }
} }
impl Updatable for Sprite {
fn update(&mut self, delta_time: f32) -> () {}
}

@ -1,5 +1,6 @@
use crate::canvas::canvas_frame::Drawable; use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::{VertexTypeContainer, ColorVertex3D}; use crate::util::vertex::{VertexTypeContainer, ColorVertex3D};
use crate::util::tr_event::{TrUIEvent, TrEvent};
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -137,13 +138,21 @@ impl Text {
} }
impl Drawable for Text { impl Drawable for Text {
fn get(&self, fn render(&self,
window_size: (u32, u32), window_size: (u32, u32),
position: (f32, f32), position: (f32, f32),
rotation: f32, rotation: f32,
size: (f32, f32), size: (f32, f32),
depth: f32, depth: f32,
) -> Vec<VertexTypeContainer> { ) -> Vec<VertexTypeContainer> {
vec![self.verts.clone()] vec![self.verts.clone()]
} }
fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
Vec::new()
}
fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
Vec::new()
}
} }

@ -25,7 +25,7 @@ use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
use winit::platform::unix::WindowBuilderExtUnix; use winit::platform::unix::WindowBuilderExtUnix;
use winit::window::{WindowBuilder, Window}; use winit::window::{WindowBuilder, Window};
use crate::canvas::canvas_frame::{CanvasFrame, Drawable, Eventable, Updatable}; use crate::canvas::canvas_frame::{CanvasFrame, Drawable};
use crate::canvas::canvas_state::CanvasState; use crate::canvas::canvas_state::CanvasState;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasTextureHandle, Handle}; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasTextureHandle, Handle};
use canvas::compu_frame::CompuFrame; use canvas::compu_frame::CompuFrame;
@ -46,41 +46,16 @@ pub mod vkprocessor;
pub mod drawables; pub mod drawables;
pub mod canvas; pub mod canvas;
extern crate specs; extern crate specs;
use specs::prelude::*; use specs::prelude::*;
use vulkano::swapchain::Surface; use vulkano::swapchain::Surface;
pub struct Render {
//struct Draws(Box<dyn Drawable + Sync + Send>, Box<dyn Eventable<TrEventExtension> + Sync + Send>); render_actor: Box<dyn Drawable + Sync + Send>,
struct SSprite(Box<dyn Drawable + Sync + Send>);
impl Component for SSprite {
type Storage = VecStorage<Self>;
}
pub struct Move {
vel_x: f32,
vel_y: f32,
} }
impl Component for Move { impl Component for Render {
type Storage = VecStorage<Self>;
}
pub struct Geom {
pos_x: f32,
pos_y: f32,
size_x: f32,
size_y: f32,
rotation: f32,
depth: f32,
}
impl Component for Geom {
type Storage = VecStorage<Self>; type Storage = VecStorage<Self>;
} }
@ -93,65 +68,23 @@ struct PersistentState {
compu_frame: CompuFrame, compu_frame: CompuFrame,
} }
// If I were to have multiple systems
/*
One for rendering
One for updating
One for eventing
Rendering is easy enough. It needs all the components necessary in order
to generate the vertices. This includes the position, size, and vertex generator
Updating can probably be multiple types, I imagine something that implemented an Updatable
trait could then be used.
So the big problem here is that I have two traits that I want to expose, BUT
I have to put the concrete value in both containers... I don't think this is something
that specs will like since it wants to be the only owner. No use in RefCell'ing it
because that's just stupid
What if I turn this on it's head and really embrace the systems. So for example I could have
the User system. Ooof this is a big question actually...
// Components that want to be updated
Move
// want to be drawn
Drawable
Geom
Notifyable
*/
struct RenderSystem; struct RenderSystem;
impl<'a> System<'a> for RenderSystem { impl<'a> System<'a> for RenderSystem {
type SystemData = ( type SystemData = (
WriteStorage<'a, Move>, // its velocity WriteStorage<'a, Render>, // generates the vertices
WriteStorage<'a, Geom>, // its size, position & rotation Write<'a, PersistentState>, // delta_time, window size, etc.
WriteStorage<'a, SSprite>, // generates the vertices Write<'a, VkProcessor>, // Renderer
Write<'a, PersistentState>, // delta_time, window size, etc.
Write<'a, VkProcessor>, // Renderer
); );
fn run(&mut self, (mut mv, mut geom, mut draw, mut state, mut vk_processor): Self::SystemData) { fn run(&mut self, (mut mv, mut draw, mut state, mut vk_processor): Self::SystemData) {
state.canvas_frame = CanvasFrame::new(state.window_size); state.canvas_frame = CanvasFrame::new(state.window_size);
state.compu_frame = CompuFrame::new(state.window_size); state.compu_frame = CompuFrame::new(state.window_size);
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); // compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); // compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
for (mv, geom, draw) in (&mut mv, &mut geom, &mut draw).join() { for (mv, geom, draw) in (&mut mv, &mut draw).join() {
geom.pos_x += mv.vel_x * state.delta_time; geom.pos_x += mv.vel_x * state.delta_time;
geom.pos_y += mv.vel_y * state.delta_time; geom.pos_y += mv.vel_y * state.delta_time;
@ -180,18 +113,18 @@ struct EventSystem;
impl<'a> System<'a> for EventSystem { impl<'a> System<'a> for EventSystem {
type SystemData = ( type SystemData = (
WriteStorage<'a, SSprite>, WriteStorage<'a, Render>,
Write<'a, PersistentState>, Write<'a, PersistentState>,
Write<'a, VkProcessor>, Write<'a, VkProcessor>,
Write<'a, Vec<TrEvent<TrEventExtension>>> Write<'a, Vec<TrEvent<TrEventExtension>>>
); );
fn run(&mut self, (mut draw, mut state, mut vk_processor, event_stack): Self::SystemData) { fn run(&mut self, (mut draw, mut state, mut vk_processor, event_stack): Self::SystemData) {
for draw_data in (&mut draw).join() { // for draw_data in (&mut draw).join() {
for event in event_stack.iter() { // for event in event_stack.iter() {
draw_data.1.notify(event) // draw_data.0.notify(event)
} // }
} // }
} }
} }
@ -263,9 +196,7 @@ pub fn main() {
processor.get_texture_handle(String::from("sfml.png")).unwrap(); processor.get_texture_handle(String::from("sfml.png")).unwrap();
let mut world = World::new(); let mut world = World::new();
world.register::<Move>(); world.register::<Render>();
world.register::<Geom>();
world.register::<SSprite>();
world.insert::<VkProcessor>(processor); world.insert::<VkProcessor>(processor);
world.insert::<Vec<TrEvent<TrEventExtension>>>(Vec::new()); world.insert::<Vec<TrEvent<TrEventExtension>>>(Vec::new());
world.insert::<PersistentState>(PersistentState { world.insert::<PersistentState>(PersistentState {
@ -281,23 +212,13 @@ pub fn main() {
// An entity may or may not contain some component. // An entity may or may not contain some component.
let t = world.create_entity() let t = world.create_entity()
.with(Move { vel_x: 0.0, vel_y: 0.0}) .with(Render{ render_actor: thing })// just a drawable
.with(Geom { size_x: 100.0, size_y: 100.0, rotation: 0.0, depth: 1.0, pos_x: 100.0, pos_y: 400.0 })
.with(SSprite(thing.clone(), thing.clone()))
.build();
world.create_entity()
.with(Move { vel_x: 0.0, vel_y: 0.0 })
.with(Geom { size_x: 100.0, size_y: 100.0, rotation: 0.0, depth: 1.0, pos_x: 100.0, pos_y: 400.0 })
.with(SSprite(thing.clone(), thing))
.build(); .build();
let thing2 = Box::new(Slider::new((300.0, 50.0), (550.0, 100.0), 30000)); let thing2 = Box::new(Slider::new((300.0, 50.0), (550.0, 100.0), 30000));
world.create_entity() world.create_entity()
.with(Move { vel_x: 0.0, vel_y: 0.0 }) .with(Render{ render_actor: thing2 })// just a drawable
.with(Geom { size_x: 100.0, size_y: 100.0, rotation: 0.0, depth: 1.0, pos_x: 100.0, pos_y: 400.0 })
.with(SSprite(thing2.clone(), thing2))
.build(); .build();
@ -352,7 +273,7 @@ pub fn main() {
world.write_resource::<PersistentState>() world.write_resource::<PersistentState>()
.window_size = surface.window().inner_size().into(); .window_size = surface.window().inner_size().into();
} else { } else {
// println!("{}", world.write_resource::<Vec<TrEvent<TrEventExtension>>>().len()); // println!("{}", world.write_resource::<Vec<TrEvent<TrEventExtension>>>().len());
world.write_resource::<Vec<TrEvent<TrEventExtension>>>().clear(); world.write_resource::<Vec<TrEvent<TrEventExtension>>>().clear();
} }
} }
@ -362,8 +283,7 @@ pub fn main() {
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => { Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button { match button {
MouseButton::Left => { MouseButton::Left => {
if state == ElementState::Pressed { if state == ElementState::Pressed {}
}
} }
_ => {} _ => {}
} }

@ -5,6 +5,11 @@ use winit::dpi::{PhysicalPosition, PhysicalSize};
use gilrs::Event as GilEvent; use gilrs::Event as GilEvent;
use vulkano::pipeline::shader::GeometryShaderExecutionMode::TrianglesWithAdjacency; use vulkano::pipeline::shader::GeometryShaderExecutionMode::TrianglesWithAdjacency;
#[derive(Clone)]
pub enum TrUIEvent<T> {
UIEvent(T)
}
#[derive(Clone)] #[derive(Clone)]
pub enum TrEventExtension { pub enum TrEventExtension {

Loading…
Cancel
Save