コード例 #1
0
 internal EntityArray(ComponentChunkIterator iterator, int length, AtomicSafetyHandle safety)
 {
     this.m_Length   = length;
     this.m_Iterator = iterator;
     this.m_Cache    = new ComponentChunkCache();
     this.m_Safety   = safety;
 }
コード例 #2
0
        public void UpdateCache(int index, out ComponentChunkCache cache, bool isWriting)
        {
            if (m_Filter.Type == FilterType.IndexList)
            {
                var remappedIndex = m_Filter.Indices.Indices[index];

                UpdateCacheResolvedIndex(remappedIndex, out cache, isWriting);

                // Find consecutive range of indices
                var maxCount = Math.Min(cache.CachedEndIndex - remappedIndex, m_Filter.Indices.Length - index);
                var i        = 1;
                while (i < maxCount)
                {
                    if (m_Filter.Indices.Indices[index + i] != remappedIndex + i)
                    {
                        break;
                    }

                    i++;
                }

                cache.CachedBeginIndex = index;
                cache.CachedEndIndex   = index + i;
                cache.CachedPtr        = (byte *)cache.CachedPtr + (remappedIndex - index) * cache.CachedSizeOf;
            }
            else
            {
                UpdateCacheResolvedIndex(index, out cache, isWriting);
            }
        }
コード例 #3
0
 internal ComponentArray(ComponentChunkIterator iterator, int length, ArchetypeManager typeMan)
 {
     m_Length           = length;
     m_Cache            = default(ComponentChunkCache);
     m_Iterator         = iterator;
     m_ArchetypeManager = typeMan;
 }
コード例 #4
0
 internal ComponentDataArray(ComponentChunkIterator iterator, int length, AtomicSafetyHandle safety)
 {
     this.m_Iterator = iterator;
     this.m_Cache    = new ComponentChunkCache();
     this.m_Length   = length;
     this.m_MinIndex = 0;
     this.m_MaxIndex = length - 1;
     this.m_Safety   = safety;
 }
コード例 #5
0
        internal unsafe EntityArray(ComponentChunkIterator iterator, int length)
#endif
        {
            m_Length   = length;
            m_Iterator = iterator;
            m_Cache    = default(ComponentChunkCache);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_Safety = safety;
#endif
        }
コード例 #6
0
        internal ComponentDataArray(ComponentChunkIterator iterator, int length)
#endif
        {
            m_Iterator = iterator;
            m_Cache    = default(ComponentChunkCache);

            m_Length = length;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_MinIndex = 0;
            m_MaxIndex = length - 1;
            m_Safety   = safety;
#endif
        }
コード例 #7
0
        internal unsafe SharedComponentDataArray(SharedComponentDataManager sharedComponentDataManager, int sharedComponentIndex, ComponentChunkIterator iterator, int length)
#endif
        {
            m_sharedComponentDataManager = sharedComponentDataManager;
            m_sharedComponentIndex       = sharedComponentIndex;
            m_Iterator = iterator;
            m_Cache    = default(ComponentChunkCache);

            Length = length;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_Safety = safety;
#endif
        }
コード例 #8
0
 internal BufferArray(ComponentChunkIterator iterator, int length, bool isReadOnly, AtomicSafetyHandle safety, AtomicSafetyHandle arrayInvalidationSafety)
 {
     this.m_Length     = length;
     this.m_IsReadOnly = isReadOnly;
     this.m_Iterator   = iterator;
     this.m_Cache      = new ComponentChunkCache();
     this.m_MinIndex   = 0;
     this.m_MaxIndex   = length - 1;
     this.m_Safety0    = safety;
     this.m_ArrayInvalidationSafety = arrayInvalidationSafety;
     this.m_SafetyReadOnlyCount     = isReadOnly ? 2 : 0;
     this.m_SafetyReadWriteCount    = isReadOnly ? 0 : 2;
 }
