Skip to content

Get rid of the "trivial types restriction" #123

@mlange-42

Description

@mlange-42

Due to storing components in type-erased byte vectors, Larecs does currently support only trivial types that don't contain any pointers and heap-allocated fields. Here is an idea how to solve that. I did this in the Julia port of Ark, Ark.jl.

There is a "component storage" for every component type C, with a type like

Vector[ Optional[Vector[C]] ]

Component storages are stored in a tuple or another collection for heterogenious (but known) types. This tuple-like type can be generated at compile-time, as components are parameters of the world. This allows us to store component instances with known type.

Archetypes don't have (type-erased) columns anymore, but just contain the list of component IDs they have, and the usual masks.

Arch. ID  Component Storages         Archetypes

           A    B    C  ...
     0    V[A]  -    -               [0]
     3    V[A] V[B]  -               [0, 1]
     2     -    -   V[C]             [2]
     4    V[A] V[B] V[C]             [0, 1, 2]
     :
     :     ^
           |
           Component storage for A

As queries are also parameterized by their component types, they can get their component storages at compile time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions