コード例 #1
0
        private void MoveToNextMatchingChunk()
        {
            var m = m_CurrentMatchingArchetypeIndex;
            var c = m_CurrentChunk;
            var e = m_MatchingArchetypeList.p[m]->Archetype->Chunks.p + m_MatchingArchetypeList.p[m]->Archetype->Chunks.Count;

            do
            {
                c = c + 1;
                while (c == e)
                {
                    m_CurrentArchetypeEntityIndex += m_CurrentChunkEntityIndex;
                    m_CurrentChunkEntityIndex      = 0;
                    m = m - 1;
                    if (m < 0)
                    {
                        m_CurrentMatchingArchetypeIndex = m;
                        m_CurrentChunk = null;
                        return;
                    }

                    c = m_MatchingArchetypeList.p[m]->Archetype->Chunks.p;
                    e = m_MatchingArchetypeList.p[m]->Archetype->Chunks.p + m_MatchingArchetypeList.p[m]->Archetype->Chunks.Count;
                }
            } while (!((*c)->MatchesFilter(m_MatchingArchetypeList.p[m], ref m_Filter) && (*c)->Capacity > 0));

            m_CurrentMatchingArchetypeIndex = m;
            m_CurrentChunk = c;
        }
コード例 #2
0
        public void MoveToEntityIndex(int index)
        {
            if (!m_Filter.RequiresMatchesFilter)
            {
                if (index < m_CurrentArchetypeEntityIndex)
                {
                    m_CurrentMatchingArchetypeIndex = m_FirstMatchingArchetypeIndex;
                    m_CurrentArchetypeEntityIndex   = 0;
                    m_CurrentChunk = m_CurrentMatchingArchetype->Archetype->Chunks.p;
                    // m_CurrentChunk might point to an invalid chunk if the first matching archetype has no chunks
                    // the while loop below will move to the first archetype that has any entities
                    m_CurrentChunkEntityIndex = 0;
                }

                while (index >= m_CurrentArchetypeEntityIndex + m_CurrentMatchingArchetype->Archetype->EntityCount)
                {
                    m_CurrentArchetypeEntityIndex  += m_CurrentMatchingArchetype->Archetype->EntityCount;
                    m_CurrentMatchingArchetypeIndex = m_CurrentMatchingArchetypeIndexNext;
                    m_CurrentChunk            = m_CurrentMatchingArchetype->Archetype->Chunks.p;
                    m_CurrentChunkEntityIndex = 0;
                }

                index -= m_CurrentArchetypeEntityIndex;
                if (index < m_CurrentChunkEntityIndex)
                {
                    m_CurrentChunk            = m_CurrentMatchingArchetype->Archetype->Chunks.p;
                    m_CurrentChunkEntityIndex = 0;
                }

                while (index >= m_CurrentChunkEntityIndex + (*m_CurrentChunk)->Count)
                {
                    m_CurrentChunkEntityIndex += (*m_CurrentChunk)->Count;
                    m_CurrentChunk             = m_CurrentChunk + 1;
                }
            }
            else
            {
                if (index < m_CurrentArchetypeEntityIndex + m_CurrentChunkEntityIndex)
                {
                    if (index < m_CurrentArchetypeEntityIndex)
                    {
                        m_CurrentMatchingArchetypeIndex = m_FirstMatchingArchetypeIndex;
                        m_CurrentArchetypeEntityIndex   = 0;
                    }

                    m_CurrentChunk = m_CurrentMatchingArchetype->Archetype->Chunks.p - 1;
                    // m_CurrentChunk now points to an invalid chunk but since the chunk list is circular
                    // it effectively points to the chunk before the first
                    // MoveToNextMatchingChunk will move it to a valid chunk if any exists
                    m_CurrentChunkEntityIndex = 0;
                    MoveToNextMatchingChunk();
                }

                while (index >= m_CurrentArchetypeEntityIndex + m_CurrentChunkEntityIndex + (*m_CurrentChunk)->Count)
                {
                    m_CurrentChunkEntityIndex += (*m_CurrentChunk)->Count;
                    MoveToNextMatchingChunk();
                }
            }
        }
コード例 #3
0
ファイル: ChunkIterator.cs プロジェクト: dn9090/Checs
 public ChunkIterator(int capacity)
 {
     this.capacity = capacity;
     this.count    = 0;
     this.index    = 0;
     this.chunks   = MemoryUtility.MallocPtrArray <Chunk>(this.capacity);
 }
