public void MoveEntityToArchetype(Entity entity, Archetype *archetype) { var entityInChunk = this.entitiesInChunk[entity.index]; var chunkIndex = 0; Chunk *chunk = archetype->chunkArray->GetChunkWithEmptySlots(ref chunkIndex); int indexInChunk = chunk->count; // TODO: This is bad. Remove the legacy stuff and reimplement this to work on batches. Span <Entity> allocated = ChunkUtility.AllocateEntities_LEGACY(chunk, 1); allocated[0] = entity; ChunkUtility.CopyComponentData(entityInChunk.chunk, chunk, entityInChunk.index, indexInChunk); ChunkUtility.PatchEntityData(entityInChunk.chunk, entityInChunk.index, 1); this.entitiesInChunk[entity.index] = new EntityInChunk(chunk, indexInChunk, entityInChunk.version); }
public void DestroyEntityBatchInChunk(EntityBatchInChunk entityBatchInChunk) { ChunkUtility.PatchEntityData(entityBatchInChunk.chunk, entityBatchInChunk.index, entityBatchInChunk.count); // TODO: This thing needs to be more efficent. var movedEntities = ChunkUtility.GetEntities(entityBatchInChunk.chunk); if (entityBatchInChunk.index < movedEntities.Length) // Copied from end? { movedEntities = movedEntities.Slice(entityBatchInChunk.index, Math.Min(movedEntities.Length, entityBatchInChunk.count)); for (int i = 0; i < movedEntities.Length; ++i) { var entityIndex = movedEntities[i].index; this.entitiesInChunk[entityIndex].chunk = entityBatchInChunk.chunk; this.entitiesInChunk[entityIndex].index = entityBatchInChunk.index + i; } } // TODO: Free chunks if chunk->count == 0 after patching entities ++this.version; }