ECS Library
ECS Library
WIP Personal Work Library C++
I decided to make an ECS (Entity Component System) library so I could add it to any project and make it work without problems. To do this I have been improving the library as I have been working on different projects that include ECS

With this library the intention is to give the user all the facility to use the ECS architecture without having to worry about the operation. You can create as many Components and Systems as you need

For the ECS to work, Entities are needed, which store a bitmask with the bits of the active components, and their position in the Archetype

Components which are objects where the information is stored, these components are stored inside the Archetypes

The Archetypes are structures that store the components followed in memory, an Archetype is created for each combination of components that exists, so they can all be read at the same time

And finally the Systems that look for the Archetypes with the combination of components they need and work with them sequentially in memory
Explanation
To implement ECS you must have 3 objects, the Entities, the Components and the Archetypes.

Components are objects that only store local information, for example a local transformation component stores position, rotation and scaling. These components have assigned a bit of the entity to know if that entity contains or not the component, for example a component of the local transformation has assigned the second bit to know if it is added to the entity.

The Entities are an object that stores a bit mask with the bits of the active components, for example if you want to add to the entity the component of the local transformation, the second bit would be set to 1. With this you can know with a check if that entity has a particular component. The Entities also have an id to know where it is within the archetype.

The Archetype is a combination of components, every time a component is added to an entity the component is added to an archetype and the entity is told the id it has in that archetype, it also has a component mask to know which components the archetype has. There is one archetype for each combination of components, so all entities that have the same components are in the same archetype. For example you have 3 entities the first entity contains 2 components, the local transformation component, and the Render component, the second entity has only the local transformation component, and the third entity has the same components as the first entity. This would have created 2 archetypes 1 with the local transformation component, which would be the component of the second entity. Another archetype would also have been created with 2 components, one of local transformation and the other of rendering, in this archetype would be the components of the first and third entity.

Finally, in order to have the correct ECS implementation, the systems are missing. The systems are functions that go through the archetypes looking for the configuration given by the user. For example if you want to paint the objects on screen you have to make a system that runs through all the archetypes until it finds an archetype that contains the Render, Material and Local Transformation components. Once the system has found the archetype it only has to go through it and there is no need to jump in the memory since that archetype has all the components together. You can also indicate if you do not want to access an entity that has a specific component. To know if an archetype has a component, the archetype mask is checked to quickly find the archetypes that meet the condition.