From 38c3f7078fcc07c0046ba457aee5f5fe11a2c7ff Mon Sep 17 00:00:00 2001 From: Christian Treffs Date: Thu, 4 Jan 2018 22:35:51 +0100 Subject: [PATCH] Update readme --- README.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a4d7678..998b4a8 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,52 @@ let package = Package( -A core element in the Fireblade-ECS is the [Nexus](https://en.wiktionary.org/wiki/nexus#Noun). It acts as a centralized way to store, access and manage entities and their components. +A core element in the Fireblade-ECS is the [Nexus](https://en.wiktionary.org/wiki/nexus#Noun). It acts as a centralized way to store, access and manage entities and their components. You may use more than one nexus at the same time. + +Initialize a nexus with ```swift let nexus = Nexus() ``` +then create entities by generating them with the nexus. + +```swift +let myEntity = nexus.create(entity: "myEntity") +``` + +You create components like this + +```swift +class Movement: Component { + var position: (x: Double, y: Double) = (0.0, 1.0) + var velocity: Double = 0.1 +} +``` +and assign them to an entity with + +```swift +myEntity.assign(Movement()) +``` + +```swift +class PlayerMovementSystem { + let family = nexus.family(requiresAll: [Movement.self, PlayerInput.self], excludesAll: []) + + func update() { + family.iterate { (_, mov: Movement!, input: PlayerInput!) in + + mov.position + mov.velocity + ... + + input.command + ... + } + } +} +``` +