src/necsus/runtime/query

Types

AnyQuery[Comps] = Query[Comps] | FullQuery[Comps]
FullQuery[Comps] = distinct RawQuery[Comps]
Allows systems to query for entities with specific components. Where Comps is a tuple of the components to fetch in this query. Provides access to the EntityId
Not[Comps] = distinct int8
A query flag that indicates a component should be excluded from a query. Where Comps is the single component that should be excluded.
Query[Comps] = distinct RawQuery[Comps]
Allows systems to query for entities with specific components. Where Comps is a tuple of the components to fetch in this query. Does not provide access to the entity ID
QueryConvert[Comps] = proc (input: pointer; adding: pointer; output: var Comps): bool {.
    ...gcsafe, raises: [], nimcall.}
Copies the components of a single row into the shape a query asked for. Returns false for rows that the query turns out not to want after all
QueryGetSpan[Comps] = proc (appStatePtr: pointer; state: var uint;
                            span: var QuerySpan[Comps]): bool {....gcsafe,
    raises: [], nimcall.}
QueryItem[Comps] = tuple[entityId: EntityId, components: Comps]
An individual value yielded by a query. Where Comps is a tuple of the components to fetch in this query
QuerySpan[Comps] = object
A run of consecutive rows belonging to one archetype. Queries hand these out rather than individual rows so that the walk over the rows stays in the caller, where the cursor lives in registers instead of behind a call
RawQuery[Comps] = ref object
Allows systems to query for entities with specific components. Where Comps is a tuple of the components to fetch in this query.

Procs

proc asFullQuery[Comps](rawQuery: RawQuery[Comps]): FullQuery[Comps]
proc asQuery[Comps](rawQuery: RawQuery[Comps]): Query[Comps]
proc len[Comps: tuple](query: AnyQuery[Comps]): Natural {....gcsafe, raises: [].}
Returns the number of entities in this query
proc newQuery[Comps: tuple](appState: pointer; getLen: QueryGetLen;
                            getSpan: QueryGetSpan[Comps]): RawQuery[Comps]
proc newQuerySpan[Comps: tuple](archSpan: ArchRowSpan;
                                convert: QueryConvert[Comps]): QuerySpan[Comps] {.
    inline.}
Describes a run of rows to be walked by a query
proc single[Comps: tuple](query: AnyQuery[Comps]): Option[Comps]
Returns a single element from a query

Iterators

iterator items[Comps: tuple](query: AnyQuery[Comps]): Comps
Iterates through the entities in a query
iterator pairs[Comps: tuple](query: FullQuery[Comps]): QueryItem[Comps]
Iterates through the entities in a query
iterator rows[Comps: tuple](span: QuerySpan[Comps]; slot: var Comps): RawArchRow
Walks the rows of a span that the query actually wants, filling slot with the components of each