I recently wrote a small article about an entity component system https://maikklein.github.io/2016/01/14/Entity-Component-System/
The gist of it is that I layout components into groups which are completely contiguous in memory and then I filter those groups at compile time. That gives me close to perfect cache efficiency.
A problem with this approach was that the compile times went up quite a bit but I recently ported the ecs to D which compiles in under a second.
Another problem is that adding components is a bit expensive. If I want to add a component at runtime, I would copy all components of the entity to a new group. For example an entity is inside the component group but if I want to add another component I would need to copy the components to "component group".
This would make temporary components a bit expensive, I am not sure at this stage how big of a problem this would be.
Also I currently impelemented handles with "smart ptrs" which seemed like a nice idea at the time, it was super easy to implement and gives me great perfomance but I just relaized that this makes serialization a nightmare.
But switching to good old handles like
struct Handle{
int id;
int counter;
}; would be a problem because I move my components in memory to keep them contigous, which is not a big problem with my "smart ptrs" because they automatically update and null if the entity is deleted, but this doesn't really work with plain old handles like the handle struct that I have posted above.
Which makes me think if I should switch to a different design all together.
I think the most common ecs is something like this:
Systems already know which entities it needs to iterate over
For example:
PrintSystem: Required NameComponent and PrintComponent => EntityId1, EntityId30, EntityId44, EntityId64
Then the system is probably a lot more flexible and easier to implement. It even is contigous in memory but it doesn't necessarily iterate contiguously over the components.
For example the components of EntityId1 and EntityId30 could lie far away in memory from each other.
Any tips are greatly appreciated.