コード例 #4
0
 public void Dispose()
 {
     UnsafeUtility.Free(p, Allocator.Persistent);
     p        = null;
     Capacity = 0;
     Count    = 0;
 }
コード例 #5
0
ファイル: ArchetypeChunkArray.cs プロジェクト: dn9090/Checs
 public void EnsureCapacity()
 {
     if (this.count == this.capacity)
     {
         this.capacity = this.capacity * 2;
         this.chunks   = MemoryUtility.ReallocPtrArray(this.chunks, this.capacity);
     }
 }
 public ArchetypeChunkData(int componentCount, int sharedComponentCount)
 {
     p                    = null;
     Capacity             = 0;
     Count                = 0;
     SharedComponentCount = sharedComponentCount;
     ComponentCount       = componentCount;
 }
コード例 #7
0
ファイル: ChunkPool.cs プロジェクト: dn9090/Checs
 private static void EnsureCapacity()
 {
     if (count == capacity)
     {
         capacity = capacity * 2;
         chunks   = MemoryUtility.ReallocPtrArray(chunks, capacity);
     }
 }
コード例 #8
0
ファイル: ChunkPool.cs プロジェクト: dn9090/Checs
 static ChunkPool()
 {
     nextSequenceNumber = 0;
     rentedCount        = 0;
     count    = 0;
     capacity = 16;
     chunks   = MemoryUtility.MallocPtrArray <Chunk>(capacity);
 }
コード例 #9
0
 public ArchetypeChunkData(int componentTypeCount, int sharedComponentCount)
 {
     data                 = null;
     p                    = null;
     Capacity             = 0;
     Count                = 0;
     SharedComponentCount = sharedComponentCount;
     EntityCountIndex     = componentTypeCount + sharedComponentCount;
     Channels             = componentTypeCount + sharedComponentCount + 1; // +1 for entity count per-chunk
 }
コード例 #10
0
ファイル: ChunkIterator.cs プロジェクト: dn9090/Checs
        private void EnsureCapacity(int count)
        {
            int requiredCapacity = this.count + count;

            if (requiredCapacity > this.capacity)
            {
                this.capacity = MemoryUtility.RoundToPowerOfTwo(requiredCapacity);
                this.chunks   = MemoryUtility.ReallocPtrArray <Chunk>(this.chunks, this.capacity);
            }
        }
コード例 #11
0
 public ComponentChunkIterator(MatchingArchetypes *match, uint globalSystemVersion,
                               ref ComponentGroupFilter filter)
 {
     m_FirstMatchingArchetype   = match;
     m_CurrentMatchingArchetype = match;
     IndexInComponentGroup      = -1;
     m_CurrentChunk             = null;
     m_CurrentArchetypeIndex    = m_CurrentArchetypeEntityIndex = int.MaxValue; // This will trigger UpdateCacheResolvedIndex to update the cache on first access
     m_CurrentChunkIndex        = m_CurrentChunkEntityIndex = 0;
     m_GlobalSystemVersion      = globalSystemVersion;
     m_Filter = filter;
 }
コード例 #12
0
ファイル: ChunkUtility.cs プロジェクト: dn9090/Checs
        public static int WriteEntitiesToBuffer(Chunk **chunks, int count, Span <Entity> buffer)
        {
            int position = 0;

            for (int i = 0; i < count; ++i)
            {
                var entities = GetEntities(chunks[i]);
                entities.CopyTo(buffer.Slice(position));
                position += entities.Length;
            }

            return(position);
        }
コード例 #13
0
        public unsafe void Execute(int index)
        {
            EntityArchetype archetype  = this.Archetypes[index];
            int             chunkCount = archetype.Archetype.ChunkCount;
            Chunk *         begin      = (Chunk *)archetype.Archetype.ChunkList.Begin;
            int             num2       = this.Offsets[index];
            Chunk **        unsafePtr  = (Chunk **)this.Chunks.GetUnsafePtr <ArchetypeChunk>();

            for (int i = 0; i < chunkCount; i++)
            {
                *((IntPtr *)(unsafePtr + (num2 + i))) = begin;
                begin = (Chunk *)begin->ChunkListNode.Next;
            }
        }
