diff --git a/notes/MakingAnActualThing.txt b/notes/MakingAnActualThing.txt new file mode 100644 index 00000000..cc205e45 --- /dev/null +++ b/notes/MakingAnActualThing.txt @@ -0,0 +1,26 @@ +Content-Type: text/x-zim-wiki +Wiki-Format: zim 0.4 +Creation-Date: 2020-08-06T21:51:48-07:00 + +====== MakingAnActualThing ====== +Created Thursday 06 August 2020 + +So, I need to figure out how to determine which objects will : + * Be rendered + * Be notified + * Get batched + * And initialized + +The best candidate that I have right now is some sort of "scene" setup. Maybe something like + +pub struct Scene { + + drawables_bucket + notifiable_bucket +} + +impl Scene { + pub fn init() -> Scene {} + pub fn get_drawable() -> Maybe iterator of drawables? + pub fn get_notifiable() - +} diff --git a/src/main.rs b/src/main.rs index e3a55b6a..365f1ca2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,79 @@ pub mod canvas; pub mod compute; +extern crate specs; + +use specs::prelude::*; + +// A component contains data which is +// associated with an entity. + +struct Vel(f32); + +impl Component for Vel { + type Storage = VecStorage; +} + +struct Pos(f32); + +impl Component for Pos { + type Storage = VecStorage; +} + +struct SysA; + +impl<'a> System<'a> for SysA { + // These are the resources required for execution. + // You can also define a struct and `#[derive(SystemData)]`, + // see the `full` example. + type SystemData = (WriteStorage<'a, Pos>, ReadStorage<'a, Vel>); + + fn run(&mut self, (mut pos, vel): Self::SystemData) { + // The `.join()` combines multiple components, + // so we only access those entities which have + // both of them. + + // This joins the component storages for Position + // and Velocity together; it's also possible to do this + // in parallel using rayon's `ParallelIterator`s. + // See `ParJoin` for more. + for (pos, vel) in (&mut pos, &vel).join() { + pos.0 += vel.0; + } + } +} + + pub fn main() { + + + + // The `World` is our + // container for components + // and other resources. + + let mut world = World::new(); + world.register::(); + world.register::(); + + world.reg + + // An entity may or may not contain some component. + world.create_entity().with(Vel(2.0)).with(Pos(0.0)).build(); + world.create_entity().with(Vel(4.0)).with(Pos(1.6)).build(); + world.create_entity().with(Vel(1.5)).with(Pos(5.4)).build(); + + world.create_entity().with(Pos(2.0)).build(); + + let mut dispatcher = DispatcherBuilder::new() + .with(SysA, "sys_a", &[]).build(); + + // This dispatches all the systems in parallel (but blocking). + dispatcher.dispatch(&mut world); + + + + hprof::start_frame(); let q1 = hprof::enter("setup"); @@ -174,6 +246,14 @@ pub fn main() { let mut canvas_frame = CanvasFrame::new(window_size); let mut compu_frame = CompuFrame::new(window_size); + + + // What would the component for a sprite be... + // Drawable with the vertex format in one rendering system + // position + velocity could then be two more in one system + // maybe some sort of input system + + // let mut big_container = vec![ Box::new(Slider::new((0.1, 0.1), (0.9, 0.9), 5000)), Box::new(Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone())), @@ -323,8 +403,5 @@ pub fn click_test(event_loop_proxy: EventLoopProxy, canvas_state: &Canv - - -