public void AddEntity(EcsEntity entity) { if (_length >= _entities.Length) { Array.Resize(ref _entities, 2 * _entities.Length); } entity.ArchetypeIndex = _length; _entities[_length++] = entity; _count++; }
/// <summary> /// Remove holes from the archetype /// </summary> private void RemoveHoles() { if (_freeIndex >= _length) { return; } int current = _freeIndex + 1; while (current < _length) { while (current < _length && _entities[current] == null) { current++; } if (current >= _length) { continue; } EcsEntity entity = _entities[current]; entity.ArchetypeIndex = _freeIndex; _entities[_freeIndex] = entity; _entities[current] = null; foreach (byte index in Indices) { _compPools[index].Replace(_freeIndex, current); } current++; _freeIndex++; } _length = _freeIndex; _freeIndex = int.MaxValue; }
public void RemoveEntity(EcsEntity entity) { _entities[entity.ArchetypeIndex] = null; foreach (byte index in Indices) { _compPools[index].Remove(entity.ArchetypeIndex); } _freeIndex = Math.Min(_freeIndex, entity.ArchetypeIndex); _count--; if (_freeIndex == _length - 1) { _length = _freeIndex; _freeIndex = int.MaxValue; } else if (_length >= _count + _count) { RemoveHoles(); } }