// ----------------------------------------------------------------------------------------------------------
        // PUBLIC
        // ----------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Moves all entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager and fills
        /// an array with their <see cref="Entity"/> objects.
        /// </summary>
        /// <remarks>
        /// After the move, the entities are managed by this EntityManager. Use the `output` array to make post-move
        /// changes to the transferred entities.
        ///
        /// Each world has one EntityManager, which manages all the entities in that world. This function
        /// allows you to transfer entities from one World to another.
        ///
        /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
        /// currently running Jobs to complete before moving the entities 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="output">An array to receive the Entity objects of the transferred entities.</param>
        /// <param name="srcEntities">The EntityManager whose entities are appropriated.</param>
        /// <param name="entityRemapping">A set of entity transformations to make during the transfer.</param>
        /// <exception cref="ArgumentException"></exception>
        public void MoveEntitiesFrom(out NativeArray <Entity> output, EntityManager srcEntities,
                                     NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (srcEntities == this)
            {
                throw new ArgumentException("srcEntities must not be the same as this EntityManager.");
            }

            if (!srcEntities.m_ManagedComponentStore.AllSharedComponentReferencesAreFromChunks(srcEntities
                                                                                               .EntityComponentStore))
            {
                throw new ArgumentException(
                          "EntityManager.MoveEntitiesFrom failed - All ISharedComponentData references must be from EntityManager. (For example EntityQuery.SetFilter with a shared component type is not allowed during EntityManager.MoveEntitiesFrom)");
            }
#endif

            BeforeStructuralChange();
            srcEntities.BeforeStructuralChange();
            var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

            EntityManagerMoveEntitiesUtility.MoveChunks(entityRemapping,
                                                        srcEntities.EntityComponentStore, srcEntities.ManagedComponentStore,
                                                        EntityComponentStore, ManagedComponentStore);

            EntityRemapUtility.GetTargets(out output, entityRemapping);

            var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);
            EntityGroupManager.AddAdditionalArchetypes(changedArchetypes);

            //@TODO: Need to increment the component versions based the moved chunks...
        }
        // ----------------------------------------------------------------------------------------------------------
        // INTERNAL
        // ----------------------------------------------------------------------------------------------------------

        void MoveEntitiesFrom(out NativeArray <Entity> output, EntityManager srcEntities,
                              NativeArray <ArchetypeChunk> chunks, NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (srcEntities == this)
            {
                throw new ArgumentException("srcEntities must not be the same as this EntityManager.");
            }
            for (int i = 0; i < chunks.Length; ++i)
            {
                if (chunks[i].m_Chunk->Archetype->HasChunkHeader)
                {
                    throw new ArgumentException(
                              "MoveEntitiesFrom can not move chunks that contain ChunkHeader components.");
                }
            }
#endif

            BeforeStructuralChange();
            srcEntities.BeforeStructuralChange();
            var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

            EntityManagerMoveEntitiesUtility.MoveChunks(chunks, entityRemapping,
                                                        srcEntities.EntityComponentStore, srcEntities.ManagedComponentStore,
                                                        EntityComponentStore, ManagedComponentStore);

            var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);
            EntityGroupManager.AddAdditionalArchetypes(changedArchetypes);

            EntityRemapUtility.GetTargets(out output, entityRemapping);
        }
Пример #3
0
 /// <summary>
 /// Moves all entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager and fills
 /// an array with their Entity objects.
 /// </summary>
 /// <remarks>
 /// After the move, the entities are managed by this EntityManager. Use the `output` array to make post-move
 /// changes to the transferred entities.
 ///
 /// Each world has one EntityManager, which manages all the entities in that world. This function
 /// allows you to transfer entities from one World to another.
 ///
 /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
 /// currently running Jobs to complete before moving the entities 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="output">An array to receive the Entity objects of the transferred entities.</param>
 /// <param name="srcEntities">The EntityManager whose entities are appropriated.</param>
 public void MoveEntitiesFrom(out NativeArray <Entity> output, EntityManager srcEntities)
 {
     using (var entityRemapping = srcEntities.CreateEntityRemapArray(Allocator.TempJob))
     {
         MoveEntitiesFromInternalAll(srcEntities, entityRemapping);
         EntityRemapUtility.GetTargets(out output, entityRemapping);
     }
 }
Пример #4
0
 /// <summary>
 /// Moves all entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager and fills
 /// an array with their <see cref="Entity"/> objects.
 /// </summary>
 /// <remarks>
 /// After the move, the entities are managed by this EntityManager. Use the `output` array to make post-move
 /// changes to the transferred entities.
 ///
 /// Each world has one EntityManager, which manages all the entities in that world. This function
 /// allows you to transfer entities from one World to another.
 ///
 /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
 /// currently running Jobs to complete before moving the entities 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="output">An array to receive the Entity objects of the transferred entities.</param>
 /// <param name="srcEntities">The EntityManager whose entities are appropriated.</param>
 /// <param name="entityRemapping">A set of entity transformations to make during the transfer.</param>
 /// <exception cref="ArgumentException"></exception>
 public void MoveEntitiesFrom(out NativeArray <Entity> output, EntityManager srcEntities, NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping)
 {
     MoveEntitiesFromInternalAll(srcEntities, entityRemapping);
     EntityRemapUtility.GetTargets(out output, entityRemapping);
 }