Exemple #1
0
///////////////////////// MeshStorage::add //////////////////////////////////
void MeshComponentStorage::add(EntityId entity, Bound3 const &bound, Mesh const *mesh, Material const *material, int flags)
{
  size_t index = 0;

  if (flags & MeshComponent::Static)
  {
    index = insert(entity);

    if (index > m_staticpartition)
    {
      for_each(m_data, [=](auto &v) { swap(v[index], v[m_staticpartition]); });

      swap(m_index[data<0>(index).index()], m_index[entity.index()]);

      index = m_staticpartition;
    }

    m_staticpartition += 1;
  }
  else
  {
    index = append(entity);
  }

  set_entity(index, entity);
  set_flags(index, flags);
  set_bound(index, bound);
  set_mesh(index, mesh);
  set_material(index, material);

  if (flags & MeshComponent::Static)
  {
    m_tree.insert(MeshIndex{ index, this });
  }
}
Exemple #2
0
///////////////////////// MeshStorage::remove ///////////////////////////////
void MeshComponentStorage::remove(EntityId entity)
{
  auto index = m_index[entity.index()];

  if (index < m_staticpartition)
  {
    m_tree.remove(MeshIndex{ index, this });

    for_each(m_data, [=](auto &v) { v[index] = {}; });

    m_freeslots.push_back(index);
  }
  else
  {
    for_each(m_data, [=](auto &v) { swap(v[index], v[v.size()-1]); });

    for_each(m_data, [](auto &v) { v.resize(v.size()-1); });

    m_index[data<0>(index).index()] = index;
  }

  m_index[entity.index()] = 0;
}