I'm writing an entity component system for a project I've been working on. It's currently in a working condition, and overall i'm pretty happy with it, but I've noticed that adding new components and systems to it requires quite a lot of boilerplate code.
I've been researching ECS a bit, and I'm not entirely sure if that's normal or not. None of the things I've read mention how much boilerplate is typically necessary to add new components or systems.
Here is how I designed my ECS. The Entity class carries an id and a map of smart pointers to it's components. Entities are defined in YAML, and a factory class parses the YAML and creates all the components an entity needs. Entities are stored in the main engine class.
Systems hold a vector of nodes, each node containing only the components needed by the particular system. Each update, the system loops through the nodes, removing ones with invalid pointers and updating ones with valid pointers.
As of right now, boilerplate for component creation is not too bad. Each new component must also come with a function that returns an instance of itself, and the factory needs to have it's map of function pointers updated to include said function.
Boilerplate for making new systems is worse. The pointers in each node are hard coded. If a node needs to hold a lot of pointers to different components, things get messy quickly. The Node constructor lists every component pointer. The function for registering entities has to check if the entity contains any of the components. The update function has to check to validity of each pointer in the node.
Obviously all of these things need to be done, but making changes to the components a node holds requires updating the system in 4 different places, and creating a new component requires updating things in the factory class.
If lots of boilerplate code is the reality of working with entity component systems, then I'm alright with it because there are a lot of benefits. However, I'm not satisfied with not knowing if there is a better way to handle these things.