From 3a6145e6342437a9d89f323b2d0b3bdae7359027 Mon Sep 17 00:00:00 2001 From: Christian Treffs Date: Thu, 30 Jul 2020 16:33:18 +0200 Subject: [PATCH] Update README --- README.md | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3e6d878..b405f68 100644 --- a/README.md +++ b/README.md @@ -66,24 +66,41 @@ let nexus = Nexus() then create entities by letting the `Nexus` generate them. ```swift -let myEntity = nexus.createEntity() +// an entity without components +let newEntity = nexus.createEntity() ``` -You can define `Components` like this +To define components conform your class to the `Component` protocol ```swift -class Movement: Component { - var position: (x: Double, y: Double) = (0.0, 1.0) - var velocity: Double = 0.1 +final class Position: Component { + var x: Int = 0 + var y: Int = 0 } ``` -and assign instances of them to an `Entity` with +and assign instances of it to an `Entity` with ```swift -let movement = Movement() -myEntity.assign(movement) +let position = Position(x: 1, y: 2) +entity.assign(position) ``` +You can be more efficient by assigning components while creating an entity. + +```swift +// an entity with two components assigned. +nexus.createEntity { + Position(x: 1, y: 2) + Color(.red) +} + +// bulk create entities with multiple components assigned. +nexus.createEntities(count: 100) { _ in + Position() + Color() +} + +``` ### 👪 Families This ECS uses a grouping approach for entities with the same component types to optimize cache locality and ease up access to them.