Hacker News new | ask | show | jobs
by xashor 2231 days ago
Side note: The vel+pos example is a common one in ECS. It also often follow that you should put them in one type in the real world. However, nowadays thanks to SIMD instructions, it is probably faster to have them separate, as you don't have to unpack/align the various fields:

  // p={(x0,y0),(x1,y1),...} and v={(vx0,vy0),(vx1,vy1),...}
  for(int j=0;j<2*SIZE;j++)p[j]+=v[j];
vs.

  // pv={(x0,y0,vx0,vy0),(x1,y1,vx1,vy1),...}
  for(int j=0;j<4*SIZE;j+=4)
    pv[i+0]+=pv[i+2],pv[i+1]+=pv[i+3];