Anders429 / brood

A fast and flexible entity component system library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Store zero-sized components separately

Anders429 opened this issue · comments

ZSTs that are components, commonly called "marker" components or "tag" components, may not actually warrant inclusion in the archetype identifier. They are not actually stored, and are just used to mark something about an entity.

I wonder if there is a better solution, using some separate storage for what ZSTs are applied to each entity within an archetype. This way, we don't have to reallocate and move the entire entity when changing what ZSTs are applied to the entity.

We can use some kind of trait extension on Component, adding a IS_ZST associated constant to the component. Then this can be used to branch when storing or modifying an entity. The sized components will be stored as normal, but the ZST components will be stored in some kind of set, mapping which entity identifiers they are associated with. Care will need to be taken in designing this feature, to ensure it doesn't slow down storage or iterating.

The advantage gained here should be an increase in performance when adding or removing ZSTs from an entity. It will save reallocation and the expensive moving of an entire entity to another archetype.