コード例 #9
0
        internal BufferArray(ComponentChunkIterator iterator, int length, bool isReadOnly)
#endif
        {
            m_Length     = length;
            m_IsReadOnly = isReadOnly;
            m_Iterator   = iterator;
            m_Cache      = default(ComponentChunkCache);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_MinIndex = 0;
            m_MaxIndex = length - 1;
            m_Safety   = safety;
#endif
        }
コード例 #10
0
        public unsafe void UpdateCacheToCurrentChunk(out ComponentChunkCache cache, bool isWriting, int indexInComponentGroup)
        {
            Archetype *archetype = this.m_CurrentMatchingArchetype.Archetype;
            int        index     = &this.m_CurrentMatchingArchetype.IndexInArchetype.FixedElementField[indexInComponentGroup];

            cache.CachedBeginIndex = this.m_CurrentChunkEntityIndex + this.m_CurrentArchetypeEntityIndex;
            cache.CachedEndIndex   = cache.CachedBeginIndex + this.m_CurrentChunk.Count;
            cache.CachedSizeOf     = archetype->SizeOfs[index];
            cache.CachedPtr        = (void *)((&this.m_CurrentChunk.Buffer.FixedElementField + archetype->Offsets[index]) - (cache.CachedBeginIndex * cache.CachedSizeOf));
            cache.IsWriting        = isWriting;
            if (isWriting)
            {
                this.m_CurrentChunk.ChangeVersion[index] = this.m_GlobalSystemVersion;
            }
        }
コード例 #11
0
        public void UpdateCacheToCurrentChunk(out ComponentChunkCache cache, bool isWriting)
        {
            var archetype            = m_CurrentMatchingArchetype->Archetype;
            var typeIndexInArchetype = m_CurrentMatchingArchetype->TypeIndexInArchetypeArray[IndexInComponentGroup];

            cache.CachedBeginIndex = 0;
            cache.CachedEndIndex   = m_CurrentChunk->Count;
            cache.CachedSizeOf     = archetype->SizeOfs[typeIndexInArchetype];
            cache.CachedPtr        = m_CurrentChunk->Buffer + archetype->Offsets[typeIndexInArchetype];

            if (isWriting)
            {
                m_CurrentChunk->ChangeVersion[typeIndexInArchetype] = m_GlobalSystemVersion;
            }
        }
コード例 #12
0
        public void GetCacheForType(int componentType, out ComponentChunkCache cache, out int typeIndexInArchetype)
        {
            var archetype = m_CurrentMatchingArchetype->Archetype;

            typeIndexInArchetype = ChunkDataUtility.GetIndexInTypeArray(archetype, componentType);
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (typeIndexInArchetype == -1)
            {
                throw new System.ArgumentException("componentType does not exist in the iterated archetype");
            }
#endif

            cache.CachedBeginIndex = m_CurrentChunkIndex + m_CurrentArchetypeIndex;
            cache.CachedEndIndex   = cache.CachedBeginIndex + m_CurrentChunk->Count;
            cache.CachedSizeOf     = archetype->SizeOfs[typeIndexInArchetype];
            cache.CachedPtr        = m_CurrentChunk->Buffer + archetype->Offsets[typeIndexInArchetype] - cache.CachedBeginIndex * cache.CachedSizeOf;
        }
コード例 #13
0
        internal BufferArray(ComponentChunkIterator iterator, int length, bool isReadOnly)
#endif
        {
            m_Length     = length;
            m_IsReadOnly = isReadOnly;
            m_Iterator   = iterator;
            m_Cache      = default(ComponentChunkCache);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_MinIndex = 0;
            m_MaxIndex = length - 1;
            m_Safety0  = safety;
            m_ArrayInvalidationSafety = arrayInvalidationSafety;
            m_SafetyReadOnlyCount     = isReadOnly ? 2 : 0;
            m_SafetyReadWriteCount    = isReadOnly ? 0 : 2;
#endif
        }
