Esempio n. 1
0
        public void CreateChunks(Archetype *archetype, ArchetypeChunk *chunks, int chunksCount, int entityCount)
        {
            fixed(EntityComponentStore *entityComponentStore = &this)
            {
                int *sharedComponentValues = stackalloc int[archetype->NumSharedComponents];

                int chunkIndex = 0;

                while (entityCount != 0)
                {
                    #if ENABLE_UNITY_COLLECTIONS_CHECKS
                    if (chunkIndex >= chunksCount)
                    {
                        throw new System.ArgumentException($"CreateChunks chunks array is not large enough to hold the array of chunks {chunksCount}.");
                    }
                    #endif

                    var chunk         = GetCleanChunk(archetype, sharedComponentValues);
                    var allocateCount = math.min(entityCount, chunk->UnusedCount);

                    ChunkDataUtility.Allocate(chunk, allocateCount);

                    chunks[chunkIndex] = new ArchetypeChunk(chunk, entityComponentStore);

                    entityCount -= allocateCount;
                    chunkIndex++;
                }
                IncrementComponentTypeOrderVersion(archetype);
            }
        }
Esempio n. 2
0
        // ----------------------------------------------------------------------------------------------------------
        // PUBLIC
        // ----------------------------------------------------------------------------------------------------------

        public void CreateEntities(Archetype *archetype, Entity *entities, int count)
        {
            var archetypeChunkFilter = new ArchetypeChunkFilter();

            archetypeChunkFilter.Archetype = archetype;

            while (count != 0)
            {
                var chunk         = GetChunkWithEmptySlots(ref archetypeChunkFilter);
                var allocateCount = math.min(count, chunk->UnusedCount);

                ChunkDataUtility.Allocate(chunk, entities, allocateCount);

                entities += allocateCount;
                count    -= allocateCount;
            }
        }