I am running into some road blocks attempting to effectively implement ECS methodology. I have a heavy background in OOP, and I think that is really tainting my perspective.
According to a lot of the information I have gathered regarding ECS, one of the primary benefits is that each system is supposed to work independently, and also, using components should help avoid memory cache issues since components should be stored in contiguous Memory.
The problem that I am experiencing is the following.
Given a particular element for which Rendering, Animation and Physics need all be applied there is a particular sub set of information which must be available and synchronized to all systems, while an overlapping subset of information may not require availability and synchronization.
For the rendering system to work it requires a component containing a Sprite, a position and a rotation.
For the physics system to work it requires a component containing a position, a force and a rotation.
The animation system is slightly more complex, as there are three types of animation
1) Tile: No animation, requires only a sprite
2) Simple Animation: Loops through a single animation, requires a set of sprites
3) State Animation: Infers sprite from a state and a TimeInState, requires a State and a set of sets of sprites.
So it seems that there is the following portions of data required for the ECS as a whole (not partitioned into components):
Sprite - Current sprite representative of entities animation
Rendering system Read
Animation system Write
Sprites - Complete set of sprites available to entity
Animation system Read
State - Current state of entity
<Some System> Write
Animation System Read
TimeInState - How long entity has been in a particular state, to enable mapping to a specific frame of a specific animation
<SomeSystem> Write
AnimationSystem Read
Position - Both physics position and drawing position (while in an idealized situation they would be equal in actuality they are only tightly coupled through some mapping function i.e drawing Y often equals -physics Y, and physics often work of Center of gravity while rendering works on either top left corner, or center of sprite)
Physics system Read/Write
Rendering System Read
Rotation - Both physics position and drawing position (similar issues to position, but possible to avoid)
Physics system Read/Write
Rendering System Read
Force - Physics
<some system> Write
Physics system Read
-----------------------------------------------
As you can see, it becomes a rats nest of inter connectivity destroying the System Independence principle. Also, since each system uses multiple components it also destroys the Contiguous memory access principal as well. Some sources concede that complete system independence is not always possible but the breakage is acceptable as long as the more performance enhancing principal of contiguous memory access is preserved, this is seems would require Data duplication, something that I find great difficulty in accepting as good practice (this may be due to OOP and Database bias).
The animation Components present a new challenge entirely... namely, how to efficiently store jagged arrays in contiguous memory.
In my particular case it turns out to be a jagged array of jagged arrays. I plan to use a image packing software to create image atlases, the image packing software produces a string->box mapping file so a particular sprite can be located by providing the sprites String formatted Name/Id. Also, since various states may have more or less frames than other states, and since some entities may have more or less states than others you can see that the first jagged array is entity to states, followed by states to frames and finally frames to strings.
I suppose the gist of this post is.... ARRRRGGGG, WTF?!?! HELP PLZ!!