void PatchGetIndexInComponentGroup(InjectionData[] componentInjections)
 {
     for (var i = 0; i != componentInjections.Length; i++)
     {
         componentInjections[i].IndexInComponentGroup = m_EntityGroup.GetIndexInComponentGroup(componentInjections[i].ComponentType.TypeIndex);
     }
 }
Esempio n. 2
0
        public static GameObjectArray GetGameObjectArray(this ComponentGroup group)
        {
            int length = group.CalculateLength();
            ComponentChunkIterator iterator = group.GetComponentChunkIterator();

            iterator.IndexInComponentGroup = group.GetIndexInComponentGroup(TypeManager.GetTypeIndex <Transform>());
            return(new GameObjectArray(iterator, length, group.ArchetypeManager));
        }
        public static ComponentArray <T> GetComponentArray <T>(this ComponentGroup group) where T : Component
        {
            int length = group.CalculateLength();
            ComponentChunkIterator iterator = group.GetComponentChunkIterator();
            var indexInComponentGroup       = group.GetIndexInComponentGroup(TypeManager.GetTypeIndex <T>());

            iterator.IndexInComponentGroup = indexInComponentGroup;
            return(new ComponentArray <T>(iterator, length, group.ArchetypeManager));
        }
Esempio n. 4
0
        public static ComponentArray <T> GetComponentArray <T>(this ComponentGroup group) where T : Component
        {
            Profiler.BeginSample("GetComponentArray");

            int length;
            ComponentChunkIterator iterator;

            group.GetComponentChunkIterator(out length, out iterator);
            var indexInComponentGroup = group.GetIndexInComponentGroup(TypeManager.GetTypeIndex <T>());

            iterator.IndexInComponentGroup = indexInComponentGroup;

            Profiler.EndSample();
            return(new ComponentArray <T>(iterator, length, group.ArchetypeManager));
        }
        public static T[] ToComponentArray <T>(this ComponentGroup group) where T : Component
        {
            int length = group.CalculateLength();
            ComponentChunkIterator iterator = group.GetComponentChunkIterator();
            var indexInComponentGroup       = group.GetIndexInComponentGroup(TypeManager.GetTypeIndex <T>());

            iterator.IndexInComponentGroup = indexInComponentGroup;

            var arr   = new T[length];
            var cache = default(ComponentChunkCache);

            for (int i = 0; i < length; ++i)
            {
                if (i < cache.CachedBeginIndex || i >= cache.CachedEndIndex)
                {
                    iterator.MoveToEntityIndexAndUpdateCache(i, out cache, true);
                }

                arr[i] = (T)iterator.GetManagedObject(group.ArchetypeManager, cache.CachedBeginIndex, i);
            }

            return(arr);
        }
        internal static unsafe void Initialize(ComponentSystemBase system, Type jobType, Type wrapperJobType, bool isParallelFor, ref JobProcessComponentDataCache cache, out ProcessIterationData iterator)
        {
            int num;
            int num1;

            if (!isParallelFor || !(cache.JobReflectionDataParallelFor == IntPtr.Zero))
            {
                num1 = isParallelFor ? 0 : ((int)(cache.JobReflectionData == IntPtr.Zero));
            }
            else
            {
                num1 = 1;
            }
            if (num1 != 0)
            {
                Type iJobProcessComponentDataInterface = GetIJobProcessComponentDataInterface(jobType);
                if (cache.Types == null)
                {
                    cache.Types = GetComponentTypes(jobType, iJobProcessComponentDataInterface, out cache.ProcessTypesCount, out cache.FilterChanged);
                }
                IntPtr ptr = GetJobReflection(jobType, wrapperJobType, iJobProcessComponentDataInterface, isParallelFor);
                if (isParallelFor)
                {
                    cache.JobReflectionDataParallelFor = ptr;
                }
                else
                {
                    cache.JobReflectionData = ptr;
                }
            }
            if (cache.ComponentSystem != system)
            {
                cache.ComponentGroup = system.GetComponentGroupInternal(cache.Types);
                if (cache.FilterChanged.Length != 0)
                {
                    cache.ComponentGroup.SetFilterChanged(cache.FilterChanged);
                }
                else
                {
                    cache.ComponentGroup.ResetFilter();
                }
                cache.ComponentSystem = system;
            }
            ComponentGroup componentGroup = cache.ComponentGroup;

            iterator.IsReadOnly3 = num = 0;
            iterator.IsReadOnly2 = num = num;
            iterator.IsReadOnly1 = num = num;
            iterator.IsReadOnly0 = num;
            int *numPtr = &iterator.IsReadOnly0;
            int  index  = 0;

            while (true)
            {
                if (index == cache.ProcessTypesCount)
                {
                    fixed(int *numRef = null)
                    {
                        componentGroup.GetComponentChunkIterator(out iterator.Iterator);
                        iterator.IndexInGroup3 = num = -1;
                        iterator.IndexInGroup2 = num = num;
                        iterator.IndexInGroup0 = iterator.IndexInGroup1 = num;
                        int *numPtr2 = &iterator.IndexInGroup0;
                        int  num3    = 0;

                        while (true)
                        {
                            if (num3 == cache.ProcessTypesCount)
                            {
                                fixed(int *numRef2 = null)
                                {
                                    iterator.m_IsParallelFor = isParallelFor;
                                    iterator.m_Length        = componentGroup.CalculateNumberOfChunksWithoutFiltering();
                                    iterator.m_MaxIndex      = iterator.m_Length - 1;
                                    iterator.m_MinIndex      = 0;
                                    AtomicSafetyHandle handle = new AtomicSafetyHandle();

                                    iterator.m_Safety3             = handle = handle;
                                    iterator.m_Safety2             = handle = handle;
                                    iterator.m_Safety0             = iterator.m_Safety1 = handle;
                                    iterator.m_SafetyReadOnlyCount = 0;
                                    AtomicSafetyHandle *handlePtr = &iterator.m_Safety0;
                                    int num4 = 0;

                                    while (true)
                                    {
                                        if (num4 == cache.ProcessTypesCount)
                                        {
                                            fixed(AtomicSafetyHandle *handleRef = null)
                                            {
                                                iterator.m_SafetyReadWriteCount = 0;
                                                AtomicSafetyHandle *handlePtr2 = &iterator.m_Safety0;
                                                int num5 = 0;

                                                while (true)
                                                {
                                                    if (num5 == cache.ProcessTypesCount)
                                                    {
                                                        fixed(AtomicSafetyHandle *handleRef2 = null)
                                                        {
                                                            Assert.AreEqual(cache.ProcessTypesCount, iterator.m_SafetyReadWriteCount + iterator.m_SafetyReadOnlyCount);
                                                            return;
                                                        }
                                                    }
                                                    if (cache.Types[num5].AccessModeType == ComponentType.AccessMode.ReadWrite)
                                                    {
                                                        handlePtr2[iterator.m_SafetyReadOnlyCount + iterator.m_SafetyReadWriteCount] = componentGroup.GetSafetyHandle(componentGroup.GetIndexInComponentGroup(cache.Types[num5].TypeIndex));
                                                        int *numPtr1 = (int *)ref iterator.m_SafetyReadWriteCount;
                                                        numPtr1[0]++;
                                                    }
                                                    num5++;
                                                }
                                            }
                                        }
                                        if (cache.Types[num4].AccessModeType == ComponentType.AccessMode.ReadOnly)
                                        {
                                            handlePtr[iterator.m_SafetyReadOnlyCount] = componentGroup.GetSafetyHandle(componentGroup.GetIndexInComponentGroup(cache.Types[num4].TypeIndex));
                                            int *numPtr3 = (int *)ref iterator.m_SafetyReadOnlyCount;
                                            numPtr3[0]++;
                                        }
                                        num4++;
                                    }
                                }
                            }
                            numPtr2[num3] = componentGroup.GetIndexInComponentGroup(cache.Types[num3].TypeIndex);
                            num3++;
                        }
                    }
                }
                numPtr[index] = (cache.Types[index].AccessModeType == ComponentType.AccessMode.ReadOnly) ? 1 : 0;
                index++;
            }
        }
 public override void PrepareEntry(ref InjectionContext.Entry entry, ComponentGroup entityGroup)
 {
     entry.IndexInComponentGroup = entityGroup.GetIndexInComponentGroup(entry.ComponentType.TypeIndex);
 }