   Frame Processing Advice
  I'm looking for some advice on how to I should be handling my frame processing. Specifically, I'm using HAAF's 2D Game Engine should that information be of use. Basically, right now frames are setup to be handled in a 2-step fashion:1. Process All Data (decide what sprites go where, what menus to show, etc)2. Render Data (call all render functions in order)Those to steps are handled in runFrame() and renderFrame() functions. However, since I have separate functions for each portion of the game, this means I would have 2 versions of each function. E.g., runGameMenu(), renderGameMenu(), runEtc(), renderEtc(), etc....This is extremely annoying. So instead I have in the past tried using a single function, which handles all processing and rendering as it goes. For example, I call BeginScene() right at the beginning of runFrame(), then as I process say that sprite over there, I render it immediately, then move on. However, this results in the two parts becoming intertwined beyond any separable recognition. For my current game, I have opted on the 1 function per game-state method, but I have maintained 2 distinct portions of each function, example below:void runMainMenu(bool render){    if (render)    {  renderMouseCoords();  gui->Render();  mouseSpr->Render();  return;    }    .....}Then during the renderFrame() function, I have a switch with each function where I call them with their render booleans set to true, and it works ok.My question: What is the best way to handle frame processing? (The most organized, hierarchical, object-oriented, way to handle this)   
  A common solution to this is to build a render queue. Instead of having your Run functions directly do rendering work, they add requests for that work into a queue. Once all your Run functions have finished, you execute a single Render function that pulls items out of that queue and draws them.This is often implemented using the Command pattern.   ;  That seems like a much more manageable solution. So I should have a class that makes a sort of virtual 'render stack' which contains a series of commands to be executed? And each render command should derive from a global 'command' class? Then I guess I could pass each pointer to an object along with the params to some vague function like:class RENDER_STACK{public:...void pushRenderFunc(RENDER_OBJECT *object, int numParams, ...); // The '...' here actually refers to the C++ variable length parameters...};And force each RENDER_OBJECT to override a default Render() function? Something along those lines?   ;  Close, but not quite [smile]Your solution should look something like this:class RenderCommand{public:   virtual ~RenderCommand() {}public:   void Render() const = 0;};class RenderFooCommand : public RenderCommand{public:   RenderFooCommand(int whichfoo) : WhichFoo(whichfoo)   { }public:   void Render() const   { DrawAFoo(TheFooContainer.GetFoo(WhichFoo));   }private:   int WhichFoo;};// Somewhere elseTheRenderQueue.Add(new RenderFooCommand(42));The "TheRenderQueue" can be a simple container (e.g. std::list) of smart pointers, each pointing to a particular RenderCommand instance. No need to have a special class for that; a typedef will work just fine.Note that the base RenderCommand is abstract (as it has a pure virtual function) and therefore you can't instantiate one directly. Any command must be instantiated via a derived class, which makes things a bit safer.Also, note that there is no need for variadic parameters; when you need to initialize a command, the class constructor already takes the correct set of parameters. The render queue need know nothing about the internals of each command - it just dispatches the Render() call and removes the item from the queue.Hope that clarifies things a bit [smile]   ;  Much clearer thank you. I followed the Wikipedia link earlier and revised my code to something similar, but not quite perfect. That makes it much better, thank you!   