|
|
@@ -48,8 +48,8 @@ async fn run() -> Result<(), Error> { |
|
|
|
info!("World initialized!"); |
|
|
|
|
|
|
|
let mut dispatcher = Dispatcher::builder() |
|
|
|
.with(ParMove, "move", &[])? |
|
|
|
.with(ParAccelerate, "accelerate", &["move"])? |
|
|
|
.with_async(ParMove, "move", &[])? |
|
|
|
.with_async(ParAccelerate, "accelerate", &["move"])? |
|
|
|
.build(); |
|
|
|
|
|
|
|
info!("Setup done!"); |
|
|
@@ -153,25 +153,21 @@ impl<'a> System<'a> for SeqMove { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
impl<'a> AsyncSystem<'a> for SeqAccelerate { |
|
|
|
impl<'a> System<'a> for SeqAccelerate { |
|
|
|
type SystemData = (WriteStorage<'a, Velocity>, ReadStorage<'a, Acceleration>); |
|
|
|
type Future = futures::future::Ready<()>; |
|
|
|
|
|
|
|
fn run(&mut self, (mut velocity, acceleration): Self::SystemData) -> Self::Future { |
|
|
|
fn run(&mut self, (mut velocity, acceleration): Self::SystemData) { |
|
|
|
for (velocity, acceleration) in (&mut velocity, &acceleration).join() { |
|
|
|
velocity.x += acceleration.x; |
|
|
|
velocity.y += acceleration.y; |
|
|
|
} |
|
|
|
|
|
|
|
futures::future::ready(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
impl<'a> AsyncSystem<'a> for ParMove { |
|
|
|
type SystemData = (WriteStorage<'a, Position>, ReadStorage<'a, Velocity>); |
|
|
|
type Future = BoxFuture<'a, ()>; |
|
|
|
|
|
|
|
fn run(&mut self, (mut position, velocity): Self::SystemData) -> Self::Future { |
|
|
|
fn run_async(&mut self, (mut position, velocity): Self::SystemData) -> BoxFuture<'a, ()> { |
|
|
|
async move { |
|
|
|
(&mut position, &velocity) |
|
|
|
.par_join() |
|
|
@@ -188,9 +184,8 @@ impl<'a> AsyncSystem<'a> for ParMove { |
|
|
|
|
|
|
|
impl<'a> AsyncSystem<'a> for ParAccelerate { |
|
|
|
type SystemData = (WriteStorage<'a, Velocity>, ReadStorage<'a, Acceleration>); |
|
|
|
type Future = BoxFuture<'a, ()>; |
|
|
|
|
|
|
|
fn run(&mut self, (mut velocity, acceleration): Self::SystemData) -> Self::Future { |
|
|
|
fn run_async(&mut self, (mut velocity, acceleration): Self::SystemData) -> BoxFuture<'a, ()> { |
|
|
|
async move { |
|
|
|
(&mut velocity, &acceleration) |
|
|
|
.par_join() |
|
|
|