Well I'm having some doubts while implementing an ECS, I'll try to explain as best as I can...
I'm using this java implementation of the ECS:
Lets take an example to see my problems with the ECS implementation. We have a side scrolling platformer game (metal slug, flashback, whatever ). We have the man entity (it could be the player or an enemy) with many components (position, weapon, etc.). What if we want to have several sprites/animations for the entity? (running, jumping, etc.)
I've thought some solutions:
1. Collections of components, so a "man" can have multiple sprite/animation component. That involves some changes in the ECS base code, chaging the entitymanager to fit lists of components.
In the graphics subsystem we will render every sprite/animation that is active.
We will have another subsystem to take care of which sprite/animation in the list of an entity is active or not, we can call it ManStateSubsystem. It will look into ManState to activate/deactivate the sprites/animations.
If we do this the graphic subsystem will just render active sprites/animations. But it will also go through many inactive components all the time.
2. Complex component, a bigger component that holds multiple components (a list of sprites, a list of animations, a list of sounds, etc.), it could be "ResourceComponent" and it holds all the assets related to the player (we could have empty lists in certain situations).
Similar to previous method, the graphics subsystem will also render active items, but now they could be sprite/animation and this new complexGraphicalComponent, which will need more code.
Same "ManStateSubsystem" to take care of activating/deactivating resources.
Similar issues as previous solution, traverses many inactive components.
It will also need more memory (we have sprite and animation lists inside the complexGraphicalComponent even if we only have 1 sprite).
For me it looks a little bit better than previous method, since we have resources grouped in a single component, rather than having lists of components.
3. Complex component, we have the same complexGraphicalComponent, but instead of rendering this component, we will have to remove/add current animation/sprite as a component to the entity.
Graphical system will only handle sprite/animations, and it won't check wether they're active or not.
ManStateSubsystem will take care of removing/adding components to an entity (implies adding removeComponent).
This approach seems like it's not breaking that much the concept behind ECS.
It has a limitation: an entity can't have more than 1 sprite and animation, so we won't be able to render 2 sprites for a single entity (looking at our example we won't be able to draw different trousers and shirts inside a single entity).
How would you solve this situation??