コード例 #14
0
 public ComponentChunkIterator(UnsafeMatchingArchetypePtrList match, uint globalSystemVersion,
                               ref EntityQueryFilter filter)
 {
     m_MatchingArchetypeList         = match;
     m_CurrentMatchingArchetypeIndex = match.Length - 1;
     IndexInEntityQuery                = -1;
     m_CurrentChunk                    = null;
     m_CurrentArchetypeIndex           =
         m_CurrentArchetypeEntityIndex =
             int.MaxValue; // This will trigger UpdateCacheResolvedIndex to update the cache on first access
     m_CurrentChunkIndex   = m_CurrentChunkEntityIndex = 0;
     m_GlobalSystemVersion = globalSystemVersion;
     m_Filter = filter;
 }
        public void Grow(int nextCapacity)
        {
            Assert.IsTrue(nextCapacity > Capacity);

            ulong nextChunkPtrSize              = (ulong)(sizeof(Chunk *) * nextCapacity);
            ulong nextChangeVersionSize         = (ulong)(sizeof(uint) * ComponentCount * nextCapacity);
            ulong nextEntityCountSize           = (ulong)(sizeof(int) * nextCapacity);
            ulong nextSharedComponentValuesSize = (ulong)(sizeof(int) * SharedComponentCount * nextCapacity);
            ulong nextBufferSize = nextChunkPtrSize + nextChangeVersionSize + nextEntityCountSize + nextSharedComponentValuesSize;
            ulong nextBufferPtr  = (ulong)Memory.Unmanaged.Allocate((long)nextBufferSize, 16, Allocator.Persistent);

            Chunk **nextChunkData = (Chunk **)nextBufferPtr;

            nextBufferPtr += nextChunkPtrSize;
            uint *nextChangeVersions = (uint *)nextBufferPtr;

            nextBufferPtr += nextChangeVersionSize;
            int *nextEntityCount = (int *)nextBufferPtr;

            nextBufferPtr += nextEntityCountSize;
            int *nextSharedComponentValues = (int *)nextBufferPtr;

            nextBufferPtr += nextSharedComponentValuesSize;

            int     prevCount                 = Count;
            int     prevCapacity              = Capacity;
            Chunk **prevChunkData             = p;
            uint *  prevChangeVersions        = ChangeVersions;
            int *   prevEntityCount           = EntityCount;
            int *   prevSharedComponentValues = SharedComponentValues;

            UnsafeUtility.MemCpy(nextChunkData, prevChunkData, (sizeof(Chunk *) * prevCount));

            for (int i = 0; i < ComponentCount; i++)
            {
                UnsafeUtility.MemCpy(nextChangeVersions + (i * nextCapacity), prevChangeVersions + (i * prevCapacity), sizeof(uint) * Count);
            }

            for (int i = 0; i < SharedComponentCount; i++)
            {
                UnsafeUtility.MemCpy(nextSharedComponentValues + (i * nextCapacity), prevSharedComponentValues + (i * prevCapacity), sizeof(uint) * Count);
            }

            UnsafeUtility.MemCpy(nextEntityCount, prevEntityCount, sizeof(int) * Count);

            Memory.Unmanaged.Free(p, Allocator.Persistent);

            p        = nextChunkData;
            Capacity = nextCapacity;
        }
コード例 #16
0
        internal int Allocate(Chunk **chunk, int entityIndex)
        {
            if (_usedCountInChunk < 0 || _usedCountInChunk >= _countInChunk)
            {
                _data.Allocate(_dataSize * _countInChunk, sizeof(ulong));
                _usedCountInChunk = 0;
                _countInTotal     = _data.Count * _countInChunk;
            }
            int r = _usedCountInChunk++;

            *chunk = _data.CurrentChunk;
            SetEntityIndex(*chunk, r, entityIndex);
            _usedCountInTotal++;
            return(r);
        }
コード例 #17
0
        public void Grow(int newCapacity)
        {
            Assert.IsTrue(newCapacity > Capacity);
            Chunk **newChunkData = (Chunk **)UnsafeUtility.Malloc(newCapacity * (Channels * sizeof(int) + sizeof(Chunk *)), 16, Allocator.Persistent);
            var     newData      = (int *)(newChunkData + newCapacity);

            UnsafeUtility.MemCpy(newChunkData, p, sizeof(Chunk *) * Count);

            for (int i = 0; i < Channels; ++i)
            {
                UnsafeUtility.MemCpy(newData + i * newCapacity, data + i * Capacity, sizeof(int) * Count);
            }

            UnsafeUtility.Free(p, Allocator.Persistent);
            data     = newData;
            p        = newChunkData;
            Capacity = newCapacity;
        }