コード例 #14
0
        public void UpdateCacheToCurrentChunk(out ComponentChunkCache cache, bool isWriting, int indexInComponentGroup)
        {
            var archetype = m_CurrentMatchingArchetype->Archetype;

            int indexInArchetype = m_CurrentMatchingArchetype->IndexInArchetype[indexInComponentGroup];

            cache.CachedBeginIndex = m_CurrentChunkEntityIndex + m_CurrentArchetypeEntityIndex;
            cache.CachedEndIndex   = cache.CachedBeginIndex + m_CurrentChunk->Count;
            cache.CachedSizeOf     = archetype->SizeOfs[indexInArchetype];
            cache.CachedPtr        = m_CurrentChunk->Buffer + archetype->Offsets[indexInArchetype] -
                                     cache.CachedBeginIndex * cache.CachedSizeOf;

            cache.IsWriting = isWriting;
            if (isWriting)
            {
                m_CurrentChunk->ChangeVersion[indexInArchetype] = m_GlobalSystemVersion;
            }
        }
コード例 #15
0
 public void MoveToEntityIndexAndUpdateCache(int index, out ComponentChunkCache cache, bool isWriting)
 {
     Assert.IsTrue(-1 != IndexInComponentGroup);
     MoveToEntityIndex(index);
     UpdateCacheToCurrentChunk(out cache, isWriting, IndexInComponentGroup);
 }
コード例 #16
0
        public void UpdateCache(int index, out ComponentChunkCache cache)
        {
            Assert.IsTrue(-1 != IndexInComponentGroup);

            if (m_FilteredSharedComponents == null)
            {
                if (index < m_CurrentArchetypeIndex)
                {
                    m_CurrentMatchingArchetype = m_FirstMatchingArchetype;
                    m_CurrentArchetypeIndex    = 0;
                    m_CurrentChunk             = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin;
                    m_CurrentChunkIndex        = 0;
                }

                while (index >= m_CurrentArchetypeIndex + m_CurrentMatchingArchetype->Archetype->EntityCount)
                {
                    m_CurrentArchetypeIndex   += m_CurrentMatchingArchetype->Archetype->EntityCount;
                    m_CurrentMatchingArchetype = m_CurrentMatchingArchetype->Next;
                    m_CurrentChunk             = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin;
                    m_CurrentChunkIndex        = 0;
                }

                index -= m_CurrentArchetypeIndex;
                if (index < m_CurrentChunkIndex)
                {
                    m_CurrentChunk      = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin;
                    m_CurrentChunkIndex = 0;
                }

                while (index >= m_CurrentChunkIndex + m_CurrentChunk->Count)
                {
                    m_CurrentChunkIndex += m_CurrentChunk->Count;
                    m_CurrentChunk       = (Chunk *)m_CurrentChunk->ChunkListNode.Next;
                }
            }
            else
            {
                if (index < m_CurrentArchetypeIndex + m_CurrentChunkIndex)
                {
                    if (index < m_CurrentArchetypeIndex)
                    {
                        m_CurrentMatchingArchetype = m_FirstMatchingArchetype;
                        m_CurrentArchetypeIndex    = 0;
                    }

                    m_CurrentChunk      = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin;
                    m_CurrentChunkIndex = 0;
                    if (!(m_CurrentChunk->MatchesFilter(m_CurrentMatchingArchetype, m_FilteredSharedComponents) &&
                          (m_CurrentChunk->Count > 0)))
                    {
                        MoveToNextMatchingChunk();
                    }
                }

                while (index >= m_CurrentArchetypeIndex + m_CurrentChunkIndex + m_CurrentChunk->Count)
                {
                    m_CurrentChunkIndex += m_CurrentChunk->Count;
                    MoveToNextMatchingChunk();
                }
            }

            var archetype            = m_CurrentMatchingArchetype->Archetype;
            var typeIndexInArchetype = m_CurrentMatchingArchetype->TypeIndexInArchetypeArray[IndexInComponentGroup];

            cache.CachedBeginIndex = m_CurrentChunkIndex + m_CurrentArchetypeIndex;
            cache.CachedEndIndex   = cache.CachedBeginIndex + m_CurrentChunk->Count;
            cache.CachedSizeOf     = archetype->SizeOfs[typeIndexInArchetype];
            cache.CachedPtr        = m_CurrentChunk->Buffer + archetype->Offsets[typeIndexInArchetype] - cache.CachedBeginIndex * cache.CachedSizeOf;
        }
