Class
Tables
View sourceRegisters Table instances under allocated TableId values.
Tables assigns zero-based IDs in insertion order. Use
Tables#resolveTableFor to reuse a table with an exact component
TypeId set, or Tables#createTable to always append a new table.
Matching table IDs can be collected with Tables#getTableIds.
Examples
import { Tables } from '@wimaengine/ecs'
import { typeid } from '@wimaengine/type'
class Position {}
const tables = new Tables()
const position = typeid(Position)
const [id, table] = tables.resolveTableFor([position])
tables.get(id) === table // true
tables.getTableIds([position], []) // [id]Constructor
Methods
createTable(typeIds: TypeId[]): [TableId, Table]
View sourceAppends a new empty table and assigns its next table ID.
The ID is the current list length, so IDs are zero-based and follow
allocation order. This method always creates a new Table; it does
not search for an existing layout. Use Tables#resolveTableFor when
an exact layout should be reused.
get(id: TableId): Table
View sourceReturns the table stored at an allocated ID.
IDs are direct indexes into the registry. An unallocated or cleared ID
therefore returns undefined; this lookup does not create a table or
validate the table’s contents.
values(): readonly Table[]
View sourceReturns the live, ID-ordered table collection.
The returned value is the registry’s backing array, typed as read-only.
Tables appended by Tables#createTable are visible
through the same reference. The Tables#clear method replaces the
backing array, so a reference obtained before clearing remains a snapshot
of the old array and does not receive later tables.
resolveTableFor(ids: TypeId[]): [TableId, Table]
View sourceFinds or creates the table for an exact component TypeId layout.
The search follows table-ID order and delegates exact matching to
Table#hasOnly: the input and table column sets must have
the same length and every input ID must be present, regardless of order.
Pass one occurrence of each TypeId. The first exact match is returned;
when none exists, this method delegates to Tables#createTable and
returns the newly allocated pair.
getTableIds(comps: TypeId[], filtered: TableId[]): TableId[]
View sourceAppends IDs of tables containing every requested component TypeId.
This is subset filtering: a table may contain additional columns. The
registry is scanned in ID order, matching IDs are appended to the supplied
filtered array, and that same array is returned. Existing entries in
filtered are preserved; this method does not clear or deduplicate it and
does not inspect table rows.
clear(): void
View sourceRemoves all tables from the registry.
Clearing replaces the backing list with a new empty array. Future tables
therefore start again at table ID 0; table objects or arrays returned
before the clear are not mutated, but they are no longer registered here.
