コード例 #1
0
 internal ComponentGroup(EntityGroupData *groupData, ComponentJobSafetyManager safetyManager, ArchetypeManager typeManager, EntityDataManager *entityDataManager)
 {
     m_ComponentGroupData = new ComponentGroupData(groupData, entityDataManager);
     m_SafetyManager      = safetyManager;
     m_TypeManager        = typeManager;
     m_EntityDataManager  = entityDataManager;
 }
コード例 #2
0
ファイル: ComponentGroup.cs プロジェクト: vesper666/UnityECS
        public AtomicSafetyHandle GetSafetyHandle(ComponentJobSafetyManager safetyManager, int indexInComponentGroup)
        {
            var type       = m_GroupData->RequiredComponents + indexInComponentGroup;
            var isReadOnly = type->AccessModeType == ComponentType.AccessMode.ReadOnly;

            return(safetyManager.GetSafetyHandle(type->TypeIndex, isReadOnly));
        }
コード例 #3
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        protected override void OnDestroyManager()
        {
            EndExclusiveEntityTransaction();

            ComponentJobSafetyManager.PreDisposeCheck();

            // Clean up all entities. This is needed to free all internal buffer allocations so memory is not leaked.
            using (var allEntities = GetAllEntities())
            {
                DestroyEntity(allEntities);
            }

            ComponentJobSafetyManager.Dispose();
            ComponentJobSafetyManager = null;

            Entities->OnDestroy();
            UnsafeUtility.Free(Entities, Allocator.Persistent);
            Entities = null;
            ArchetypeManager.Dispose();
            ArchetypeManager = null;
            m_GroupManager.Dispose();
            m_GroupManager = null;
            m_ExclusiveEntityTransaction.OnDestroyManager();

            m_SharedComponentManager.Dispose();

            UnsafeUtility.Free(m_CachedComponentTypeArray, Allocator.Persistent);
            m_CachedComponentTypeArray = null;

            UnsafeUtility.Free(m_CachedComponentTypeInArchetypeArray, Allocator.Persistent);
            m_CachedComponentTypeInArchetypeArray = null;
        }
コード例 #4
0
ファイル: ComponentSystem.cs プロジェクト: qntnt/platformer
        protected override void OnBeforeCreateManagerInternal(World world)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_SystemID = World.AllocateSystemID();
#endif
            m_World         = world;
            m_EntityManager = world.GetOrCreateManager <EntityManager>();
            m_SafetyManager = m_EntityManager.ComponentJobSafetyManager;

            m_ComponentGroups = new ComponentGroup[0];
#if !UNITY_CSHARP_TINY
            m_CachedComponentGroupArrays = new ComponentGroupArrayStaticCache[0];
            m_AlwaysUpdateSystem         = GetType().GetCustomAttributes(typeof(AlwaysUpdateSystemAttribute), true).Length != 0;
#else
            m_AlwaysUpdateSystem = true;
#endif
            m_JobDependencyForReadingManagers = new NativeList <int>(10, Allocator.Persistent);
            m_JobDependencyForWritingManagers = new NativeList <int>(10, Allocator.Persistent);

#if !UNITY_ZEROPLAYER
            ComponentSystemInjection.Inject(this, world, m_EntityManager, out m_InjectedComponentGroups, out m_InjectFromEntityData);
            m_InjectFromEntityData.ExtractJobDependencyTypes(this);
#endif
            InjectNestedIJobProcessComponentDataJobs();

            UpdateInjectedComponentGroups();
        }
コード例 #5
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);
        }
コード例 #6
0
 internal ComponentGroup(ComponentGroup parentComponentGroup, ComponentGroupData componentGroupData)
 {
     m_ComponentGroupData = componentGroupData;
     m_SafetyManager      = parentComponentGroup.m_SafetyManager;
     m_TypeManager        = parentComponentGroup.m_TypeManager;
     m_EntityDataManager  = parentComponentGroup.m_EntityDataManager;
 }
コード例 #7
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        public ExclusiveEntityTransaction BeginExclusiveEntityTransaction()
        {
            ComponentJobSafetyManager.BeginExclusiveTransaction();
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_ExclusiveEntityTransaction.SetAtomicSafetyHandle(ComponentJobSafetyManager.ExclusiveTransactionSafety);
#endif
            return(m_ExclusiveEntityTransaction);
        }
コード例 #8
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
        }
コード例 #9
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
        }
