Great explanation, thank you.
> This comes at a cost of making adding and removing components from an entity more expensive.
I think you could write a design-time tool that takes a simple description file (with hints) and outputs code that stores your entities and components efficiently.
Description file:
{
"archetypes": [
{
"components": [ "A", "B", "C" ]
},
{
"components": [ "B" ]
},
{
"components": [ "B", "C" ]
}
]
}
Output: class ArchetypeABC {
A a;
B b;
C c;
}
class ArchetypeB {
B b;
}
class ArchetypeBC {
B b;
C c;
}
class EntityStore {
ArchetypeABC[] entitiesABC;
ArchetypeB[] entitiesB;
ArchetypeBC[] entitiesB;
}