public void RemoveComponents(ArchetypeChunk *chunks, int chunkCount, ComponentTypes componentTypes) { Archetype *prevArchetype = null; Archetype *dstArchetype = null; for (int i = 0; i < chunkCount; i++) { var chunk = chunks[i].m_Chunk; var srcArchetype = chunk->Archetype; if (prevArchetype != chunk->Archetype) { dstArchetype = GetArchetypeWithRemovedComponents(srcArchetype, componentTypes); prevArchetype = chunk->Archetype; } if (dstArchetype == srcArchetype) { continue; } var archetypeChunkFilter = GetArchetypeChunkFilterWithRemovedComponents(chunk, dstArchetype); Move(chunk, ref archetypeChunkFilter); } }
public void AssertCanAddComponents(Entity entity, ComponentTypes types) { for (int i = 0; i < types.Length; ++i) { AssertCanAddComponent(entity, types.GetComponentType(i)); } }
public void AssertCanAddComponents(Archetype *archetype, ComponentTypes componentTypes) { int totalComponentInstanceSize = 0; for (int i = 0; i < componentTypes.Length; i++) { var type = componentTypes.GetComponentType(i); if (type == m_EntityComponentType) { throw new ArgumentException("Cannot add Entity as a component."); } if (type.IsSharedComponent && (archetype->NumSharedComponents == kMaxSharedComponentCount)) { throw new InvalidOperationException($"Cannot add more than {kMaxSharedComponentCount} SharedComponent to a single Archetype"); } var componentTypeInfo = GetTypeInfo(type.TypeIndex); totalComponentInstanceSize += GetComponentArraySize(componentTypeInfo.SizeInChunk, 1); } var archetypeInstanceSize = archetype->InstanceSizeWithOverhead + totalComponentInstanceSize; var chunkDataSize = Chunk.GetChunkBufferSize(); if (archetypeInstanceSize > chunkDataSize) { throw new InvalidOperationException("Entity archetype component data is too large. Previous archetype size per instance {archetype->InstanceSizeWithOverhead} bytes. Attempting to add component size {totalComponentInstanceSize} bytes. Maximum chunk size {chunkDataSize}."); } }
public void AssertCanRemoveComponents(Entity entity, ComponentTypes types) { for (int i = 0; i < types.Length; ++i) { AssertCanRemoveComponent(entity, ComponentType.FromTypeIndex(types.GetTypeIndex(i))); } }
public void RemoveComponents(UnsafeList *sortedEntityBatchList, ref ComponentTypes types) { Assert.IsFalse(types.ChunkComponentCount > 0); // Reverse order so that batch indices do not change while iterating. for (int i = sortedEntityBatchList->Length - 1; i >= 0; i--) { RemoveComponents(((EntityBatchInChunk *)sortedEntityBatchList->Ptr)[i], types); } }
public void AddComponents(Entity entity, ComponentTypes types) { var archetypeChunkFilter = GetArchetypeChunkFilterWithAddedComponents(GetChunk(entity), types); if (archetypeChunkFilter.Archetype == null) { return; } Move(entity, ref archetypeChunkFilter); }
public void AssertCanAddComponents(NativeArray <Entity> entities, ComponentTypes types) { for (int i = 0; i < entities.Length; ++i) { var entity = entities[i]; for (int j = 0; j < types.Length; ++j) { AssertCanAddComponent(entity, types.GetComponentType(j)); } } }
public void RemoveComponents(Entity entity, ComponentTypes types) { var archetypeChunkFilter = GetArchetypeChunkFilterWithRemovedComponents(GetChunk(entity), types); if (archetypeChunkFilter.Archetype == null) // none were removed { return; } Move(entity, ref archetypeChunkFilter); }
/// <summary> /// Adds a set of component to an entity. /// </summary> /// <remarks> /// Adding components changes the entity's archetype and results in the entity being moved to a different /// chunk. /// /// The added components have the default values for the type. /// /// If the <see cref="Entity"/> object refers to an entity that has been destroyed, this function throws an ArgumentError /// exception. /// /// **Important:** This function creates a sync point, which means that the EntityManager waits for all /// currently running Jobs to complete before adding these components and no additional Jobs can start before /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not /// be able to make use of the processing power of all available cores. /// </remarks> /// <param name="entity">The entity to modify.</param> /// <param name="types">The types of components to add.</param> public void AddComponents(Entity entity, ComponentTypes types) { BeforeStructuralChange(); var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking(); EntityComponentStore->AssertCanAddComponents(entity, types); EntityManagerChangeArchetypeUtility.AddComponents(entity, types, EntityComponentStore, ManagedComponentStore); var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges); EntityGroupManager.AddAdditionalArchetypes(changedArchetypes); }
public void RemoveComponent(EntityQuery entityQuery, ComponentTypes types) { if (entityQuery.CalculateLength() == 0) { return; } // @TODO: Opportunity to do all components in batch on a per chunk basis. for (int i = 0; i != types.Length; i++) { RemoveComponent(entityQuery, types.GetComponentType(i)); } }
/// <summary> /// Adds a set of component to an entity. /// </summary> /// <remarks> /// Adding components changes the entity's archetype and results in the entity being moved to a different /// chunk. /// /// The added components have the default values for the type. /// /// If the <see cref="Entity"/> object refers to an entity that has been destroyed, this function throws an ArgumentError /// exception. /// /// **Important:** This function creates a sync point, which means that the EntityManager waits for all /// currently running Jobs to complete before adding these components and no additional Jobs can start before /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not /// be able to make use of the processing power of all available cores. /// </remarks> /// <param name="entity">The entity to modify.</param> /// <param name="types">The types of components to add.</param> public void AddComponents(Entity entity, ComponentTypes types) { BeforeStructuralChange(); var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking(); EntityComponentStore->AssertCanAddComponents(entity, types); EntityComponentStore->AddComponents(entity, types); var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges); EntityQueryManager.AddAdditionalArchetypes(changedArchetypes); ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker); }
public void RemoveComponents(Entity entity, ComponentTypes componentTypes) { var chunk = GetChunk(entity); var newArchetype = GetArchetypeWithRemovedComponents(chunk->Archetype, componentTypes); if (newArchetype == chunk->Archetype) // none were removed { return; } var archetypeChunkFilter = GetArchetypeChunkFilterWithRemovedComponents(chunk, newArchetype); Move(entity, ref archetypeChunkFilter); }
bool AddComponents(EntityBatchInChunk entityBatchInChunk, ComponentTypes componentTypes) { var srcChunk = entityBatchInChunk.Chunk; var dstArchetype = GetArchetypeWithAddedComponents(srcChunk->Archetype, componentTypes); if (dstArchetype == srcChunk->Archetype) // none were added { return(false); } var archetypeChunkFilter = GetArchetypeChunkFilterWithAddedComponents(srcChunk, dstArchetype); if (archetypeChunkFilter.Archetype == null) { return(false); } Move(entityBatchInChunk, ref archetypeChunkFilter); return(true); }
public void RemoveComponents(ArchetypeChunk *chunks, int chunkCount, ComponentTypes types) { Archetype * prevArchetype = null; ArchetypeChunkFilter archetypeChunkFilter = default(ArchetypeChunkFilter); for (int i = 0; i < chunkCount; i++) { var chunk = chunks[i].m_Chunk; var archetype = chunk->Archetype; if (archetype != prevArchetype) { // returns default if no types removed archetypeChunkFilter = GetArchetypeChunkFilterWithRemovedComponents(chunk, types); prevArchetype = archetype; } if (archetypeChunkFilter.Archetype != null) { Move(chunk, ref archetypeChunkFilter); } } }
public void RemoveMultipleComponentsWithValidation(Entity entity, ComponentTypes componentTypes) { ValidateEntity(entity); AssertCanRemoveComponents(componentTypes); RemoveComponents(entity, componentTypes); }
public void AddMultipleComponentsWithValidation(Entity entity, ComponentTypes componentTypes) { AssertCanAddComponents(entity, componentTypes); AddComponents(entity, componentTypes); }
public unsafe void AddComponents(Entity entity, ComponentTypes types) { this.BeforeStructuralChange(); this.Entities.AssertEntitiesExist(&entity, 1); this.Entities.AddComponents(entity, types, this.ArchetypeManager, this.m_SharedComponentManager, this.m_GroupManager, this.m_CachedComponentTypeInArchetypeArray); }
public static void RemoveComponentsEntity(EntityComponentStore *entityComponentStore, Entity *entity, ref ComponentTypes types) { #if !UNITY_IOS if (UseDelegate()) { _forward_mono_RemoveComponentsEntity(entityComponentStore, entity, ref types); return; } #endif _RemoveComponentsEntity(entityComponentStore, entity, ref types); }
private static void _forward_mono_RemoveComponentsChunks(EntityComponentStore *entityComponentStore, ArchetypeChunk *chunks, int chunkCount, ref ComponentTypes types) { _bfp_RemoveComponentsChunks(entityComponentStore, chunks, chunkCount, ref types); }
public static void RemoveComponentsChunks(EntityComponentStore *entityComponentStore, ArchetypeChunk *chunks, int chunkCount, ref ComponentTypes types) { #if !UNITY_IOS if (UseDelegate()) { _forward_mono_RemoveComponentsChunks(entityComponentStore, chunks, chunkCount, ref types); return; } #endif _RemoveComponentsChunks(entityComponentStore, chunks, chunkCount, ref types); }
private static void _forward_mono_RemoveComponentsEntitiesBatch(EntityComponentStore *entityComponentStore, Unity.Collections.LowLevel.Unsafe.UnsafeList *entityBatchList, ref ComponentTypes types) { Managed._bfp_RemoveComponentsEntitiesBatch((IntPtr)entityComponentStore, (IntPtr)entityBatchList, ref types); }
private static void _mono_to_burst_RemoveComponentsEntitiesBatch(IntPtr entityComponentStore, IntPtr entityBatchList, ref ComponentTypes types) { _RemoveComponentsEntitiesBatch((EntityComponentStore *)entityComponentStore, (Unity.Collections.LowLevel.Unsafe.UnsafeList *)entityBatchList, ref types); }
private static void _forward_mono_RemoveComponentsEntity(EntityComponentStore *entityComponentStore, Entity *entity, ref ComponentTypes types) { Managed._bfp_RemoveComponentsEntity((IntPtr)entityComponentStore, (IntPtr)entity, ref types); }
private static void _mono_to_burst_RemoveComponentsEntity(IntPtr entityComponentStore, IntPtr entity, ref ComponentTypes types) { _RemoveComponentsEntity((EntityComponentStore *)entityComponentStore, (Entity *)entity, ref types); }
private static void _mono_to_burst_AddComponentsChunks(EntityComponentStore *entityComponentStore, ArchetypeChunk *chunks, int chunkCount, ref ComponentTypes types) { _AddComponentsChunks(entityComponentStore, chunks, chunkCount, ref types); }
private static void _mono_to_burst_RemoveComponentsChunks(IntPtr entityComponentStore, IntPtr chunks, int chunkCount, ref ComponentTypes types) { _RemoveComponentsChunks((EntityComponentStore *)entityComponentStore, (ArchetypeChunk *)chunks, chunkCount, ref types); }
public static void RemoveComponentsChunks(EntityComponentStore *entityComponentStore, ArchetypeChunk *chunks, int chunkCount, ref ComponentTypes types) { #if !(UNITY_DOTSRUNTIME || (UNITY_2020_1_OR_NEWER && UNITY_IOS)) if (UseDelegate()) { _forward_mono_RemoveComponentsChunks(entityComponentStore, chunks, chunkCount, ref types); return; } #endif _RemoveComponentsChunks(entityComponentStore, chunks, chunkCount, ref types); }
public void AssertCanAddComponents(UnsafeMatchingArchetypePtrList archetypeList, ComponentTypes componentTypes) { int newShared = 0; int totalNewComponentSize = 0; for (int i = 0; i < componentTypes.Length; i++) { var componentType = componentTypes.GetComponentType(i); if (componentType == m_EntityComponentType) { throw new ArgumentException("Cannot add Entity as a component."); } if (componentType.IsSharedComponent) { newShared++; } totalNewComponentSize += GetComponentArraySize(GetTypeInfo(componentType.TypeIndex).SizeInChunk, 1); } for (int i = 0; i < archetypeList.Length; i++) { var archetype = archetypeList.Ptr[i]->Archetype; if ((archetype->NumSharedComponents + newShared) > kMaxSharedComponentCount) { throw new InvalidOperationException($"Cannot add more than {kMaxSharedComponentCount} SharedComponent to a single Archetype"); } if ((archetype->InstanceSizeWithOverhead + totalNewComponentSize) > Chunk.GetChunkBufferSize()) { throw new InvalidOperationException("Entity archetype component data is too large. Previous archetype size per instance {archetype->InstanceSizeWithOverhead} bytes. Attempting to add component size {componentInstanceSize} bytes. Maximum chunk size {chunkDataSize}."); } } }
public static void RemoveComponentsEntitiesBatch(EntityComponentStore *entityComponentStore, Unity.Collections.LowLevel.Unsafe.UnsafeList *entityBatchList, ref ComponentTypes types) { #if !UNITY_IOS if (UseDelegate()) { _forward_mono_RemoveComponentsEntitiesBatch(entityComponentStore, entityBatchList, ref types); return; } #endif _RemoveComponentsEntitiesBatch(entityComponentStore, entityBatchList, ref types); }
private static void _forward_mono_AddComponentsChunks(EntityComponentStore *entityComponentStore, ArchetypeChunk *chunks, int chunkCount, ref ComponentTypes types) { Managed._bfp_AddComponentsChunks((IntPtr)entityComponentStore, (IntPtr)chunks, chunkCount, ref types); }