コード例 #1
0
        internal AtomicSafetyHandle GetSafetyHandle(int indexInComponentGroup)
        {
            var type       = m_GroupData->RequiredComponents + indexInComponentGroup;
            var isReadOnly = type->AccessModeType == ComponentType.AccessMode.ReadOnly;

            return(m_SafetyManager.GetSafetyHandle(type->TypeIndex, isReadOnly));
        }
コード例 #2
0
        internal void GetIndexFromEntity(out IndexFromEntity output)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            output = new IndexFromEntity(m_ComponentGroupData, m_SafetyManager.GetSafetyHandle(TypeManager.GetTypeIndex <Entity>(), true));
#else
            output = new IndexFromEntity(m_ComponentGroupData);
#endif
        }
コード例 #3
0
        public NativeArray <T> GetFixedArray <T>(Entity entity) where T : struct
        {
            var typeIndex = TypeManager.GetTypeIndex <T>();

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_Entities->AssertEntityHasComponent(entity, typeIndex);
            if (TypeManager.GetComponentType <T>().Category != TypeManager.TypeCategory.OtherValueType)
            {
                throw new ArgumentException($"GetComponentFixedArray<{typeof(T)}> may not be IComponentData or ISharedComponentData");
            }
#endif

            ComponentJobSafetyManager.CompleteWriteDependency(typeIndex);

            byte *ptr;
            int   length;
            m_Entities->GetComponentDataWithTypeAndFixedArrayLength(entity, typeIndex, out ptr, out length);

            var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(ptr, length, Allocator.Invalid);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, ComponentJobSafetyManager.GetSafetyHandle(typeIndex, false));
#endif

            return(array);
        }
コード例 #4
0
        public FixedArrayFromEntity <T> GetFixedArrayFromEntity <T>(int typeIndex, bool isReadOnly = false) where T : struct
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            return(new FixedArrayFromEntity <T>(typeIndex, m_Entities, ComponentJobSafetyManager.GetSafetyHandle(typeIndex, isReadOnly)));
#else
            return(new FixedArrayFromEntity <T>(typeIndex, m_Entities));
#endif
        }
コード例 #5
0
        internal ComponentDataFromEntity <T> GetComponentDataFromEntity <T>(int typeIndex, bool isReadOnly) where T : struct, IComponentData
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            return(new ComponentDataFromEntity <T>(typeIndex, m_Entities, ComponentJobSafetyManager.GetSafetyHandle(typeIndex, isReadOnly)));
#else
            return(new ComponentDataFromEntity <T>(typeIndex, m_Entities));
#endif
        }
コード例 #6
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        public ArchetypeChunkEntityType GetArchetypeChunkEntityType()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            return(new ArchetypeChunkEntityType(
                       ComponentJobSafetyManager.GetSafetyHandle(TypeManager.GetTypeIndex <Entity>(), true)));
#else
            return(new ArchetypeChunkEntityType(false));
#endif
        }
コード例 #7
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        public ArchetypeChunkSharedComponentType <T> GetArchetypeChunkSharedComponentType <T>()
            where T : struct, ISharedComponentData
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            return(new ArchetypeChunkSharedComponentType <T>(
                       ComponentJobSafetyManager.GetSafetyHandle(TypeManager.GetTypeIndex <T>(), true)));
#else
            return(new ArchetypeChunkSharedComponentType <T>(false));
#endif
        }
コード例 #8
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        public BufferFromEntity <T> GetBufferFromEntity <T>(int typeIndex, bool isReadOnly = false)
            where T : struct, IBufferElementData
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            return(new BufferFromEntity <T>(typeIndex, Entities, isReadOnly,
                                            ComponentJobSafetyManager.GetSafetyHandle(typeIndex, isReadOnly),
                                            ComponentJobSafetyManager.GetBufferSafetyHandle(typeIndex)));
#else
            return(new BufferFromEntity <T>(typeIndex, m_Entities, isReadOnly));
#endif
        }
コード例 #9
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        public ArchetypeChunkComponentType <T> GetArchetypeChunkComponentType <T>(bool isReadOnly)
            where T : struct, IComponentData
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            var typeIndex = TypeManager.GetTypeIndex <T>();
            return(new ArchetypeChunkComponentType <T>(
                       ComponentJobSafetyManager.GetSafetyHandle(typeIndex, isReadOnly), isReadOnly,
                       GlobalSystemVersion));
#else
            return(new ArchetypeChunkComponentType <T>(isReadOnly, GlobalSystemVersion));
#endif
        }
コード例 #10
0
ファイル: ComponentGroup.cs プロジェクト: vesper666/UnityECS
        internal void GetSharedComponentDataArray <T>(ref ComponentChunkIterator iterator, int indexInComponentGroup,
                                                      int length, out SharedComponentDataArray <T> output) where T : struct, ISharedComponentData
        {
            iterator.IndexInComponentGroup = indexInComponentGroup;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            var typeIndex = m_ComponentGroupData.ComponentTypeIndex(indexInComponentGroup);
            output = new SharedComponentDataArray <T>(ArchetypeManager.GetSharedComponentDataManager(),
                                                      indexInComponentGroup, iterator, length, m_SafetyManager.GetSafetyHandle(typeIndex, true));
#else
            output = new SharedComponentDataArray <T>(ArchetypeManager.GetSharedComponentDataManager(),
                                                      indexInComponentGroup, iterator, length);
#endif
        }
