Browse Source

Expand README

Getty Ritter 4 years ago
parent
commit
ce5ae36a05
1 changed files with 42 additions and 2 deletions
  1. 42 2
      README.md

+ 42 - 2
README.md

@@ -77,8 +77,48 @@ system! {
 }
 ```
 
+# resources
+
+To get access to resources, you can use the `resource` or `resource mut` keywords. These will be represented as `ReadExpect` and `WriteExpect` resources in the relevant `SystemData`, and will not be looped over in the loop of the macro. Due to implementation restrictions, a `resource` _cannot_ be the last thing in the argument list, so it's best to keep `resource`s first.
+
+```rust
+system! {
+    Move(resource keys: KeySet, _con: Controlled, mut vel: Velocity) {
+        vel.dx = 0.0;
+        vel.dy = 0.0;
+
+        if keys.contains(&winit::VirtualKeyCode::W) {
+            vel.dy -= 2.0;
+        }
+        if keys.contains(&winit::VirtualKeyCode::A) {
+            vel.dx -= 2.0;
+        }
+        if keys.contains(&winit::VirtualKeyCode::S) {
+            vel.dy += 2.0;
+        }
+        if keys.contains(&winit::VirtualKeyCode::D) {
+            vel.dx += 2.0;
+        }
+    }
+}
+```
+
+# the system_impl macro
+
+The `system_impl!` macro is similar to `system!` but does not automatically loop a body over the joined components. This will result in less terse but more flexible system definitions that can e.g. loop over multiple sets of components. For example, the above `DamageSystem` system could be equivalently written as
+
+```rust
+system_impl! {
+    DamageSystem (mut stats: CombatStats, mut damage: SufferDamage) {
+        for (damage, mut stats) in (&damage, &mut stats).join() {
+            stats.hp -= damage.amount;
+        }
+        damage.clear();
+    }
+}
+```
+
 ## TODO:
 
-- [ ] Read/write access to resources
 - [ ] Setup blocks in addition to finally blocks
-- [ ] Systems 
+- [ ] Systems