Color legend plain property method
Every component of one type, as a sparse set: the components packed into one array with no holes, the entity owning each at the same index of a second array, and a sparse array indexed by entity id that points into both. Adding, getting, asking and removing each take one step.
A sealed class, for any T that implements IComponent; it implements IComponentStore, whose GetBoxed and SetBoxed are reached through that interface. The world keeps one per component type and doesn’t hand them out; a store of your own works outside any world. The storage and performance page shows it in context, with code.
A store keys on Entity.Id alone and knows nothing of generations: every member answers for any handle with the id, alive or not.
Names are colored by what they are: a property or a method; values and fields keep the plain color.
Properties
ComponentType →
Type · Read-only. Always typeof(T). From IComponentStore.
Components →
Span<T> · Read-only. The packed components, Count of them: Components[i] belongs to Entities[i]. A view of the store’s array, not a copy, so changes through it go into the store. Any add or remove may move the components: don’t keep the span across one.
Count →
int · Read-only. How many entities have a component in the store.
Entities →
ReadOnlySpan<Entity> · Read-only. The entity owning each of Components, index for index: the handle the entity’s component was first set with.
Methods
ComponentStore() →
ComponentStore() · An empty store, with room for 16 components and ids up to 15 before it grows.
Get() →
Get(Entity entity) · Returns ref T: a reference to the entity’s component, to read and write in place. Valid until the next add or remove. Throws KeyNotFoundException when the entity has none.
| Parameter | Type | Description |
|---|---|---|
entity |
Entity |
The entity whose component to get. |
Has() →
Has(Entity entity) · Whether an entity with the id has a component here. false for a negative id.
| Parameter | Type | Description |
|---|---|---|
entity |
Entity |
The entity to ask about. |
IndexOf() →
IndexOf(Entity entity) · Where the entity’s component sits in Components, and the entity in Entities, or −1 when it has none. One sparse lookup, which is all Has and Get cost too: code that needs both the answer and the component looks up once and indexes the span. The world’s queries do.
| Parameter | Type | Description |
|---|---|---|
entity |
Entity |
The entity to look up. |
Remove() →
Remove(Entity entity) · Removes the entity’s component, moving the last component, and its entity, into its place: the order of the packed arrays changes. Clears the freed slot when T holds references, so the store doesn’t keep a removed object alive. Does nothing when the entity has none. From IComponentStore.
| Parameter | Type | Description |
|---|---|---|
entity |
Entity |
The entity whose component to remove. |
Set() →
Set(Entity entity, in T component) · Adds the entity’s component at the end of the packed arrays, or overwrites the one it has where it is. The arrays double when they fill up, and the sparse array grows to fit the id. Throws ArgumentOutOfRangeException for a negative id, such as Entity.Invalid’s, or one too large for an array.
| Parameter | Type | Description |
|---|---|---|
entity |
Entity |
The entity whose component to set. |
component |
T |
The component, copied into the store. |