In a game, many entities should be updated every frame. Im toying with different design patterns to achieve this. Up until now, Ive had a singleton manager class to which every Logic instance is added. But Im considering the following, a static list in the Logic class itself. This is nice since it would remove a class from the project. "Engine" in this example would be the master class calling the update_all.
class Logic
{
public:
Logic() { all.push_back(this); }
virtual ~Logic() { all.erase(this); }
virtual void update(float deltatime) = 0;
private:
friend Engine;
static std::list<Logic*> all;
static void update_all(float deltatime)
{
for (std::list::iterator i = all.begin(); i!=all.end(); ++i)
(*i)->update(deltatime);
}
};
- Does this pattern have a name?
- Do you consider this a nicer approach than a singleton manager class?
- Any other comments or caveats?