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

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Possible if: Someone writes a generic ORM to Bigtable mapper.… May 11, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer If I understand you correctly, you're building a report on… May 11, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer This article says you cannot assume FIFO, though seems to… May 11, 2026 at 4:41 pm

Related Questions

I have 3 tables (and corresponding entities in the entity model) Game: Id -
For fun, I'm trying to write one of my son's favorite board games as
I'm building a game server in Python and I just wanted to get some
I'm in the process of writing a Java 2D game. I'm using the built-in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.