-
-
Notifications
You must be signed in to change notification settings - Fork 10
Nexus
public final class Nexus
CustomDebugStringConvertible
public convenience init()
var numComponents: Int
Number of entities in nexus.
var numEntities: Int
var numFamilies: Int
The entity identifier generator responsible for providing unique ids for entities during runtime.
var entityIdGenerator: EntityIdentifierGenerator
Provide a custom implementation prior to entity creation.
Defaults to DefaultEntityIdGenerator
.
The coding strategy used to encode/decode entities from/into families.
var codingStrategy: CodingStrategy
Provide a custom implementation prior to encoding/decoding.
Defaults to DefaultCodingStrategy
.
var delegate: NexusEventDelegate?
var debugDescription: String
Create a family of entities (aka members) having 1 required components.
public func family<Comp1>(requires comp1: Comp1.Type, excludesAll excludedComponents: Component.Type) -> Family1<Comp1> where Comp1: Component
A family is a collection of entities with uniform component types per entity. Entities that are be part of this family will have at least the 1 required components, but may have more components assigned.
A family is just a view on (component) data, creating them is cheap.
Use them to iterate efficiently over entities with the same components assigned.
Families with the same requirements provide a view on the same collection of entities (aka members).
A family conforms to the LazySequenceProtocol
and therefore can be accessed like any other (lazy) sequence.
General usage
let family = nexus.family(requires: Comp1.self)
// iterate each entity's components
family.forEach { (comp1) in
...
}
Caveats
-
Component types must be unique per family
-
Component type order is arbitrary
- comp1: Component type 1 required by members of this family.
- excludedComponents: All component types that must not be assigned to an entity in this family.
The family of entities having 1 required components each.
Create a family of entities (aka members) having 2 required components.
public func family<Comp1, Comp2>(requiresAll comp1: Comp1.Type, _ comp2: Comp2.Type, excludesAll excludedComponents: Component.Type) -> Family2<Comp1, Comp2> where Comp1: Component, Comp2: Component
A family is a collection of entities with uniform component types per entity. Entities that are be part of this family will have at least the 2 required components, but may have more components assigned.
A family is just a view on (component) data, creating them is cheap.
Use them to iterate efficiently over entities with the same components assigned.
Families with the same requirements provide a view on the same collection of entities (aka members).
A family conforms to the LazySequenceProtocol
and therefore can be accessed like any other (lazy) sequence.
General usage
let family = nexus.family(requiresAll: Comp1.self, Comp2.self)
// iterate each entity's components
family.forEach { (comp1, comp2) in
...
}
Caveats
-
Component types must be unique per family
-
Component type order is arbitrary
- comp1: Component type 1 required by members of this family.
- comp2: Component type 2 required by members of this family.
- excludedComponents: All component types that must not be assigned to an entity in this family.
The family of entities having 2 required components each.
Create a family of entities (aka members) having 3 required components.
public func family<Comp1, Comp2, Comp3>(requiresAll comp1: Comp1.Type, _ comp2: Comp2.Type, _ comp3: Comp3.Type, excludesAll excludedComponents: Component.Type) -> Family3<Comp1, Comp2, Comp3> where Comp1: Component, Comp2: Component, Comp3: Component
A family is a collection of entities with uniform component types per entity. Entities that are be part of this family will have at least the 3 required components, but may have more components assigned.
A family is just a view on (component) data, creating them is cheap.
Use them to iterate efficiently over entities with the same components assigned.
Families with the same requirements provide a view on the same collection of entities (aka members).
A family conforms to the LazySequenceProtocol
and therefore can be accessed like any other (lazy) sequence.
General usage
let family = nexus.family(requiresAll: Comp1.self, Comp2.self, Comp3.self)
// iterate each entity's components
family.forEach { (comp1, comp2, comp3) in
...
}
Caveats
-
Component types must be unique per family
-
Component type order is arbitrary
- comp1: Component type 1 required by members of this family.
- comp2: Component type 2 required by members of this family.
- comp3: Component type 3 required by members of this family.
- excludedComponents: All component types that must not be assigned to an entity in this family.
The family of entities having 3 required components each.
Create a family of entities (aka members) having 4 required components.
public func family<Comp1, Comp2, Comp3, Comp4>(requiresAll comp1: Comp1.Type, _ comp2: Comp2.Type, _ comp3: Comp3.Type, _ comp4: Comp4.Type, excludesAll excludedComponents: Component.Type) -> Family4<Comp1, Comp2, Comp3, Comp4> where Comp1: Component, Comp2: Component, Comp3: Component, Comp4: Component
A family is a collection of entities with uniform component types per entity. Entities that are be part of this family will have at least the 4 required components, but may have more components assigned.
A family is just a view on (component) data, creating them is cheap.
Use them to iterate efficiently over entities with the same components assigned.
Families with the same requirements provide a view on the same collection of entities (aka members).
A family conforms to the LazySequenceProtocol
and therefore can be accessed like any other (lazy) sequence.
General usage
let family = nexus.family(requiresAll: Comp1.self, Comp2.self, Comp3.self, Comp4.self)
// iterate each entity's components
family.forEach { (comp1, comp2, comp3, comp4) in
...
}
Caveats
-
Component types must be unique per family
-
Component type order is arbitrary
- comp1: Component type 1 required by members of this family.
- comp2: Component type 2 required by members of this family.
- comp3: Component type 3 required by members of this family.
- comp4: Component type 4 required by members of this family.
- excludedComponents: All component types that must not be assigned to an entity in this family.
The family of entities having 4 required components each.
Create a family of entities (aka members) having 5 required components.
public func family<Comp1, Comp2, Comp3, Comp4, Comp5>(requiresAll comp1: Comp1.Type, _ comp2: Comp2.Type, _ comp3: Comp3.Type, _ comp4: Comp4.Type, _ comp5: Comp5.Type, excludesAll excludedComponents: Component.Type) -> Family5<Comp1, Comp2, Comp3, Comp4, Comp5> where Comp1: Component, Comp2: Component, Comp3: Component, Comp4: Component, Comp5: Component
A family is a collection of entities with uniform component types per entity. Entities that are be part of this family will have at least the 5 required components, but may have more components assigned.
A family is just a view on (component) data, creating them is cheap.
Use them to iterate efficiently over entities with the same components assigned.
Families with the same requirements provide a view on the same collection of entities (aka members).
A family conforms to the LazySequenceProtocol
and therefore can be accessed like any other (lazy) sequence.
General usage
let family = nexus.family(requiresAll: Comp1.self, Comp2.self, Comp3.self, Comp4.self, Comp5.self)
// iterate each entity's components
family.forEach { (comp1, comp2, comp3, comp4, comp5) in
...
}
Caveats
-
Component types must be unique per family
-
Component type order is arbitrary
- comp1: Component type 1 required by members of this family.
- comp2: Component type 2 required by members of this family.
- comp3: Component type 3 required by members of this family.
- comp4: Component type 4 required by members of this family.
- comp5: Component type 5 required by members of this family.
- excludedComponents: All component types that must not be assigned to an entity in this family.
The family of entities having 5 required components each.
Create a family of entities (aka members) having 6 required components.
public func family<Comp1, Comp2, Comp3, Comp4, Comp5, Comp6>(requiresAll comp1: Comp1.Type, _ comp2: Comp2.Type, _ comp3: Comp3.Type, _ comp4: Comp4.Type, _ comp5: Comp5.Type, _ comp6: Comp6.Type, excludesAll excludedComponents: Component.Type) -> Family6<Comp1, Comp2, Comp3, Comp4, Comp5, Comp6> where Comp1: Component, Comp2: Component, Comp3: Component, Comp4: Component, Comp5: Component, Comp6: Component
A family is a collection of entities with uniform component types per entity. Entities that are be part of this family will have at least the 6 required components, but may have more components assigned.
A family is just a view on (component) data, creating them is cheap.
Use them to iterate efficiently over entities with the same components assigned.
Families with the same requirements provide a view on the same collection of entities (aka members).
A family conforms to the LazySequenceProtocol
and therefore can be accessed like any other (lazy) sequence.
General usage
let family = nexus.family(requiresAll: Comp1.self, Comp2.self, Comp3.self, Comp4.self, Comp5.self, Comp6.self)
// iterate each entity's components
family.forEach { (comp1, comp2, comp3, comp4, comp5, comp6) in
...
}
Caveats
-
Component types must be unique per family
-
Component type order is arbitrary
- comp1: Component type 1 required by members of this family.
- comp2: Component type 2 required by members of this family.
- comp3: Component type 3 required by members of this family.
- comp4: Component type 4 required by members of this family.
- comp5: Component type 5 required by members of this family.
- comp6: Component type 6 required by members of this family.
- excludedComponents: All component types that must not be assigned to an entity in this family.
The family of entities having 6 required components each.
Create a family of entities (aka members) having 7 required components.
public func family<Comp1, Comp2, Comp3, Comp4, Comp5, Comp6, Comp7>(requiresAll comp1: Comp1.Type, _ comp2: Comp2.Type, _ comp3: Comp3.Type, _ comp4: Comp4.Type, _ comp5: Comp5.Type, _ comp6: Comp6.Type, _ comp7: Comp7.Type, excludesAll excludedComponents: Component.Type) -> Family7<Comp1, Comp2, Comp3, Comp4, Comp5, Comp6, Comp7> where Comp1: Component, Comp2: Component, Comp3: Component, Comp4: Component, Comp5: Component, Comp6: Component, Comp7: Component
A family is a collection of entities with uniform component types per entity. Entities that are be part of this family will have at least the 7 required components, but may have more components assigned.
A family is just a view on (component) data, creating them is cheap.
Use them to iterate efficiently over entities with the same components assigned.
Families with the same requirements provide a view on the same collection of entities (aka members).
A family conforms to the LazySequenceProtocol
and therefore can be accessed like any other (lazy) sequence.
General usage
let family = nexus.family(requiresAll: Comp1.self, Comp2.self, Comp3.self, Comp4.self, Comp5.self, Comp6.self, Comp7.self)
// iterate each entity's components
family.forEach { (comp1, comp2, comp3, comp4, comp5, comp6, comp7) in
...
}
Caveats
-
Component types must be unique per family
-
Component type order is arbitrary
- comp1: Component type 1 required by members of this family.
- comp2: Component type 2 required by members of this family.
- comp3: Component type 3 required by members of this family.
- comp4: Component type 4 required by members of this family.
- comp5: Component type 5 required by members of this family.
- comp6: Component type 6 required by members of this family.
- comp7: Component type 7 required by members of this family.
- excludedComponents: All component types that must not be assigned to an entity in this family.
The family of entities having 7 required components each.
Create a family of entities (aka members) having 8 required components.
public func family<Comp1, Comp2, Comp3, Comp4, Comp5, Comp6, Comp7, Comp8>(requiresAll comp1: Comp1.Type, _ comp2: Comp2.Type, _ comp3: Comp3.Type, _ comp4: Comp4.Type, _ comp5: Comp5.Type, _ comp6: Comp6.Type, _ comp7: Comp7.Type, _ comp8: Comp8.Type, excludesAll excludedComponents: Component.Type) -> Family8<Comp1, Comp2, Comp3, Comp4, Comp5, Comp6, Comp7, Comp8> where Comp1: Component, Comp2: Component, Comp3: Component, Comp4: Component, Comp5: Component, Comp6: Component, Comp7: Component, Comp8: Component
A family is a collection of entities with uniform component types per entity. Entities that are be part of this family will have at least the 8 required components, but may have more components assigned.
A family is just a view on (component) data, creating them is cheap.
Use them to iterate efficiently over entities with the same components assigned.
Families with the same requirements provide a view on the same collection of entities (aka members).
A family conforms to the LazySequenceProtocol
and therefore can be accessed like any other (lazy) sequence.
General usage
let family = nexus.family(requiresAll: Comp1.self, Comp2.self, Comp3.self, Comp4.self, Comp5.self, Comp6.self, Comp7.self, Comp8.self)
// iterate each entity's components
family.forEach { (comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8) in
...
}
Caveats
-
Component types must be unique per family
-
Component type order is arbitrary
- comp1: Component type 1 required by members of this family.
- comp2: Component type 2 required by members of this family.
- comp3: Component type 3 required by members of this family.
- comp4: Component type 4 required by members of this family.
- comp5: Component type 5 required by members of this family.
- comp6: Component type 6 required by members of this family.
- comp7: Component type 7 required by members of this family.
- comp8: Component type 8 required by members of this family.
- excludedComponents: All component types that must not be assigned to an entity in this family.
The family of entities having 8 required components each.
public final func has(componentId: ComponentIdentifier, entityId: EntityIdentifier) -> Bool
public final func count(components entityId: EntityIdentifier) -> Int
@discardableResult public final func assign(component: Component, to entity: Entity) -> Bool
@discardableResult public final func assign<C>(component: C, to entity: Entity) -> Bool where C: Component
@discardableResult public final func assign<C>(components: C, to entity: Entity) -> Bool where C: Collection, C.Element == Component
@inlinable public final func get(safe componentId: ComponentIdentifier, for entityId: EntityIdentifier) -> Component?
@inlinable public final func get(unsafe componentId: ComponentIdentifier, for entityId: EntityIdentifier) -> Component
@inlinable public final func get<C>(safe componentId: ComponentIdentifier, for entityId: EntityIdentifier) -> C? where C: Component
@inlinable public final func get<C>(safe entityId: EntityIdentifier) -> C? where C: Component
@inlinable public final func get<C>(unsafe entityId: EntityIdentifier) -> C where C: Component
@inlinable public final func get(components entityId: EntityIdentifier) -> Set<ComponentIdentifier>?
@discardableResult public final func remove(component componentId: ComponentIdentifier, from entityId: EntityIdentifier) -> Bool
@discardableResult public final func removeAll(components entityId: EntityIdentifier) -> Bool
Create an entity assigning one component.
@discardableResult public func createEntity(using builder: () -> Component) -> Entity
Usage:
let newEntity = nexus.createEntity {
Position(x: 1, y: 2)
}
- builder: The component builder.
The newly created entity with the provided component assigned.
Create an entity assigning multiple components.
@discardableResult public func createEntity(using builder: () -> [Component]) -> Entity
Usage:
let newEntity = nexus.createEntity {
Position(x: 1, y: 2)
Name(name: "Some name")
}
- builder: The component builder.
The newly created entity with the provided components assigned.
Create multiple entities assigning one component each.
@discardableResult public func createEntities(count: Int, using builder: (ComponentsBuilder.Context) -> Component) -> [Entity]
Usage:
let newEntities = nexus.createEntities(count: 100) { ctx in
Velocity(a: Float(ctx.index))
}
- count: The count of entities to create.
- builder: The component builder providing context.
The newly created entities with the provided component assigned.
Create multiple entities assigning multiple components each.
@discardableResult public func createEntities(count: Int, using builder: (ComponentsBuilder.Context) -> [Component] = { _ in [] }) -> [Entity]
Usage:
let newEntities = nexus.createEntities(count: 100) { ctx in
Position(x: ctx.index, y: ctx.index)
Name(name: "\(ctx.index)")
}
- count: The count of entities to create.
- builder: The component builder providing context.
The newly created entities with the provided components assigned.
@discardableResult public func createEntity() -> Entity
@discardableResult public func createEntity(with components: Component) -> Entity
@discardableResult public func createEntity<C>(with components: C) -> Entity where C: Collection, C.Element == Component
Creates an iterator over all entities in the nexus.
public func makeEntitiesIterator() -> EntitiesIterator
Entity order is not guaranteed to stay the same over iterations.
public func exists(entity entityId: EntityIdentifier) -> Bool
public func entity(from entityId: EntityIdentifier) -> Entity
@discardableResult public func destroy(entity: Entity) -> Bool
@discardableResult public func destroy(entityId: EntityIdentifier) -> Bool
public func canBecomeMember(_ entity: Entity, in traits: FamilyTraitSet) -> Bool
public func members(withFamilyTraits traits: FamilyTraitSet) -> UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Identifier>
public func isMember(_ entity: Entity, in family: FamilyTraitSet) -> Bool
public func isMember(_ entityId: EntityIdentifier, in family: FamilyTraitSet) -> Bool
public func isMember(entity entityId: EntityIdentifier, inFamilyWithTraits traits: FamilyTraitSet) -> Bool
public final func clear()
public func single<S>(_ component: S.Type) -> Single<S> where S: SingleComponent
Generated at 2020-11-25T10:28:11+0000 using swift-doc 1.0.0-beta.5.
Types
- ComponentAdded
- ComponentIdentifier
- ComponentInstanceProvider
- ComponentRemoved
- ComponentSingletonProvider
- ComponentTypeProvider
- ComponentsBuilder.Context
- ComponentsBuilderPreview
- DefaultCodingStrategy
- DynamicCodingKey
- DynamicComponentProvider
- DynamicComponentProvider.Closure
- Entity
- Entity.ComponentsIterator
- EntityCreated
- EntityDestroyed
- EntityIdentifier
- EntityState
- EntityStateMachine
- Family
- Family.ComponentsIterator
- Family.EntityComponentIterator
- Family.EntityIterator
- FamilyMemberAdded
- FamilyMemberBuilderPreview
- FamilyMemberRemoved
- FamilyTraitSet
- LinearIncrementingEntityIdGenerator
- ManagedContiguousArray
- Nexus
- Nexus.EntitiesIterator
- Requires1
- Requires2
- Requires3
- Requires4
- Requires5
- Requires6
- Requires7
- Requires8
- Single
- StateComponentMapping
- StringHashing
- UnorderedSparseSet
- UnorderedSparseSet.ElementIterator
Protocols
- CodingStrategy
- Component
- ComponentProvider
- DefaultInitializable
- EntityIdentifierGenerator
- FamilyDecoding
- FamilyEncoding
- FamilyRequirementsManaging
- NexusEvent
- NexusEventDelegate
- RequiringComponents1
- RequiringComponents2
- RequiringComponents3
- RequiringComponents4
- RequiringComponents5
- RequiringComponents6
- RequiringComponents7
- RequiringComponents8
- SingleComponent
- TopLevelDecoder
- TopLevelEncoder