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

  • SEARCH
  • Home
  • 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 8758821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:38:50+00:00 2026-06-13T14:38:50+00:00

In my C# game engine, I used to handle ordered drawing by adding/removing action

  • 0

In my C# game engine, I used to handle ordered drawing by adding/removing action to a manager object, which sorted the actions by priority, then executed them.

Here is a very simplified example:

class DrawManager
{
    public List<Tuple<Action, int>> DrawActions = new List<Tuple<Action, int>>();
    void Draw() { foreach (var tuple in DrawActions) tuple.Item1(); }
}

class Example
{
    DrawManager manager;

    Example()
    {
        manager.DrawActions.Add(new Tuple<Action, int>(DrawBackground, 0));
        manager.DrawActions.Add(new Tuple<Action, int>(DrawForeground, 100));
    }
    ~Example()
    {
        manager.DrawActions.Remove(manager.DrawActions.Find(x => x.Item1 == DrawBackground));
        manager.DrawActions.Remove(manager.DrawActions.Find(x => x.Item1 == DrawForeground));
    }

    void DrawBackground() { /* draw something */ }
    void DrawForeground() { /* draw something */ }
}

By adding some helper methods, the code becomes very elegant and easy to use in my engine.

I’ve moved to C++ recently, and I can’t find any easy way to achieve the same result.

I tried using std::function, but in order to remove the method on object destruction, I had to store the draw method in a pointer owned by the caller, then wrap it into a lambda and pass it in. Very inelegant and time consuming.

Is there any way to get code similar to the one shown in the C# example?

  • 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. Editorial Team
    Editorial Team
    2026-06-13T14:38:53+00:00Added an answer on June 13, 2026 at 2:38 pm

    You can use std::function in place of Action:

    typedef std::function<void()> Action;
    std::vector<std::pair<Action, int> > DrawActions;
    void Draw() {
        for_each(DrawActions.begin(), DrawActions.end(), [](std::pair<Action, int>& a) {
           a.first(); 
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a game engine, in which a list of list of
I almost finished writing the first draft of my game's logic engine which is
I was developing an HTML5 game engine. I used Git as the SV and
I'm utilizing a game engine called AndEngine (which I'm completely new to) in my
I have an engine library that is used by a game executable. That engine
I started a web based game engine a while back, but used primarily jQuery
I'm developing a method for encrypting game data files which will be used in
I am making a game engine using HTML5 canvas, and I have decided to
I'm programming a game engine right now. The hardest part for me has been
I have a game engine that uses OpenGL for display. I coded a small

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.