Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 163429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:33:57+00:00 2026-05-11T11:33:57+00:00

In a game, many entities should be updated every frame. Im toying with different

  • 0

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?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:33:58+00:00Added an answer on May 11, 2026 at 11:33 am

    First, you need to use remove() instead of erase() (the latter would need an iterator as argument)

    If you use a slightly different loop like

    std::list<Logic*>::iterator it = all.begin(); while (it != all.end()) {   Logic* current = *it;   ++it;   current->update(deltatime); } 

    you can even overcome the problem siukurnin mentioned (deletion of a Logic object during update()). list::remove() doesn’t invalidate iterators except of the ones pointing to the removed element.

    Apart from this, I also vote for this being a variation of the singleton pattern. And I would suggest for keeping the original solution with a separate management class, just in case you want to have to have two loops with different delta times or explicit multithread support (different Logic objects on different threads) or whatever in the future.

    In my opinion this is a general advantage of the singleton class over static methods (which you could always use): You can easily multiply your functionality if you want to do so in the future …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've asked questions on here so many times about this ruddy game that I'm
I have several different color block images that are reused in my game many
I have a table which stores highscores for a game. This game has many
I'm making my first D3D simple game. My game uses many images. This is
I'm designing game site where many (hopefully thousands) players will simultenaously play certain card
I have played many Point and Click adventure game (Broken Sword, Sam & Max,
I've looked at many collision detection technique for a 2D game but I can't
I'm working a game. The game requires entities to analyse an image and head
I'm working on a game that has many elements on stage, so I'm looking
I'm in the design/skeleton coding phase of my C++ game with Lua scripting, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.