internal override void UpdateSerializedData(EntityManager manager, Entity entity) { if (!ComponentType.Create <T>().IsZeroSized) { m_SerializedData = manager.GetComponentData <T>(entity); } }
public void AddSharedComponentData <T>(Entity entity, ref T componentData) where T : struct, ISharedComponentData #if REF_EQUATABLE , IRefEquatable <T> #endif { //TODO: optimize this (no need to move the entity to a new chunk twice) AddComponent(entity, ComponentType.Create <T>()); SetSharedComponentData(entity, ref componentData); }
int PopulatedCachedTypeInArchetypeArray(ComponentType[] requiredComponents) { m_CachedComponentTypeInArchetypeArray[0] = new ComponentTypeInArchetype(ComponentType.Create <Entity>()); for (var i = 0; i < requiredComponents.Length; ++i) { SortingUtilities.InsertSorted(m_CachedComponentTypeInArchetypeArray, i + 1, requiredComponents[i]); } return(requiredComponents.Length + 1); }
private int PopulatedCachedTypeInArchetypeArray(ComponentType *requiredComponents, int count) { m_CachedComponentTypeInArchetypeArray[0] = new ComponentTypeInArchetype(ComponentType.Create <Entity>()); for (var i = 0; i < count; ++i) { SortingUtilities.InsertSorted(m_CachedComponentTypeInArchetypeArray, i + 1, requiredComponents[i]); } return(count + 1); }
public void AddComponentData <T>(Entity entity, T componentData) where T : struct, IComponentData { var type = ComponentType.Create <T>(); AddComponent(entity, type); if (!type.IsZeroSized) { SetComponentData(entity, componentData); } }
void CreateRequiredComponents(ComponentType *requiredComponents, int requiredComponentsCount, out ComponentType *types, out int typesCount) { types = (ComponentType *)m_GroupDataChunkAllocator.Allocate(sizeof(ComponentType) * (requiredComponentsCount + 1), UnsafeUtility.AlignOf <ComponentType>()); types[0] = ComponentType.Create <Entity>(); for (int i = 0; i != requiredComponentsCount; i++) { types[i + 1] = requiredComponents[i]; } typesCount = requiredComponentsCount + 1; }
public static unsafe T GetComponentObject <T>(this EntityManager entityManager, Entity entity) where T : Component { var componentType = ComponentType.Create <T>(); entityManager.Entities->AssertEntityHasComponent(entity, componentType.TypeIndex); Chunk *chunk; int chunkIndex; entityManager.Entities->GetComponentChunk(entity, out chunk, out chunkIndex); return(entityManager.ArchetypeManager.GetManagedObject(chunk, componentType, chunkIndex) as T); }
private int PopulatedCachedTypeInArchetypeArray(ComponentType *requiredComponents, int count) { #if ENABLE_UNITY_COLLECTIONS_CHECKS if (count + 1 > m_CachedComponentTypeInArchetypeArrayLength) { throw new System.ArgumentException($"Archetypes can't hold more than {m_CachedComponentTypeInArchetypeArrayLength}"); } #endif m_CachedComponentTypeInArchetypeArray[0] = new ComponentTypeInArchetype(ComponentType.Create <Entity>()); for (var i = 0; i < count; ++i) { SortingUtilities.InsertSorted(m_CachedComponentTypeInArchetypeArray, i + 1, requiredComponents[i]); } return(count + 1); }
public void SetSingleton <T>(T value) where T : struct, IComponentData { var type = ComponentType.Create <T>(); var group = GetComponentGroupInternal(&type, 1); var array = group.GetComponentDataArray <T>(); #if ENABLE_UNITY_COLLECTIONS_CHECKS if (array.Length != 1) { throw new System.InvalidOperationException($"SetSingleton<{typeof(T)}>() requires that exactly one {typeof(T)} exists but there are {array.Length}."); } #endif group.CompleteDependency(); array[0] = value; }
private unsafe void CreateRequiredComponents(ComponentType[] requiredComponents, out ComponentType *types, out int typesCount) { types = (ComponentType *)this.m_GroupDataChunkAllocator.Allocate(sizeof(ComponentType) * (requiredComponents.Length + 1), UnsafeUtility.AlignOf <ComponentType>()); types = (ComponentType *)ComponentType.Create <Entity>(); int index = 0; while (true) { if (index == requiredComponents.Length) { typesCount = requiredComponents.Length + 1; return; } types + (((IntPtr)(index + 1)) * sizeof(ComponentType)) = (ComponentType *)requiredComponents[index]; index++; } }
public ComponentDataFromEntity <T> GetComponentDataFromEntity <T>(bool isReadOnly = false) where T : struct, IComponentData { AddReaderWriter(isReadOnly ? ComponentType.ReadOnly <T>() : ComponentType.Create <T>()); return(EntityManager.GetComponentDataFromEntity <T>(isReadOnly)); }
public ArchetypeChunkBufferType <T> GetArchetypeChunkBufferType <T>(bool isReadOnly = false) where T : struct, IBufferElementData { AddReaderWriter(isReadOnly ? ComponentType.ReadOnly <T>() : ComponentType.Create <T>()); return(EntityManager.GetArchetypeChunkBufferType <T>(isReadOnly)); }
public void TryRemoveEntityId(Entity *entities, int count, ArchetypeManager archetypeManager, SharedComponentDataManager sharedComponentDataManager, EntityGroupManager groupManager, ComponentTypeInArchetype *componentTypeInArchetypeArray) { var entityIndex = 0; while (entityIndex != count) { int indexInChunk; int batchCount; fixed(EntityDataManager *manager = &this) { var chunk = EntityChunkBatch(manager, entities + entityIndex, count - entityIndex, out indexInChunk, out batchCount); var archetype = GetArchetype(entities[entityIndex]); if (!archetype->SystemStateCleanupNeeded) { DeallocateDataEntitiesInChunk(manager, entities + entityIndex, chunk, indexInChunk, batchCount); IncrementComponentOrderVersion(chunk->Archetype, chunk, sharedComponentDataManager); if (chunk->ManagedArrayIndex >= 0) { // We can just chop-off the end, no need to copy anything if (chunk->Count != indexInChunk + batchCount) { ChunkDataUtility.CopyManagedObjects(archetypeManager, chunk, chunk->Count - batchCount, chunk, indexInChunk, batchCount); } ChunkDataUtility.ClearManagedObjects(archetypeManager, chunk, chunk->Count - batchCount, batchCount); } chunk->Archetype->EntityCount -= batchCount; archetypeManager.SetChunkCount(chunk, chunk->Count - batchCount); } else { for (var batchEntityIndex = 0; batchEntityIndex < batchCount; batchEntityIndex++) { var entity = entities[entityIndex + batchEntityIndex]; var removedTypes = 0; var removedComponentIsShared = false; for (var t = 1; t < archetype->TypesCount; ++t) { var type = archetype->Types[t]; if (!(type.IsSystemStateComponent || type.IsSystemStateSharedComponent)) { ++removedTypes; removedComponentIsShared |= type.IsSharedComponent; } else { componentTypeInArchetypeArray[t - removedTypes] = archetype->Types[t]; } } componentTypeInArchetypeArray[archetype->TypesCount - removedTypes] = new ComponentTypeInArchetype(ComponentType.Create <CleanupEntity>()); var newType = archetypeManager.GetOrCreateArchetype(componentTypeInArchetypeArray, archetype->TypesCount - removedTypes + 1, groupManager); int *sharedComponentDataIndices = null; if (newType->NumSharedComponents > 0) { var oldSharedComponentDataIndices = GetComponentChunk(entity)->SharedComponentValueArray; if (removedComponentIsShared) { int *tempAlloc = stackalloc int[newType->NumSharedComponents]; sharedComponentDataIndices = tempAlloc; var srcIndex = 0; var dstIndex = 0; for (var t = 0; t < archetype->TypesCount; ++t) { if (archetype->SharedComponentOffset[t] != -1) { var typeIndex = archetype->Types[t].TypeIndex; var systemStateType = typeof(ISystemStateComponentData).IsAssignableFrom(TypeManager.GetType(typeIndex)); var systemStateSharedType = typeof(ISystemStateSharedComponentData).IsAssignableFrom(TypeManager.GetType(typeIndex)); if (!(systemStateType || systemStateSharedType)) { srcIndex++; } else { sharedComponentDataIndices[dstIndex] = oldSharedComponentDataIndices[srcIndex]; srcIndex++; dstIndex++; } } } } else { // reuse old sharedComponentDataIndices sharedComponentDataIndices = oldSharedComponentDataIndices; } } IncrementComponentOrderVersion(archetype, GetComponentChunk(entity), sharedComponentDataManager); SetArchetype(archetypeManager, entity, newType, sharedComponentDataIndices); } } } entityIndex += batchCount; } }
public BufferFromEntity <T> GetBufferFromEntity <T>(bool isReadOnly = false) where T : struct, IBufferElementData { this.AddReaderWriter(isReadOnly ? ComponentType.ReadOnly <T>() : ComponentType.Create <T>()); return(base.EntityManager.GetBufferFromEntity <T>(isReadOnly)); }
public void AddSharedComponentData <T>(Entity entity, T componentData) where T : struct, ISharedComponentData { //TODO: optimize this (no need to move the entity to a new chunk twice) AddComponent(entity, ComponentType.Create <T>()); SetSharedComponentData(entity, componentData); }
public void AddSharedComponentData <T>(Entity entity, T componentData) where T : struct, ISharedComponentData { this.AddComponent(entity, ComponentType.Create <T>()); this.SetSharedComponentData <T>(entity, componentData); }
public bool HasComponent <T>(Entity entity) { return(Entities->HasComponent(entity, ComponentType.Create <T>())); }
public FixedArrayFromEntity <T> GetFixedArrayFromEntity <T>(bool isReadOnly = false) where T : struct { AddReaderWriter(isReadOnly ? ComponentType.ReadOnly <T>() : ComponentType.Create <T>()); return(EntityManager.GetFixedArrayFromEntity <T>(TypeManager.GetTypeIndex <T>(), isReadOnly)); }
public unsafe bool HasComponent <T>(Entity entity) => this.Entities.HasComponent(entity, ComponentType.Create <T>());
private unsafe int PopulatedCachedTypeInArchetypeArray(ComponentType *requiredComponents, int count) { if ((count + 1) > 0x400) { throw new ArgumentException($"Archetypes can't hold more than {0x400}"); } this.m_CachedComponentTypeInArchetypeArray[0] = new ComponentTypeInArchetype(ComponentType.Create <Entity>()); for (int i = 0; i < count; i++) { SortingUtilities.InsertSorted(this.m_CachedComponentTypeInArchetypeArray, i + 1, requiredComponents[i]); } return(count + 1); }
public void RemoveComponent <T>(Entity entity) { RemoveComponent(entity, ComponentType.Create <T>()); }
internal override ComponentType GetComponentType(EntityManager manager) { return(ComponentType.Create <T>()); }
public void AddBuffer <T>(Entity entity) where T : struct, IBufferElementData { AddComponent(entity, ComponentType.Create <T>()); }
public void AddComponentData <T>(Entity entity, T componentData) where T : struct, IComponentData { AddComponent(entity, ComponentType.Create <T>()); SetComponentData(entity, componentData); }
public Archetype *GetOrCreateArchetype(ComponentTypeInArchetype *types, int count, EntityGroupManager groupManager) { var srcArchetype = GetExistingArchetype(types, count); if (srcArchetype != null) { return(srcArchetype); } srcArchetype = CreateArchetypeInternal(types, count, groupManager); var removedTypes = 0; var prefabTypeIndex = TypeManager.GetTypeIndex <Prefab>(); for (var t = 0; t < srcArchetype->TypesCount; ++t) { var type = srcArchetype->Types[t]; var skip = type.IsSystemStateComponent || type.IsSystemStateSharedComponent || (type.TypeIndex == prefabTypeIndex); if (skip) { ++removedTypes; } else { types[t - removedTypes] = srcArchetype->Types[t]; } } srcArchetype->InstantiableArchetype = srcArchetype; if (removedTypes > 0) { var instantiableArchetype = GetOrCreateArchetypeInternal(types, count - removedTypes, groupManager); srcArchetype->InstantiableArchetype = instantiableArchetype; instantiableArchetype->InstantiableArchetype = instantiableArchetype; instantiableArchetype->SystemStateResidueArchetype = null; } if (!srcArchetype->SystemStateCleanupNeeded) { return(srcArchetype); } var cleanupEntityType = new ComponentTypeInArchetype(ComponentType.Create <CleanupEntity>()); bool cleanupAdded = false; var newTypeCount = 1; for (var t = 1; t < srcArchetype->TypesCount; ++t) { var type = srcArchetype->Types[t]; if (type.IsSystemStateComponent || type.IsSystemStateSharedComponent) { if (!cleanupAdded && (cleanupEntityType < srcArchetype->Types[t])) { types[newTypeCount++] = cleanupEntityType; cleanupAdded = true; } types[newTypeCount++] = srcArchetype->Types[t]; } } if (!cleanupAdded) { types[newTypeCount++] = cleanupEntityType; } var systemStateResidueArchetype = GetOrCreateArchetype(types, newTypeCount, groupManager); systemStateResidueArchetype->SystemStateResidueArchetype = systemStateResidueArchetype; systemStateResidueArchetype->InstantiableArchetype = GetEntityOnlyArchetype(types, groupManager); srcArchetype->SystemStateResidueArchetype = systemStateResidueArchetype; return(srcArchetype); }
public void RemoveComponent <T>(Entity e) { EnforceSingleThreadOwnership(); AddEntityComponentTypeCommand(Command.RemoveComponent, e, ComponentType.Create <T>()); }
internal override ComponentType GetComponentType() { return(ComponentType.Create <T>()); }
public ArchetypeChunkComponentType <T> GetArchetypeChunkComponentType <T>(bool isReadOnly = false) { AddReaderWriter(isReadOnly ? ComponentType.ReadOnly <T>() : ComponentType.Create <T>()); return(EntityManager.GetArchetypeChunkComponentType <T>(isReadOnly)); }