瀏覽代碼

Added documentation and examples

raster
Bergmann89 5 年之前
父節點
當前提交
0454c96e95
共有 4 個文件被更改,包括 9 次插入13 次删除
  1. +1
    -0
      Cargo.lock
  2. +1
    -1
      async-ecs
  3. +1
    -1
      async-ecs-derive
  4. +6
    -11
      space-crush/src/main.rs

+ 1
- 0
Cargo.lock 查看文件

@@ -30,6 +30,7 @@ name = "async-ecs"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"asparit", "asparit",
"async-ecs-derive",
"futures", "futures",
"hashbrown", "hashbrown",
"hibitset", "hibitset",


+ 1
- 1
async-ecs

@@ -1 +1 @@
Subproject commit 0c94dac6c2a9307aba8296fb2450314250f2e8d4
Subproject commit 39fa7475beefd197f2d99e8b30ae4ec8c4e5ba12

+ 1
- 1
async-ecs-derive

@@ -1 +1 @@
Subproject commit 19038f49ebecd0d132002e4c42fe1e29440cf5a2
Subproject commit 14f0bdde2d5e4154a9f895e3b0a42970bd2aca5e

+ 6
- 11
space-crush/src/main.rs 查看文件

@@ -48,8 +48,8 @@ async fn run() -> Result<(), Error> {
info!("World initialized!"); info!("World initialized!");


let mut dispatcher = Dispatcher::builder() let mut dispatcher = Dispatcher::builder()
.with(ParMove, "move", &[])?
.with(ParAccelerate, "accelerate", &["move"])?
.with_async(ParMove, "move", &[])?
.with_async(ParAccelerate, "accelerate", &["move"])?
.build(); .build();


info!("Setup done!"); 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 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() { for (velocity, acceleration) in (&mut velocity, &acceleration).join() {
velocity.x += acceleration.x; velocity.x += acceleration.x;
velocity.y += acceleration.y; velocity.y += acceleration.y;
} }

futures::future::ready(())
} }
} }


impl<'a> AsyncSystem<'a> for ParMove { impl<'a> AsyncSystem<'a> for ParMove {
type SystemData = (WriteStorage<'a, Position>, ReadStorage<'a, Velocity>); 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 { async move {
(&mut position, &velocity) (&mut position, &velocity)
.par_join() .par_join()
@@ -188,9 +184,8 @@ impl<'a> AsyncSystem<'a> for ParMove {


impl<'a> AsyncSystem<'a> for ParAccelerate { impl<'a> AsyncSystem<'a> for ParAccelerate {
type SystemData = (WriteStorage<'a, Velocity>, ReadStorage<'a, Acceleration>); 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 { async move {
(&mut velocity, &acceleration) (&mut velocity, &acceleration)
.par_join() .par_join()


Loading…
取消
儲存