src/necsus/runtime/archetypeStore

Search:
Group by:

Types

ArchetypeStore[Comps] = object
Stores a specific archetype shape
ArchRow[Comps] = object
  entityId*: EntityId
  components*: Comps
A row of data stored about an entity that matches a specific archetype
ArchRowSpan = object
Every row an archetype had at the moment the span was taken, described without the shape of the components in it. That is what lets a single walk cover archetypes that do not share a shape
NewArchSlot[Comps] = distinct Entry[ArchRow[Comps]]
RawArchRow = object
A single row, reached without knowing the shape of the components in it. Where each half of the row sits is worked out here, so a caller never has to know how a row is laid out

Procs

proc `=copy`[Comps: tuple](target: var ArchetypeStore[Comps];
                           source: ArchetypeStore[Comps]) {.error.}
proc `=copy`[Comps: tuple](target: var ArchRow[Comps]; source: ArchRow[Comps]) {.
    error.}
func addLen[Comps: tuple](store: var ArchetypeStore[Comps]; len: var Natural)
Accessor for the archetype of a store
proc addLen[Comps: tuple](store: var ArchetypeStore[Comps]; len: var Natural;
    predicate: proc (row: var Comps): bool {.nimcall, ...gcsafe, raises: [].})
Reads the length of an archetype store, using a predicate to determine whether to count a row
proc components(row: RawArchRow): pointer {.inline, ...raises: [], tags: [],
    forbids: [].}
The components in a row, untyped. Only code generated against this archetype knows the shape well enough to read them
proc del(store: var ArchetypeStore; index: uint)
Return the components for an archetype
proc ensureAlloced[Comps: tuple](store: var ArchetypeStore[Comps])
Allocs the memory for this archetype if it hasn't been alloced already
proc entityId(row: RawArchRow): EntityId {.inline, ...raises: [], tags: [],
    forbids: [].}
The entity a row belongs to. Only read if a caller actually asks for it
proc entityId[Comps: tuple](entry: NewArchSlot[Comps]): EntityId
proc getComps[Comps: tuple](store: var ArchetypeStore[Comps]; index: uint): ptr Comps
Return the components for an archetype
proc index[Comps: tuple](entry: NewArchSlot[Comps]): uint
proc isEmpty(span: ArchRowSpan): bool {.inline, ...raises: [], tags: [],
                                        forbids: [].}
Whether this span covers any rows at all
proc moveEntity[FromArch: tuple; NewComps: tuple; ToArch: tuple](
    world: var World; entityIndex: ptr EntityIndex;
    fromArch: var ArchetypeStore[FromArch]; toArch: var ArchetypeStore[ToArch];
    newValues: sink NewComps; combine: proc (existing: sink FromArch;
    newValues: sink NewComps; output: var ToArch): bool {....gcsafe, raises: [],
    nimcall.}) {....gcsafe, raises: [ValueError].}
Moves the components for an entity from one archetype to another
proc newArchetypeStore[Comps: tuple](archetype: ArchetypeId;
                                     initialSize: Natural): ArchetypeStore[Comps]
Creates a new storage block for an archetype
proc newSlot[Comps: tuple](store: var ArchetypeStore[Comps]; entityId: EntityId): NewArchSlot[
    Comps]
Reserves a slot for storing a new component
proc next[Comps: tuple](store: var ArchetypeStore[Comps]; iter: var BlockIter;
                        eid: var EntityId): ptr Comps {.inline.}
Returns the next row of components in this archetype store
proc readArchetype(store: ArchetypeStore): ArchetypeId {.inline.}
Accessor for the archetype of a store
proc setComp[Comps: tuple](slot: NewArchSlot[Comps]; comps: sink Comps): EntityId
Stores an entity and its components into this slot
proc wholeSpan[Comps: tuple](store: var ArchetypeStore[Comps]): ArchRowSpan {.
    inline.}
Returns every row in this archetype. Callers walk the rows themselves, which keeps the archetype out of the per row path entirely

Iterators

iterator entityIds[Comps](store: var ArchetypeStore[Comps]): EntityId
iterator rows(span: ArchRowSpan): RawArchRow {....raises: [], tags: [], forbids: [].}
Walks the rows in a span, resolving where each half of a row sits as it goes