|
|
@ -48,7 +48,79 @@ pub mod canvas;
|
|
|
|
pub mod compute;
|
|
|
|
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<Self>;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Pos(f32);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Component for Pos {
|
|
|
|
|
|
|
|
type Storage = VecStorage<Self>;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
pub fn main() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The `World` is our
|
|
|
|
|
|
|
|
// container for components
|
|
|
|
|
|
|
|
// and other resources.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut world = World::new();
|
|
|
|
|
|
|
|
world.register::<Pos>();
|
|
|
|
|
|
|
|
world.register::<Vel>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
hprof::start_frame();
|
|
|
|
|
|
|
|
|
|
|
|
let q1 = hprof::enter("setup");
|
|
|
|
let q1 = hprof::enter("setup");
|
|
|
@ -174,6 +246,14 @@ pub fn main() {
|
|
|
|
let mut canvas_frame = CanvasFrame::new(window_size);
|
|
|
|
let mut canvas_frame = CanvasFrame::new(window_size);
|
|
|
|
let mut compu_frame = CompuFrame::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![
|
|
|
|
let mut big_container = vec![
|
|
|
|
Box::new(Slider::new((0.1, 0.1), (0.9, 0.9), 5000)),
|
|
|
|
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())),
|
|
|
|
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<TrEvent>, canvas_state: &Canv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|