コード例 #17
0
        public void UpdateCacheResolvedIndex(int index, out ComponentChunkCache cache, bool isWriting)
        {
            Assert.IsTrue(-1 != IndexInComponentGroup);

            if (!m_Filter.RequiresMatchesFilter)
            {
                if (index < m_CurrentArchetypeIndex)
                {
                    m_CurrentMatchingArchetype = m_FirstMatchingArchetype;
                    m_CurrentArchetypeIndex    = 0;
                    m_CurrentChunk             = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin;
                    // 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_CurrentChunkIndex = 0;
                }

                while (index >= m_CurrentArchetypeIndex + m_CurrentMatchingArchetype->Archetype->EntityCount)
                {
                    m_CurrentArchetypeIndex   += m_CurrentMatchingArchetype->Archetype->EntityCount;
                    m_CurrentMatchingArchetype = m_CurrentMatchingArchetype->Next;
                    m_CurrentChunk             = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin;
                    m_CurrentChunkIndex        = 0;
                }

                index -= m_CurrentArchetypeIndex;
                if (index < m_CurrentChunkIndex)
                {
                    m_CurrentChunk      = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin;
                    m_CurrentChunkIndex = 0;
                }

                while (index >= m_CurrentChunkIndex + m_CurrentChunk->Count)
                {
                    m_CurrentChunkIndex += m_CurrentChunk->Count;
                    m_CurrentChunk       = (Chunk *)m_CurrentChunk->ChunkListNode.Next;
                }
            }
            else
            {
                if (index < m_CurrentArchetypeIndex + m_CurrentChunkIndex)
                {
                    if (index < m_CurrentArchetypeIndex)
                    {
                        m_CurrentMatchingArchetype = m_FirstMatchingArchetype;
                        m_CurrentArchetypeIndex    = 0;
                    }

                    m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.End;
                    // 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_CurrentChunkIndex = 0;
                    MoveToNextMatchingChunk();
                }

                while (index >= m_CurrentArchetypeIndex + m_CurrentChunkIndex + m_CurrentChunk->Count)
                {
                    m_CurrentChunkIndex += m_CurrentChunk->Count;
                    MoveToNextMatchingChunk();
                }
            }

            var archetype            = m_CurrentMatchingArchetype->Archetype;
            var typeIndexInArchetype = m_CurrentMatchingArchetype->TypeIndexInArchetypeArray[IndexInComponentGroup];

            cache.CachedBeginIndex = m_CurrentChunkIndex + m_CurrentArchetypeIndex;
            cache.CachedEndIndex   = cache.CachedBeginIndex + m_CurrentChunk->Count;
            cache.CachedSizeOf     = archetype->SizeOfs[typeIndexInArchetype];
            cache.CachedPtr        = m_CurrentChunk->Buffer + archetype->Offsets[typeIndexInArchetype] -
                                     cache.CachedBeginIndex * cache.CachedSizeOf;

            if (isWriting)
            {
                m_CurrentChunk->ChangeVersion[typeIndexInArchetype] = m_GlobalSystemVersion;
            }
        }
コード例 #18
0
 internal ComponentDataArraySt(ComponentChunkIterator iterator, int length)
 {
     m_Length   = length;
     m_Iterator = iterator;
     m_Cache    = default(ComponentChunkCache);
 }