/// <summary> /// Copies all entities from srcEntityManager and replaces all entities in this EntityManager /// </summary> /// <remarks> /// Guarantees that the chunk layout & order of the entities will match exactly, thus this method can be used for deterministic rollback. /// This feature is not complete and only supports a subset of the EntityManager features at the moment: /// * Currently it copies all SystemStateComponents (They should not be copied) /// * Currently does not support class based components /// </remarks> public void CopyAndReplaceEntitiesFrom(EntityManager srcEntityManager) { srcEntityManager.CompleteAllJobs(); CompleteAllJobs(); var srcAccess = srcEntityManager.GetCheckedEntityDataAccess(); var selfAccess = GetCheckedEntityDataAccess(); using (var srcChunks = srcAccess->ManagedEntityDataAccess.m_UniversalQueryWithChunks.CreateArchetypeChunkArrayAsync(Allocator.TempJob, out var srcChunksJob)) using (var dstChunks = selfAccess->ManagedEntityDataAccess.m_UniversalQueryWithChunks.CreateArchetypeChunkArrayAsync(Allocator.TempJob, out var dstChunksJob)) { using (var archetypeChunkChanges = EntityDiffer.GetArchetypeChunkChanges( srcChunks, dstChunks, Allocator.TempJob, jobHandle: out var archetypeChunkChangesJob, dependsOn: JobHandle.CombineDependencies(srcChunksJob, dstChunksJob))) { archetypeChunkChangesJob.Complete(); EntityDiffer.CopyAndReplaceChunks(srcEntityManager, this, selfAccess->ManagedEntityDataAccess.m_UniversalQueryWithChunks, archetypeChunkChanges); Unity.Entities.EntityComponentStore.AssertSameEntities(srcAccess->EntityComponentStore, selfAccess->EntityComponentStore); } } }
/// <summary> /// Copies all entities from srcEntityManager and replaces all entities in this EntityManager /// </summary> /// <remarks> /// Guarantees that the chunk layout & order of the entities will match exactly, thus this method can be used for deterministic rollback. /// This feature is not complete and only supports a subset of the EntityManager features at the moment: /// * Currently it copies all SystemStateComponents (They should not be copied) /// * Currently does not support class based components /// </remarks> public void CopyAndReplaceEntitiesFrom(EntityManager srcEntityManager) { #if ENABLE_UNITY_COLLECTIONS_CHECKS if (srcEntityManager == null || !srcEntityManager.IsCreated) { throw new ArgumentNullException(nameof(srcEntityManager)); } if (!IsCreated) { throw new ArgumentException("This EntityManager has been destroyed"); } #endif srcEntityManager.CompleteAllJobs(); CompleteAllJobs(); using (var srcChunks = srcEntityManager.m_UniversalQueryWithChunks.CreateArchetypeChunkArray(Allocator.TempJob, out var srcChunksJob)) using (var dstChunks = m_UniversalQueryWithChunks.CreateArchetypeChunkArray(Allocator.TempJob, out var dstChunksJob)) { using (var archetypeChunkChanges = EntityDiffer.GetArchetypeChunkChanges( srcChunks, dstChunks, Allocator.TempJob, jobHandle: out var archetypeChunkChangesJob, dependsOn: JobHandle.CombineDependencies(srcChunksJob, dstChunksJob))) { archetypeChunkChangesJob.Complete(); EntityDiffer.CopyAndReplaceChunks(srcEntityManager, this, m_UniversalQueryWithChunks, archetypeChunkChanges); Unity.Entities.EntityComponentStore.AssertSameEntities(srcEntityManager.EntityComponentStore, EntityComponentStore); } } }
public void ReleaseUnusedBlobAssets() { using (var chunks = EntityManager.CreateEntityQuery(EntityGuidQueryDesc).CreateArchetypeChunkArray(Allocator.TempJob)) using (var blobAssets = EntityDiffer.GetBlobAssetsWithDistinctHash(EntityManager.GetCheckedEntityDataAccess()->ManagedComponentStore, chunks, Allocator.TempJob)) { m_BlobAssetBatchPtr->RemoveUnusedBlobAssets(blobAssets.BlobAssetsMap); } }
/// <summary> /// Generates a detailed change set for the world. /// All entities to be considered for diffing must have the <see cref="EntityGuid"/> component with a unique value. /// </summary> /// <remarks> /// The resulting <see cref="EntityChanges"/> must be disposed when no longer needed. /// </remarks> /// <param name="options">A set of options which can be toggled.</param> /// <param name="allocator">The allocator to use for the results object.</param> /// <returns>A set of changes for the world since the last fast-forward.</returns> public EntityChanges GetChanges(EntityManagerDifferOptions options, Allocator allocator) { var changes = EntityDiffer.GetChanges( srcEntityManager: m_SourceEntityManager, dstEntityManager: m_ShadowEntityManager, options, m_EntityQueryDesc, m_BlobAssetCache, allocator); return(changes); }
/// <summary> /// Generates a detailed change set for the world. /// All entities to be considered for diffing must have the <see cref="EntityGuid"/> component with a unique value. /// </summary> /// <remarks> /// The resulting <see cref="EntityChanges"/> must be disposed when no longer needed. /// </remarks> /// <param name="options">A set of options which can be toggled.</param> /// <param name="allocator">The allocator to use for the results object.</param> /// <returns>A set of changes for the world since the last fast-forward.</returns> public EntityChanges GetChanges(EntityManagerDifferOptions options, Allocator allocator) { #if ENABLE_UNITY_COLLECTIONS_CHECKS if (null == m_SourceEntityManager || null == m_ShadowEntityManager) { throw new ArgumentException($"The {nameof(EntityManagerDiffer)} has already been Disposed."); } #endif var changes = EntityDiffer.GetChanges( srcEntityManager: m_SourceEntityManager, dstEntityManager: m_ShadowEntityManager, options, m_EntityQueryDesc, m_BlobAssetCache, allocator); return(changes); }