コード例 #10
0
 internal ComponentGroup(EntityGroupData *groupData, ComponentJobSafetyManager safetyManager, ArchetypeManager typeManager, EntityDataManager *entityDataManager)
 {
     m_GroupData         = groupData;
     m_EntityDataManager = entityDataManager;
     m_Filter            = default(ComponentGroupFilter);
     m_SafetyManager     = safetyManager;
     ArchetypeManager    = typeManager;
     EntityDataManager   = entityDataManager;
 }
コード例 #11
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
        }
コード例 #12
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
        }
コード例 #13
0
        internal void SetComponentDataRaw(Entity entity, int typeIndex, void *data, int size)
        {
            m_Entities->AssertEntityHasComponent(entity, typeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

            byte *ptr = m_Entities->GetComponentDataWithType(entity, typeIndex);

            UnsafeUtility.MemCpy(ptr, data, size);
        }
コード例 #14
0
        internal void *GetComponentDataRawRW(Entity entity, int typeIndex)
        {
            Entities->AssertEntityHasComponent(entity, typeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

            var ptr = Entities->GetComponentDataWithTypeRW(entity, typeIndex, Entities->GlobalSystemVersion);

            return(ptr);
        }
コード例 #15
0
        internal void SetComponentDataRaw(Entity entity, int typeIndex, void *data, int size)
        {
            Entities->AssertEntityHasComponent(entity, typeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

            var ptr = Entities->GetComponentDataWithTypeRW(entity, typeIndex, Entities->GlobalSystemVersion);

            UnsafeUtility.MemCpy(ptr, data, size);
        }
コード例 #16
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        internal void *GetBufferRawRW(Entity entity, int typeIndex)
        {
            Entities->AssertEntityHasComponent(entity, typeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

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

            return(BufferHeader.GetElementPointer(header));
        }
コード例 #17
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();
        }
コード例 #18
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        internal int GetBufferLength(Entity entity, int typeIndex)
        {
            Entities->AssertEntityHasComponent(entity, typeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

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

            return(header->Length);
        }
コード例 #19
0
        internal void *GetComponentDataRaw(Entity entity, int typeIndex)
        {
            m_Entities->AssertEntityHasComponent(entity, typeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

            byte *ptr = m_Entities->GetComponentDataWithType(entity, typeIndex);

            return(ptr);
        }
コード例 #20
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
        }
コード例 #21
0
        public void SetComponentData <T>(Entity entity, T componentData) where T : struct, IComponentData
        {
            var typeIndex = TypeManager.GetTypeIndex <T>();

            m_Entities->AssertEntityHasComponent(entity, typeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

            var ptr = m_Entities->GetComponentDataWithType(entity, typeIndex);

            UnsafeUtility.CopyStructureToPtr(ref componentData, ptr);
        }
コード例 #22
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
        }
コード例 #23
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        internal void SetBufferRaw(Entity entity, int componentTypeIndex, BufferHeader *tempBuffer, int sizeInChunk)
        {
            Entities->AssertEntityHasComponent(entity, componentTypeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(componentTypeIndex);

            var ptr = Entities->GetComponentDataWithTypeRW(entity, componentTypeIndex, Entities->GlobalSystemVersion);

            BufferHeader.Destroy((BufferHeader *)ptr);

            UnsafeUtility.MemCpy(ptr, tempBuffer, sizeInChunk);
        }
コード例 #24
0
        public T GetComponentData <T>(Entity entity) where T : struct, IComponentData
        {
            var typeIndex = TypeManager.GetTypeIndex <T>();

            m_Entities->AssertEntityHasComponent(entity, typeIndex);
            ComponentJobSafetyManager.CompleteWriteDependency(typeIndex);

            var ptr = m_Entities->GetComponentDataWithType(entity, typeIndex);

            T value;

            UnsafeUtility.CopyPtrToStructure(ptr, out value);
            return(value);
        }
コード例 #25
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        internal void SetComponentDataRaw(Entity entity, int typeIndex, void *data, int size)
        {
            Entities->AssertEntityHasComponent(entity, typeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (TypeManager.GetTypeInfo(typeIndex).SizeInChunk != size)
            {
                throw new System.ArgumentException($"SetComponentDataRaw<{TypeManager.GetType(typeIndex)}> can not be called with a zero sized component and must have same size as sizeof(T).");
            }
#endif

            var ptr = Entities->GetComponentDataWithTypeRW(entity, typeIndex, Entities->GlobalSystemVersion);
            UnsafeUtility.MemCpy(ptr, data, size);
        }
コード例 #26
0
        protected override void OnBeforeCreateManagerInternal(World world, int capacity)
        {
            m_World              = world;
            m_EntityManager      = world.GetOrCreateManager <EntityManager>();
            m_SafetyManager      = m_EntityManager.ComponentJobSafetyManager;
            m_AlwaysUpdateSystem = GetType().GetCustomAttributes(typeof(AlwaysUpdateSystemAttribute), true).Length != 0;

            m_ComponentGroups                 = new ComponentGroup[0];
            m_CachedComponentGroupArrays      = new ComponentGroupArrayStaticCache[0];
            m_JobDependencyForReadingManagers = new NativeList <int>(10, Allocator.Persistent);
            m_JobDependencyForWritingManagers = new NativeList <int>(10, Allocator.Persistent);

            ComponentSystemInjection.Inject(this, world, m_EntityManager, out m_InjectedComponentGroups, out m_InjectFromEntityData);
            m_InjectFromEntityData.ExtractJobDependencyTypes(this);

            UpdateInjectedComponentGroups();
        }
コード例 #27
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        internal void *GetComponentDataRawRW(Entity entity, int typeIndex)
        {
            Entities->AssertEntityHasComponent(entity, typeIndex);

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (TypeManager.GetTypeInfo(typeIndex).IsZeroSized)
            {
                throw new System.ArgumentException($"GetComponentDataRaw<{TypeManager.GetType(typeIndex)}> can not be called with a zero sized component.");
            }
#endif


            var ptr = Entities->GetComponentDataWithTypeRW(entity, typeIndex, Entities->GlobalSystemVersion);
            return(ptr);
        }
コード例 #28
0
        protected override void OnCreateManager(int capacity)
        {
            TypeManager.Initialize();

            m_Entities = (EntityDataManager *)UnsafeUtility.Malloc(sizeof(EntityDataManager), 64, Allocator.Persistent);
            m_Entities->OnCreate(capacity);

            m_SharedComponentManager = new SharedComponentDataManager();

            m_ArchetypeManager        = new ArchetypeManager(m_SharedComponentManager);
            ComponentJobSafetyManager = new ComponentJobSafetyManager();
            m_GroupManager            = new EntityGroupManager(ComponentJobSafetyManager);

            m_ExclusiveEntityTransaction = new ExclusiveEntityTransaction(m_ArchetypeManager, m_GroupManager, m_SharedComponentManager, m_Entities);

            m_CachedComponentTypeArray            = (ComponentType *)UnsafeUtility.Malloc(sizeof(ComponentType) * 32 * 1024, 16, Allocator.Persistent);
            m_CachedComponentTypeInArchetypeArray = (ComponentTypeInArchetype *)UnsafeUtility.Malloc(sizeof(ComponentTypeInArchetype) * 32 * 1024, 16, Allocator.Persistent);
        }
コード例 #29
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        public void SetComponentData <T>(Entity entity, T componentData) where T : struct, IComponentData
        {
            var typeIndex = TypeManager.GetTypeIndex <T>();

            Entities->AssertEntityHasComponent(entity, typeIndex);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (ComponentType.FromTypeIndex(typeIndex).IsZeroSized)
            {
                throw new System.ArgumentException($"GetComponentData<{typeof(T)}> can not be called with a zero sized component.");
            }
#endif

            ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex);

            var ptr = Entities->GetComponentDataWithTypeRW(entity, typeIndex, Entities->GlobalSystemVersion);
            UnsafeUtility.CopyStructureToPtr(ref componentData, ptr);
        }
コード例 #30
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        public T GetComponentData <T>(Entity entity) where T : struct, IComponentData
        {
            var typeIndex = TypeManager.GetTypeIndex <T>();

            Entities->AssertEntityHasComponent(entity, typeIndex);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (ComponentType.FromTypeIndex(typeIndex).IsZeroSized)
            {
                throw new System.ArgumentException($"GetComponentData<{typeof(T)}> can not be called with a zero sized component.");
            }
#endif

            ComponentJobSafetyManager.CompleteWriteDependency(typeIndex);

            var ptr = Entities->GetComponentDataWithTypeRO(entity, typeIndex);

            T value;
            UnsafeUtility.CopyPtrToStructure(ptr, out value);
            return(value);
        }