Create, Read, Update, Delete
fennecs.Entity
is a builder struct that combines its associated fennecs.World
and fennecs.Identity
to form an easily usable access pattern which exposes operations to add, remove, and read Components , Links , and Relations. You can also conveniently Despawn the Entity.
The component data is accessed and processed in bulk through Queries, a typical way that ECS provide composable functionality.
Specific Component Operations
Ref<T>()
: Get a reference to a component Ref<T>(Entity relation)
: Get a reference to a component backing a relation (useful for reassigning the value, but not the relation)
Get<T>(Match match)
: Gets all components matching the expression; e.g.entity.Get<MyLinkType>(Link.Any)
to get all the Links.Components
: Returns anIReadonlyList<Component>
of all components on the entity. See Boxed Components for more information.
Interface IAddRemoveComponent
The IAddRemoveComponent<SELF>
interface provides methods for adding and removing components from entities or sets of entities. It follows a fluent pattern, allowing chained method calls.
Adding Components
Add<C>()
: Adds a default, plain newable component of typeC
to the entity/entities.Add<C>(C value)
: Adds a plain component with the specified value of typeC
to the entity/entities.Add<T>(Entity relation)
: Adds a newable relation component backed by a default value of typeT
to the entity/entities.Add<R>(R value, Entity relation)
: Adds a relation component backed by the specified value of typeR
to the entity/entities.Add<L>(Link<L> link)
: Adds an object link component with an object of typeL
to the entity/entities.
Removing Components
Remove<C>()
: Removes a plain component of typeC
from the entity/entities.Remove<R>(Entity relation)
: Removes a relation component of typeR
with the specified relation from the entity/entities.Remove<L>(L linkedObject)
: Removes an object link component with the specified linked object from the entity/entities.Remove<L>(Link<L> link)
: Removes an object link component with the specified link from the entity/entities.
All methods return the interface itself (SELF
), allowing for fluent method chaining.
Note: The type parameters C
, T
, R
, and L
have constraints to ensure they are non-null and/or class types.
Interface IHasComponent
The IHasComponent
interface provides methods for checking the presence of components on an entity or set of entities.
Has Component
Has<C>()
: Checks if the entity/entities has a plain component of typeC
.Has<R>(Entity relation)
: Checks if the entity/entities has a relation component of typeR
with the specified relation.Has<L>(L linkedObject)
: Checks if the entity/entities has an object link component with the specified linked object.Has<L>(Link<L> link)
: Checks if the entity/entities has an object link component with the specified link.
All Has
methods return a boolean value indicating whether the entity/entities has the specified component. Therefore, they can only be at the end of a chain.
Note: The type parameters C
, R
, and L
have constraints to ensure they are non-null and/or class types.
Entity.Despawn
Entity.Despawn()
: Despawns the Entity from its World.
Caveats
BEWARE of FRAGMENTATION
Use Object Links and Relations sparingly to group larger families of Entities. The difference to a reference type Component is that an entity can have any number of Object Links or Relations of the same type. This means that for n
different linked Objects or target Entities, up to n!
Archetypes could exist at runtime were you to attach all permutations of them to Entities at runtime.
Naturally, only Archetypes for actual constellations of Links and Relations on Entities will exist, so it is entirely up to your code. Great power, great responsibility.