Archetype

View source

Represents one exact ECS component layout and its associated table ID.

Use Archetype#has for subset matching: every requested component TypeId must be present, but the layout may contain additional components. Use Archetype#hasOnly for exact-set matching. Both checks are order-independent, and exact matching expects deduplicated TypeId lists.

The table ID identifies the table associated with this component layout.

Examples

const tableId = 0
const archetype = new Archetype(tableId, [positionTypeId, velocityTypeId])

archetype.has([positionTypeId]) // true: a required subset is present
archetype.hasOnly([positionTypeId]) // false: velocityTypeId is also present
archetype.hasOnly([velocityTypeId, positionTypeId]) // true: same set, new order

Constructor


constructor(tableId: TableId, types: TypeId[])

View source

Creates an archetype for a table and component TypeId set.

Parameters

NameDescriptionDefault
tableId——
types

Component TypeIds in the table’s layout.

—

Properties


readonlytypes: readonly TypeId[]

View source

Component TypeIds that define this archetype’s layout.

Matching methods treat this collection as a set and do not depend on its order.

readonlytableId: TableId

View source

ID of the table associated with this archetype’s layout.

This is the table’s identity, not an ID assigned by an archetype registry.

Methods


has(typeids: TypeId[]): boolean

View source

Checks whether this layout contains every requested component TypeId.

This is subset matching. Extra component TypeIds in the layout do not affect the result.

Parameters

NameDescriptionDefault
typeids

Component TypeIds that must be present.

—

Returns

true when every requested TypeId is present.

hasOnly(typeIds: TypeId[]): boolean

View source

Checks whether this layout has exactly the requested component set.

The lists must have the same length and every requested TypeId must be present. Order does not matter, but callers should provide deduplicated TypeId lists because the check uses length plus membership.

Parameters

NameDescriptionDefault
typeIds

The complete component TypeId set to match.

—

Returns

true when the requested set exactly matches this archetype.