Esempio n. 1
0
        void BeforeStructuralChange()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (ComponentJobSafetyManager.IsInTransaction)
            {
                throw new InvalidOperationException("Access to EntityManager is not allowed after EntityManager.BeginExclusiveEntityTransaction(); has been called.");
            }
#endif
            ComponentJobSafetyManager.CompleteAllJobsAndInvalidateArrays();
        }
Esempio n. 2
0
 //@TODO: Not clear to me what this method is really for...
 public void CompleteAllJobs()
 {
     ComponentJobSafetyManager.CompleteAllJobsAndInvalidateArrays();
 }
Esempio n. 3
0
        public ComponentGroup CreateEntityGroup(ArchetypeManager typeMan, EntityDataManager *entityDataManager,
                                                ComponentType *requiredTypes, int requiredCount)
        {
            var hash = HashUtility.Fletcher32((ushort *)requiredTypes,
                                              requiredCount * sizeof(ComponentType) / sizeof(short));
            var grp = GetCachedGroupData(hash, requiredTypes, requiredCount);

            if (grp != null)
            {
                return(new ComponentGroup(grp, m_JobSafetyManager, typeMan, entityDataManager));
            }

            m_JobSafetyManager.CompleteAllJobsAndInvalidateArrays();

            grp             = (EntityGroupData *)m_GroupDataChunkAllocator.Allocate(sizeof(EntityGroupData), 8);
            grp->PrevGroup  = m_LastGroupData;
            m_LastGroupData = grp;
            grp->RequiredComponentsCount = requiredCount;
            grp->RequiredComponents      =
                (ComponentType *)m_GroupDataChunkAllocator.Construct(sizeof(ComponentType) * requiredCount, 4,
                                                                     requiredTypes);

            grp->ReaderTypesCount = 0;
            grp->WriterTypesCount = 0;

            grp->SubtractiveComponentsCount = 0;

            for (var i = 0; i != requiredCount; i++)
            {
                if (requiredTypes[i].AccessModeType == ComponentType.AccessMode.Subtractive)
                {
                    grp->SubtractiveComponentsCount++;
                }
                if (!requiredTypes[i].RequiresJobDependency)
                {
                    continue;
                }
                switch (requiredTypes[i].AccessModeType)
                {
                case ComponentType.AccessMode.ReadOnly:
                    grp->ReaderTypesCount++;
                    break;

                default:
                    grp->WriterTypesCount++;
                    break;
                }
            }

            grp->ReaderTypes = (int *)m_GroupDataChunkAllocator.Allocate(sizeof(int) * grp->ReaderTypesCount, 4);
            grp->WriterTypes = (int *)m_GroupDataChunkAllocator.Allocate(sizeof(int) * grp->WriterTypesCount, 4);

            var curReader = 0;
            var curWriter = 0;

            for (var i = 0; i != requiredCount; i++)
            {
                if (!requiredTypes[i].RequiresJobDependency)
                {
                    continue;
                }
                switch (requiredTypes[i].AccessModeType)
                {
                case ComponentType.AccessMode.ReadOnly:
                    grp->ReaderTypes[curReader++] = requiredTypes[i].TypeIndex;
                    break;

                default:
                    grp->WriterTypes[curWriter++] = requiredTypes[i].TypeIndex;
                    break;
                }
            }

            grp->RequiredComponents =
                (ComponentType *)m_GroupDataChunkAllocator.Construct(sizeof(ComponentType) * requiredCount, 4,
                                                                     requiredTypes);

            grp->FirstMatchingArchetype = null;
            grp->LastMatchingArchetype  = null;
            for (var type = typeMan.m_LastArchetype; type != null; type = type->PrevArchetype)
            {
                AddArchetypeIfMatching(type, grp);
            }
            m_GroupLookup.Add(hash, (IntPtr)grp);
            return(new ComponentGroup(grp, m_JobSafetyManager, typeMan, entityDataManager));
        }