コード例 #11
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        public DynamicBuffer <T> GetBuffer <T>(Entity entity) where T : struct, IBufferElementData
        {
            var typeIndex = TypeManager.GetTypeIndex <T>();

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            Entities->AssertEntityHasComponent(entity, typeIndex);
            if (TypeManager.GetTypeInfo <T>().Category != TypeManager.TypeCategory.BufferData)
            {
                throw new ArgumentException(
                          $"GetBuffer<{typeof(T)}> may not be IComponentData or ISharedComponentData; currently {TypeManager.GetTypeInfo<T>().Category}");
            }
#endif

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

            BufferHeader *header = (BufferHeader *)Entities->GetComponentDataWithTypeRW(entity, typeIndex, Entities->GlobalSystemVersion);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            return(new DynamicBuffer <T>(header, ComponentJobSafetyManager.GetSafetyHandle(typeIndex, false), ComponentJobSafetyManager.GetBufferSafetyHandle(typeIndex), false));
#else
            return(new DynamicBuffer <T>(header));
#endif
        }
コード例 #12
0
        public unsafe ComponentGroupArrayData(ComponentGroupArrayStaticCache staticCache)
        {
            int outLength = 0;

            staticCache.ComponentGroup.GetComponentChunkIterator(out outLength, out this.m_ChunkIterator);
            this.m_ChunkIterator.IndexInComponentGroup = 0;
            this.m_Length             = outLength;
            this.m_MinIndex           = 0;
            this.m_MaxIndex           = outLength - 1;
            this.CacheBeginIndex      = 0;
            this.CacheEndIndex        = 0;
            this.m_ArchetypeManager   = staticCache.ComponentGroup.GetArchetypeManager();
            this.m_ComponentDataCount = staticCache.ComponentDataCount;
            this.m_ComponentCount     = staticCache.ComponentCount;
            int * numPtr  = &this.m_IndexInComponentGroup.FixedElementField;
            bool *flagPtr = &this.m_IsWriting.FixedElementField;
            ComponentGroupStream *streamPtr = (ComponentGroupStream *)&this.m_Caches.FixedElementField;
            int index = 0;

            while (true)
            {
                if (index >= (staticCache.ComponentDataCount + staticCache.ComponentCount))
                {
                    fixed(bool **flagPtrRef = null)
                    {
                        fixed(byte **numPtrRef2 = null)
                        {
                            fixed(int **numPtrRef = null)
                            {
                                this.m_Safety0 = new AtomicSafetyHandle();
                                this.m_Safety1 = new AtomicSafetyHandle();
                                this.m_Safety2 = new AtomicSafetyHandle();
                                this.m_Safety3 = new AtomicSafetyHandle();
                                this.m_Safety4 = new AtomicSafetyHandle();
                                this.m_Safety5 = new AtomicSafetyHandle();
                                Assert.AreEqual(6, 6);
                                this.m_SafetyReadWriteCount = 0;
                                this.m_SafetyReadOnlyCount  = 0;
                                ComponentJobSafetyManager safetyManager = staticCache.SafetyManager;
                                AtomicSafetyHandle *      handlePtr     = &this.m_Safety0;
                                int num3 = 0;

                                while (true)
                                {
                                    if (num3 == staticCache.ComponentTypes.Length)
                                    {
                                        int num4 = 0;
                                        while (true)
                                        {
                                            if (num4 == staticCache.ComponentTypes.Length)
                                            {
                                                fixed(AtomicSafetyHandle *handleRef = null)
                                                {
                                                    return;
                                                }
                                            }
                                            ComponentType type2 = staticCache.ComponentTypes[num4];
                                            if (type2.AccessModeType == ComponentType.AccessMode.ReadWrite)
                                            {
                                                handlePtr[this.m_SafetyReadOnlyCount + this.m_SafetyReadWriteCount] = safetyManager.GetSafetyHandle(type2.TypeIndex, false);
                                                this.m_SafetyReadWriteCount++;
                                            }
                                            num4++;
                                        }
                                    }
                                    ComponentType type = staticCache.ComponentTypes[num3];
                                    if (type.AccessModeType == ComponentType.AccessMode.ReadOnly)
                                    {
                                        handlePtr[this.m_SafetyReadOnlyCount] = safetyManager.GetSafetyHandle(type.TypeIndex, true);
                                        this.m_SafetyReadOnlyCount++;
                                    }
                                    num3++;
                                }
                            }
                        }
                    }
                }
                numPtr[index] = staticCache.ComponentGroup.GetIndexInComponentGroup(staticCache.ComponentTypes[index].TypeIndex);
                streamPtr[index].FieldOffset  = (ushort)staticCache.ComponentFieldOffsets[index];
                *((sbyte *)(flagPtr + index)) = staticCache.ComponentTypes[index].AccessModeType == ComponentType.AccessMode.ReadWrite;
                index++;
            }
        }