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; }
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)); }
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; }
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(); }
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); }
internal ComponentGroup(ComponentGroup parentComponentGroup, ComponentGroupData componentGroupData) { m_ComponentGroupData = componentGroupData; m_SafetyManager = parentComponentGroup.m_SafetyManager; m_TypeManager = parentComponentGroup.m_TypeManager; m_EntityDataManager = parentComponentGroup.m_EntityDataManager; }
public ExclusiveEntityTransaction BeginExclusiveEntityTransaction() { ComponentJobSafetyManager.BeginExclusiveTransaction(); #if ENABLE_UNITY_COLLECTIONS_CHECKS m_ExclusiveEntityTransaction.SetAtomicSafetyHandle(ComponentJobSafetyManager.ExclusiveTransactionSafety); #endif return(m_ExclusiveEntityTransaction); }
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 }
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 }
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; }
public ArchetypeChunkEntityType GetArchetypeChunkEntityType() { #if ENABLE_UNITY_COLLECTIONS_CHECKS return(new ArchetypeChunkEntityType( ComponentJobSafetyManager.GetSafetyHandle(TypeManager.GetTypeIndex <Entity>(), true))); #else return(new ArchetypeChunkEntityType(false)); #endif }
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 }
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); }
internal void *GetComponentDataRawRW(Entity entity, int typeIndex) { Entities->AssertEntityHasComponent(entity, typeIndex); ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex); var ptr = Entities->GetComponentDataWithTypeRW(entity, typeIndex, Entities->GlobalSystemVersion); return(ptr); }
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); }
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)); }
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(); }
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); }
internal void *GetComponentDataRaw(Entity entity, int typeIndex) { m_Entities->AssertEntityHasComponent(entity, typeIndex); ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex); byte *ptr = m_Entities->GetComponentDataWithType(entity, typeIndex); return(ptr); }
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 }
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); }
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 }
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); }
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); }
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); }
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(); }
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); }
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); }
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); }
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); }