title: A clean way to render things
body: <p>I don't really have any problems with the way I'm rendering now, but I don't feel like it's a very good way of handling rendering. I'm using SDL.</p>
  
  <p>It boils down to this I have some abstract class</p>
  
  <pre><code>class Renderable
  </code></pre>
  
  <p>With two functions.</p>
  
  <pre><code>virtual void update() = 0;
  virtual void doRender(SDL_Surface* surface) = 0;
  </code></pre>
  
  <hr>
  
  <p>I have another class</p>
  
  <pre><code>class RenderManager
  </code></pre>
  
  <p>With 1 <code>std::vector</code></p>
  
  <pre><code>std::vector&lt;Renderable*&gt; _world;
  </code></pre>
  
  <p>and 2 <code>std::queue</code></p>
  
  <pre><code>std::queue&lt;Renderable*&gt; _addQueue;
  std::queue&lt;Renderable*&gt; _delQueue;
  </code></pre>
  
  <p>The two queues hold the renderables that need to be added in the next tick and the ones that need to be removed. Doing everything in one shot gave me problems and now that I think about it, it makes sense (at least the way I did it).</p>
  
  <p>Renderables can add and remove themselves from the RenderManager statically.</p>
  
  <p>Here's more or less the function handling everything.</p>
  
  <pre><code>void renderAll() {
      std::vector&lt;Renderable*&gt;::iterator begin, end;
      begin = _world.begin();
      end = _world.end();
  
      for (;begin != end; ++begin) {
          (*begin)-&gt;update();
          (*begin)-&gt;doRender(_mainWindow); // _mainWindow is the screen of course
      }
  
      begin = world.begin();
  
      if (_delQueue.size() &gt; 0) {
          for (unsigned int i = 0; i &lt; _delQueue.size(); i++) {
              std::vector&lt;Renderable*&gt;::iterator del;
              del = std::find(begin, end, _delQueue.front());
  
              if (del != end) {
                  delete *del;
                  _world.erase(del);
              }
              _delQueue.pop();
          }
      }
  
      if (_addQueue.size() &gt; 0) {
          for (unsigned int i = 0; i &lt; _addQueue.size(); i++) {
              Renderable* front = _addQueue.front();
  
              // _placement is a property of Renderable calculated by RenderManager
              // where they can choose the level they want to be rendered on.
              _world.insert(begin + front-&gt;_placement, front);
              _addQueue.pop();
          }
      }
  }
  </code></pre>
  
  <p>I'm kinda sorta newish to C++, but I think I know my way around it on an average scale at least. I'm even newer to SDL, but it seems pretty simple and easy to learn. I'm concerned because I have 3 big loops together. I tried one shotting it but I was having problems with _world resizing during the loop causing massive amounts of destruction. But I'm not claiming I did it right! :)</p>
  
  <p>I was thinking maybe something involving threads?</p>
  
  <p>EDIT:</p>
  
  <p>Ahh, sorry for the ambiguity. By "cleaner" I mean more efficient. Also there is no "problem" with my approach, I just feel there's a more efficient way.</p>