Class
Archetypes
View sourceRegisters Archetype instances under zero-based ArchetypeId
values in insertion order.
Use Archetypes#set to append an archetype, Archetypes#get
to retrieve one by ID, and Archetypes#has or
Archetypes#getArchetypeWithOnly to search by component TypeIds.
Examples
import { Archetype, Archetypes } from '@wimaengine/ecs'
import { typeid } from '@wimaengine/type'
class Position {}
class Velocity {}
const archetypes = new Archetypes()
const position = typeid(Position)
const velocity = typeid(Velocity)
const id = archetypes.set(new Archetype(0, [position, velocity]))
archetypes.has([position]) // true: subset lookup allows velocity too
archetypes.getArchetypeWithOnly([position, velocity]) // [id, Archetype]Constructor
Methods
has(types: TypeId[]): boolean
View sourceChecks whether any registered archetype contains every requested TypeId.
This is subset lookup through Archetype#has: an archetype may
contain additional component types. The method returns only a boolean; use
Archetypes#getArchetypeWithOnly when the
matching archetype and its ID are needed.
get(id: ArchetypeId): Archetype
View sourceReturns the archetype stored at an allocated ID.
IDs are zero-based insertion indexes assigned by Archetypes#set. An
ID that has not been allocated returns
undefined because the lookup reads the backing array directly.
set(archetype: Archetype): ArchetypeId
View sourceAppends an archetype and assigns its next zero-based ID.
Every call appends the supplied object, even when an equivalent archetype
is already registered. The returned ID is the new entry’s index and is
also the value accepted by Archetypes#get.
size(): number
View sourceReturns the number of archetypes currently registered.
values(): readonly Archetype[]
View sourceReturns the live, ID-ordered collection of registered archetypes.
The returned collection is the registry’s backing array, typed as
read-only. Entries added by Archetypes#set are visible through the
same returned reference, so callers should treat it as read-only rather
than modifying it directly.
getArchetypeWithOnly(typeIds: TypeId[]): [ArchetypeId, Archetype]
View sourceFinds the first archetype whose component TypeIds exactly match the input.
Matching delegates to Archetype#hasOnly: the lists must
have the same length and contain the same TypeIds, regardless of order.
Pass a deduplicated set of TypeIds, as the exact check uses length plus
membership. The search follows allocation order and returns the matching
ID together with its archetype.
