How Do Entities Index To Relevant Component Datas?

I’m familiar with databases so the ECS memory layout concept isn’t new. What is strange is how an entity (an id plus version number) automagically computes indexes into respective data arrays. How is this done?

It’s done via a lookup.
There’s a single freelist of EntityData structs, each containing a reference to the chunk and index offset for that Entity.
The Entity.Index refers directly to the index in the freelist, from which it can then directly index into the chunk and individual components. Double indirection lookup.
However for the most part, you’re simply iterating arrays where no lookup is required.
Only the index is needed for the lookup. The version serves another purpose.

1 Like