예제 #1
0
파일: EntityStore.cs 프로젝트: dn9090/Checs
        public void MoveEntityBatchInChunkToArchetype(EntityBatchInChunk entityBatchInChunk, Archetype *archetype)
        {
            var count = entityBatchInChunk.count;

            while (count > 0)
            {
                Chunk *chunk = archetype->chunkArray->GetChunkWithEmptySlots(count);

                var allocatedCount = 1;
                // ChunkUtility.AllocateEntities(chunk, ...) is overkill here.

                count -= allocatedCount;
            }



            /*
             * 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);
             */
        }
예제 #2
0
파일: EntityStore.cs 프로젝트: dn9090/Checs
        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;
        }