title: ECS - Handling components and specifically, a collision component
body: <p>I'm working on a game in c++ and am implementing an ECS system.</p>
  
  <ol>
  <li><p>I have a class: EntityFactory that is used to create and store an entity in a vector. An entity consists of a map of components. When a system is doing logic, should I just iterate over each entity, and then each of its components, or should I store vectors that contain references to each component created?</p></li>
  <li><p>I have a component called "CollisionComponent". I'm a little confused as how to perform collision updates with the collision system. As pseudo code I was thinking this:</p></li>
  </ol>
  
  <p>I'm sorry if I formatted this wrong:</p>
  
  <pre><code>foreach(entity)
  
     rect collide = getComponent&lt;CollisionComponent&gt;().bounds
  
     for(loop through every other entity with collision component)
  
         if(rect.intersects(otherEntity)
            //do collide logic
  </code></pre>
  
  <p>I feel like this is an inefficient way to accomplish this task.</p>
  
  <p>Thanks for the help!</p>