Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        internal void CreateEntityInternal_LEGACY(Archetype *archetype, Span <Entity> entities)
        {
            this.entityStore->EnsureCapacity(entities.Length);
            this.entityStore->ReserveEntityBatch(entities);

            var allocatedEntityCount = 0;
            var chunkIndexInArray    = 0;

            while (allocatedEntityCount < entities.Length)
            {
                Chunk *chunk      = archetype->chunkArray->GetChunkWithEmptySlots(ref chunkIndexInArray);
                int    chunkCount = chunk->count;

                Span <Entity> entitiesInChunk = ChunkUtility.AllocateEntities_LEGACY(chunk, entities.Length - allocatedEntityCount);

                for (int i = 0; i < entitiesInChunk.Length; ++i)
                {
                    Entity entity = entities[allocatedEntityCount++];
                    entitiesInChunk[i] = entity;
                    this.entityStore->entitiesInChunk[entity.index] = new EntityInChunk(chunk, chunkCount + i, entity.version);
                }
            }
        }