Original Post
I've been researching a lot into component based systems and have kind of come to point where I'm not really sure of the best way to update components per frame or control their update order. In all my reading I have basically found at least 3 different approaches.
These all have there pros and cons which I'll briefly state:
1)
Pros:
- Simple to use and manage as behaviours are contained within each component.
Cons:
- Cost of virtual call overhead
- No clear way to order update calls between components (at least that I can see)
2)
Pros:
- Same as 1 except no virtuals.
- Fits in with current use of signals/slots for attribute change notification
Cons:
- Has some overhead but not sure if its more than virtuals?
3)
Pros:
- Solves the update call order problem as each component manager can be called in order based on the game/engine context.
Cons:
- Manager explosion! You could require a manager for every type of component. This could be really hard to maintain :/
Would really appreciate what others with experience on this topic have to say and what decisions they made in their systems, etc.
Cheers!
- You have a component interface with a virtual Update() function. The entity that owns this component has an Update() function which iterates all it's components calling their Update().
- Similar to #1 except you use a signal/slot setup where components can subscribe to an OnUpdate event in entity that owns them.
- There is no such thing as Update() within components or entities. This update logic is moved to another class which manages a particular component type.
These all have there pros and cons which I'll briefly state:
1)
Pros:
- Simple to use and manage as behaviours are contained within each component.
Cons:
- Cost of virtual call overhead
- No clear way to order update calls between components (at least that I can see)
2)
Pros:
- Same as 1 except no virtuals.
- Fits in with current use of signals/slots for attribute change notification
Cons:
- Has some overhead but not sure if its more than virtuals?
3)
Pros:
- Solves the update call order problem as each component manager can be called in order based on the game/engine context.
Cons:
- Manager explosion! You could require a manager for every type of component. This could be really hard to maintain :/
Would really appreciate what others with experience on this topic have to say and what decisions they made in their systems, etc.
Cheers!