public unsafe void Destroy(ref Entity entity) { Assert.IsTrue(0 <= entity.Index && entity.Index < _capacity); var data = _dataManager.Get(entity.Index); if (data->ArcheType != null) { _componentBlockManager.Free(data->ArcheType, data->Chunk, data->IndexInChunk); } int idx = entity.Index; var buf = (Entity *)NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(_entities); buf[idx].Index = -1; entity.Index = -1; _occupation.Clear(idx); --_count; _lastUnused = idx; }
internal void Free(Chunk *chunk, int indexInChunk, Chunk **newChunk, int *newIndexInChunk) { // @bug #if false Assert.IsTrue(_usedCountInTotal > 0); int lastIndexInTotal = --_usedCountInTotal; _usedCountInChunk--; if (_usedCountInChunk < 0) { _usedCountInChunk = _countInChunk; } var lastChunk = _data.GetChunk(lastIndexInTotal / _countInChunk); var lastIndexInChunk = lastIndexInTotal % _countInChunk; int lastEntityIndex = GetEntityIndex(lastChunk, lastIndexInChunk); var entityData = _entityDataManager.Get(lastEntityIndex); CopyInternal(chunk, indexInChunk, entityData->Chunk, entityData->IndexInChunk); entityData->Chunk = chunk; entityData->IndexInChunk = indexInChunk; #endif }