Building an ECS #2: Archetypes and Vectorization
Created on 2024-03-28T12:32:32-05:00
An array of components is useful for traveral, but you may end up skipping over large ranges of unrelated components.
Archetypes allow storing an array of components per archetype; thus iterating results only in component IDs that are relevant to a given process.
Entities can store the archetype they belong to and offset in the archetype's data storage. Doing this lets you easily jump from an ID to a component table.
Components have a list of archetypes they belong to, because there are less components than archetypes.
You can store which column of an archetype the component is stored within in that list to speed up fetches.
Archetype graph: giving each archetype a sparse table of where to find another archetype if you add or removed a single component. This lets you find where an entity should migrate to during attachment changes.