In order to get components to be able to update every frame (and leave this functionality out of components that don't need to) I got the idea to make an UpdateComponent component. Other components like MovableComponent
(which holds velocity) would inherit from the IUpdatable
abstract class. This forces MovableComponent
to implement an Update(gametime dt)
method and another RegisterWithUpdater()
that gives UpdateComponent
a pointer to the MovableComponent
. Many components could do this and then UpdateComponent
could call all of their Update(gametime dt)
methods without having to care about who or what they are.
My questions are:
- Does this seem like anything that is normal or used by anyone? I cannot find anything on the subject.
- How could I maintain an order to the components like physics then position change? Is this even necessary?
- What are other ways of insuring that components that should be process every frame are in fact processed?
EDIT
I think I will be concidering how to give the entity manager a list of types that are updatable. Then ALL of the components of that type can update rather than managing it per entity (which are just indexes in my system anyway).
Still. My questions remain valid to me. I don't know if this is reasonabl/normal, or what others tend to do.
Also, the people at Insomniac are awesome! /EDIT
Boiled down code for previous example:
class IUpdatable
{
public:
virtual void Update(float dt) = 0;
protected:
virtual void RegisterAsUpdatable() = 0;
};
class Component
{
...
};
class MovableComponent: public Component, public IUpdatable
{
public:
...
virtual void Update(float dt);
private:
...
virtual void RegisterWithUpdater();
};
class UpdateComponent: public Component
{
public:
...
void UpdateAll();
void RegisterUpdatable(Component* component);
void RemoveUpdatable(Component* component);
private:
...
std::set<Component*> updatables_;
};