public bool Remove(Entity entity) { int dataIndex = IndexOf(entity); if (dataIndex == -1) { return(false); } // Mark the mapping as invalid so the entity can no longer be // queried directly. // _mapping[EntityUtil.DecomposeIndex(entity)] = int.MaxValue; // Update mapping for the last component which is going to be moved into // the removed location. // int newMappingIndex = EntityUtil.DecomposeIndex(_entities[_entities.Count - 1]); _mapping[newMappingIndex] = dataIndex; // Move the component and entity information into the removed index. // _entities[dataIndex] = _entities[_entities.Count - 1]; _data[dataIndex] = _data[_data.Count - 1]; // Pop the final component. // _entities.RemoveAt(_entities.Count - 1); _data.RemoveAt(_data.Count - 1); return(true); }
public int IndexOf(Entity entity) { int mappingIndex = EntityUtil.DecomposeIndex(entity); if (mappingIndex < 0 || mappingIndex >= _mapping.Count) { return(-1); } int dataIndex = _mapping[mappingIndex]; if (dataIndex >= _entities.Count) { return(-1); } return(_entities[dataIndex] == entity ? dataIndex : -1); }