I'm trying to build a entity component system. Here is what I have :
An entity, that can have components : these are derived from a base "Component" class to carry common methods like OnCreated(), etc... Now, I want to add "Systems" that can operate on components to do the actual calculations. For example, a "Physics" system would loop over all physics component to update them, a "Renderer" system would loop over mesh components, etc...
My first idea was to have an template Update method, taking a system as a template type. Then, any component that want to be used by some system would only need to override that specific Update method for that system. Here was the idea :
// base component class
class Component {
template<class S>
virtual void Update(float _deltaTime) { } // empty on base component
}
// system class (inherits from the system base class)
class Physics : System {
void Update(float _deltaTime) {
// call Update<Physics>(float _deltaTime) on every concerned component
}
}
// component class somewhat related to the physics system
class Collider : Component {
void Update<Physics>(float _deltaTime) { /* calculations */ }
}
Now, I've read from here that it is not possible to override template methods. As I'm still learning C++, I can't think of a system that would allow what I want. So is there any smarter / possible ways to do what I want to achieve ?
Thanks in advance :