コード例 #18
0
        internal void Free(Chunk *chunk, int indexInChunk, Chunk **newChunk, int *newIndexInChunk)
        {
            // @bug
#if false
            Assert.IsTrue(_usedCountInTotal > 0);
            int lastIndexInTotal = --_usedCountInTotal;
            _usedCountInChunk--;
            if (_usedCountInChunk < 0)
            {
                _usedCountInChunk = _countInChunk;
            }
            var lastChunk        = _data.GetChunk(lastIndexInTotal / _countInChunk);
            var lastIndexInChunk = lastIndexInTotal % _countInChunk;

            int lastEntityIndex = GetEntityIndex(lastChunk, lastIndexInChunk);
            var entityData      = _entityDataManager.Get(lastEntityIndex);

            CopyInternal(chunk, indexInChunk, entityData->Chunk, entityData->IndexInChunk);
            entityData->Chunk        = chunk;
            entityData->IndexInChunk = indexInChunk;
#endif
        }
コード例 #19
0
        public void MoveToChunkWithoutFiltering(int index)
        {
            if (index < m_CurrentArchetypeIndex)
            {
                m_CurrentMatchingArchetypeIndex = m_FirstMatchingArchetypeIndex;
                m_CurrentChunk          = m_CurrentMatchingArchetype->Archetype->Chunks.p;
                m_CurrentArchetypeIndex = m_CurrentArchetypeEntityIndex = 0;
                m_CurrentChunkIndex     = m_CurrentChunkEntityIndex = 0;
            }

            while (index >= m_CurrentArchetypeIndex + m_CurrentMatchingArchetype->Archetype->Chunks.Count)
            {
                m_CurrentArchetypeEntityIndex += m_CurrentMatchingArchetype->Archetype->EntityCount;
                m_CurrentArchetypeIndex       += m_CurrentMatchingArchetype->Archetype->Chunks.Count;

                m_CurrentMatchingArchetypeIndex = m_CurrentMatchingArchetypeIndexNext;
                m_CurrentChunk = m_CurrentMatchingArchetype->Archetype->Chunks.p;

                m_CurrentChunkIndex = m_CurrentChunkEntityIndex = 0;
            }

            index -= m_CurrentArchetypeIndex;
            if (index < m_CurrentChunkIndex)
            {
                m_CurrentChunk      = m_CurrentMatchingArchetype->Archetype->Chunks.p;
                m_CurrentChunkIndex = m_CurrentChunkEntityIndex = 0;
            }

            while (index >= m_CurrentChunkIndex + 1)
            {
                m_CurrentChunkEntityIndex += (*m_CurrentChunk)->Count;
                m_CurrentChunkIndex       += 1;

                m_CurrentChunk = m_CurrentChunk + 1;
            }
        }
コード例 #20
0
ファイル: ChunkIterator.cs プロジェクト: dn9090/Checs
 public void Add(Chunk **chunks, int count)
 {
     EnsureCapacity(count);
     Unsafe.CopyBlock((void *)&this.chunks[this.count], (void *)chunks, (uint)(sizeof(Chunk *) * count));
 }
コード例 #21
0
ファイル: 050-TestStructs.cs プロジェクト: Lozamded/IPG_RTA01
        public static unsafe int TestRegressionInvalidGetElementPtrStructLayoutInternal(int index, int limit, Chunk **currentChunk)
        {
            int rValue = 0;

            while (index >= limit + 1)
            {
                rValue += (*currentChunk)->Count;
                index  += 1;
            }

            return(rValue);
        }
コード例 #22
0
        internal int Allocate(ArcheType *archeType, Chunk **chunk, int entityIndex)
        {
            var block = GetOrCreateBlock(archeType);

            return(block.Allocate(chunk, entityIndex));
        }
コード例 #23
0
 public ParallelReader(Chunk **ptr, int length)
 {
     Ptr = ptr; Length = length;
 }
コード例 #24
0
 public unsafe UnsafeChunkPtrList(int initialCapacity, Allocator allocator, NativeArrayOptions options = NativeArrayOptions.UninitializedMemory)
 {
     Ptr = null; Length = 0; Capacity = 0; Allocator = Allocator.Invalid; this.ListData() = new UnsafePtrList(initialCapacity, allocator, options);
 }
コード例 #25
0
 public unsafe UnsafeChunkPtrList(Chunk **ptr, int length)
 {
     Ptr = null; Length = 0; Capacity = 0; Allocator = Allocator.Invalid; this.ListData() = new UnsafePtrList((void **)ptr, length);
 }