コード例 #1
0
        public void AddToChunkList(Chunk *chunk, SharedComponentValues sharedComponentIndices, uint changeVersion, ref EntityComponentStore.ChunkListChanges changes)
        {
            chunk->ListIndex = Chunks.Count;
            if (Chunks.Count == Chunks.Capacity)
            {
                var newCapacity = (Chunks.Capacity == 0) ? 1 : (Chunks.Capacity * 2);

                // The shared component indices we are inserting belong to the same archetype so they need to be adjusted after reallocation
                if (Chunks.InsideAllocation((ulong)sharedComponentIndices.firstIndex))
                {
                    int chunkIndex = (int)(sharedComponentIndices.firstIndex - Chunks.GetSharedComponentValueArrayForType(0));
                    Chunks.Grow(newCapacity);
                    sharedComponentIndices = Chunks.GetSharedComponentValues(chunkIndex);
                }
                else
                {
                    Chunks.Grow(newCapacity);
                }
            }

            Chunks.Add(chunk, sharedComponentIndices, changeVersion);

            fixed(Archetype *archetype = &this)
            {
                changes.TrackArchetype(archetype);
            }
        }