@ -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 { }
}
}
}
_ = > { }
_ = > { }
}
}