title: Entity Systems in C++
body: <p>In game development there is a notion of Entity System which is aiming to simplify the game loop by gaining a flexible architecture. For details see the links below:</p>
  
  <p><a href="http://www.richardlord.net/blog/what-is-an-entity-framework">http://www.richardlord.net/blog/what-is-an-entity-framework</a>
  <a href="http://shaun.boyblack.co.za/blog/2012/08/04/games-and-entity-systems/">http://shaun.boyblack.co.za/blog/2012/08/04/games-and-entity-systems/</a></p>
  
  <p>Now I wonder how it is possible to realize automatic <code>Node</code> creation when a <code>Component</code> is added to an <code>Entity</code> in C++? Please tell me the principle of identifying what <code>Nodes</code> can be spawned from a specific <code>Entity</code>, i.e. you should have list of <code>Component</code> and classes that aggregate components. And you should understand what classes can be created with the list of data.</p>
  
  <p>For example I have <code>Components</code>:</p>
  
  <pre><code>class PositionComponent
  {
    int m_x;
    int m_y;
    int m_rotation;
  };
  
  class VelocityComponent
  {
    int m_vX;
    int m_vY;
    int m_vAngular;
  };
  
  class RenderableComponent
  {
    Sprite m_view;
  };
  </code></pre>
  
  <p>And nodes:</p>
  
  <pre><code>class MoveNode
  {
    PositionComponent m_position;
    VelocityComponent m_velocity;
  };
  
  class RenderNode
  {
    RenderableComponent m_rend;
    PositionComponent m_position;
  };
  </code></pre>
  
  <p>Now if I create an <code>Entity</code> like this:</p>
  
  <pre><code>Entity * e = new Entity;
  e.add(new PositionComponent);
  e.add(new VelocityComponent);
  </code></pre>
  
  <p>Then I want to have a code that creates a <code>MoveNode</code> automatically, and if I add also this:</p>
  
  <pre><code>e.add(new RenderableComponent);
  </code></pre>
  
  <p>Then I want to know that also <code>RenderNode</code> is created. Consequently, when I delete it:</p>
  
  <p>e.remove(new RenderableComponent);</p>
  
  <p>the <code>RenderNode</code> should be deleted. And this process, of course, should not be bind to the specific <code>Nodes</code> and <code>Components</code> I have defined.</p>
  
  <p>How is it possible to realize this in C++?</p>