a-star
mitchellhansen 4 years ago
parent 28565652c0
commit a42d23e5f9

@ -53,17 +53,18 @@ use specs::prelude::*;
use vulkano::swapchain::Surface;
struct Draws(Box<dyn Drawable + Sync + Send>, Box<dyn Eventable<TrEventExtension> + Sync + Send>);
//struct Draws(Box<dyn Drawable + Sync + Send>, Box<dyn Eventable<TrEventExtension> + Sync + Send>);
struct SSprite(Box<dyn Drawable + Sync + Send>);
impl Component for Draws {
impl Component for SSprite {
type Storage = VecStorage<Self>;
}
pub struct Move {
vel_x: f32,
vel_y: f32,
pos_x: f32,
pos_y: f32,
}
impl Component for Move {
@ -71,6 +72,8 @@ impl Component for Move {
}
pub struct Geom {
pos_x: f32,
pos_y: f32,
size_x: f32,
size_y: f32,
rotation: f32,
@ -90,16 +93,55 @@ struct PersistentState {
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;
impl<'a> System<'a> for RenderSystem {
type SystemData = (
WriteStorage<'a, Move>,
WriteStorage<'a, Geom>,
WriteStorage<'a, Draws>,
Write<'a, PersistentState>,
Write<'a, VkProcessor>,
WriteStorage<'a, Move>, // its velocity
WriteStorage<'a, Geom>, // its size, position & rotation
WriteStorage<'a, SSprite>, // generates the vertices
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) {
@ -110,13 +152,13 @@ impl<'a> System<'a> for RenderSystem {
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
for (mv, geom, draw) in (&mut mv, &mut geom, &mut draw).join() {
mv.pos_x += mv.vel_x * state.delta_time;
mv.pos_y += mv.vel_y * state.delta_time;
geom.pos_x += mv.vel_x * state.delta_time;
geom.pos_y += mv.vel_y * state.delta_time;
let window_size = state.window_size.clone();
state.canvas_frame.add(draw.0.get(
window_size,
(mv.pos_x, mv.pos_y),
(geom.pos_x, geom.pos_y),
geom.rotation,
(geom.size_x, geom.size_y),
geom.depth,
@ -138,7 +180,7 @@ struct EventSystem;
impl<'a> System<'a> for EventSystem {
type SystemData = (
WriteStorage<'a, Draws>,
WriteStorage<'a, SSprite>,
Write<'a, PersistentState>,
Write<'a, VkProcessor>,
Write<'a, Vec<TrEvent<TrEventExtension>>>
@ -223,7 +265,7 @@ pub fn main() {
let mut world = World::new();
world.register::<Move>();
world.register::<Geom>();
world.register::<Draws>();
world.register::<SSprite>();
world.insert::<VkProcessor>(processor);
world.insert::<Vec<TrEvent<TrEventExtension>>>(Vec::new());
world.insert::<PersistentState>(PersistentState {
@ -238,24 +280,24 @@ pub fn main() {
let thing = Box::new(Sprite::new(funky_handle.clone()));
// An entity may or may not contain some component.
world.create_entity()
.with(Move { vel_x: 0.0, vel_y: 0.0, pos_x: 100.0, pos_y: 400.0 })
.with(Geom { size_x: 100.0, size_y: 100.0, rotation: 0.0, depth: 1.0 })
.with(Draws(thing.clone(), thing.clone()))
let t = 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.clone()))
.build();
world.create_entity()
.with(Move { vel_x: 0.0, vel_y: 0.0, pos_x: 100.0, pos_y: 400.0 })
.with(Geom { size_x: 100.0, size_y: 100.0, rotation: 0.0, depth: 1.0 })
.with(Draws(thing.clone(), thing))
.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();
let thing2 = Box::new(Slider::new((300.0, 50.0), (550.0, 100.0), 30000));
world.create_entity()
.with(Move { vel_x: 0.0, vel_y: 0.0, pos_x: 100.0, pos_y: 400.0 })
.with(Geom { size_x: 100.0, size_y: 100.0, rotation: 0.0, depth: 1.0 })
.with(Draws(thing2.clone(), thing2))
.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(thing2.clone(), thing2))
.build();

Loading…
Cancel
Save