コード例 #1
0
        // ----------------------------------------------------------------------------------------------------------
        // 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...
        }
コード例 #2
0
        public void MoveEntitiesFromInternalAll(EntityManager srcEntities, NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping)
        {
            var srcAccess  = srcEntities.GetCheckedEntityDataAccess();
            var selfAccess = GetCheckedEntityDataAccess();

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (srcEntities.m_EntityDataAccess == m_EntityDataAccess)
            {
                throw new ArgumentException("srcEntities must not be the same as this EntityManager.");
            }

            if (entityRemapping.Length < srcAccess->EntityComponentStore->EntitiesCapacity)
            {
                throw new ArgumentException("entityRemapping.Length isn't large enough, use srcEntities.CreateEntityRemapArray");
            }

            if (!srcAccess->ManagedComponentStore.AllSharedComponentReferencesAreFromChunks(srcAccess->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 = selfAccess->EntityComponentStore->BeginArchetypeChangeTracking();

            MoveChunksFromAll(entityRemapping, srcAccess->EntityComponentStore, srcAccess->ManagedComponentStore);

            selfAccess->EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges, selfAccess->EntityQueryManager);
        }
コード例 #3
0
        void MoveEntitiesFrom(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.");
            }

            if (entityRemapping.Length < srcEntities.m_EntityComponentStore->EntitiesCapacity)
            {
                throw new ArgumentException(
                          "entityRemapping.Length isn't large enough, use srcEntities.CreateEntityRemapArray");
            }

            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();

            MoveChunksFrom(chunks, entityRemapping, srcEntities.EntityComponentStore,
                           srcEntities.ManagedComponentStore);

            var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);
            EntityQueryManager.AddAdditionalArchetypes(changedArchetypes);
        }
コード例 #4
0
        // ----------------------------------------------------------------------------------------------------------
        // 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);
        }
コード例 #5
0
        // @TODO Proper description of remap utility.
        /// <summary>
        /// Moves all entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager.
        /// </summary>
        /// <remarks>
        /// After the move, the entities are managed by this EntityManager.
        ///
        /// 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="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">Thrown if you attempt to transfer entities to the EntityManager
        /// that already owns them.</exception>
        public void MoveEntitiesFrom(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 (entityRemapping.Length < srcEntities.m_EntityComponentStore->EntitiesCapacity)
            {
                throw new ArgumentException(
                          "entityRemapping.Length isn't large enough, use srcEntities.CreateEntityRemapArray");
            }

            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();

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

            //@TODO: Need to increment the component versions based the moved chunks...
        }
コード例 #6
0
 internal unsafe void MoveEntitiesFrom(EntityManager srcEntities, NativeArray <ArchetypeChunk> chunks, NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping)
 {
     if (srcEntities == this)
     {
         throw new ArgumentException("srcEntities must not be the same as this EntityManager.");
     }
     this.BeforeStructuralChange();
     srcEntities.BeforeStructuralChange();
     Unity.Entities.ArchetypeManager.MoveChunks(srcEntities, chunks, this.ArchetypeManager, this.m_GroupManager, this.Entities, this.m_SharedComponentManager, this.m_CachedComponentTypeInArchetypeArray, entityRemapping);
 }
コード例 #7
0
 public unsafe void MoveEntitiesFrom(EntityManager srcEntities, NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping)
 {
     if (srcEntities == this)
     {
         throw new ArgumentException("srcEntities must not be the same as this EntityManager.");
     }
     if (!srcEntities.m_SharedComponentManager.AllSharedComponentReferencesAreFromChunks(srcEntities.ArchetypeManager))
     {
         throw new ArgumentException("EntityManager.MoveEntitiesFrom failed - All ISharedComponentData references must be from EntityManager. (For example ComponentGroup.SetFilter with a shared component type is not allowed during EntityManager.MoveEntitiesFrom)");
     }
     this.BeforeStructuralChange();
     srcEntities.BeforeStructuralChange();
     Unity.Entities.ArchetypeManager.MoveChunks(srcEntities, this.ArchetypeManager, this.m_GroupManager, this.Entities, this.m_SharedComponentManager, this.m_CachedComponentTypeInArchetypeArray, entityRemapping);
 }
コード例 #8
0
ファイル: EntityManager.cs プロジェクト: Zauras/QPH_curve
        internal void MoveEntitiesFrom(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.");
            }
#endif

            BeforeStructuralChange();
            srcEntities.BeforeStructuralChange();

            ArchetypeManager.MoveChunks(srcEntities, chunks, ArchetypeManager, m_GroupManager, Entities, m_SharedComponentManager, m_CachedComponentTypeInArchetypeArray, entityRemapping);
        }
コード例 #9
0
        public void MoveEntitiesFrom(EntityManager srcEntities)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (srcEntities == this)
            {
                throw new ArgumentException("srcEntities must not be the same as this EntityManager.");
            }
#endif

            BeforeStructuralChange();
            srcEntities.BeforeStructuralChange();

            ArchetypeManager.MoveChunks(srcEntities.m_ArchetypeManager, srcEntities.m_Entities, srcEntities.m_SharedComponentManager, m_ArchetypeManager, m_GroupManager, m_SharedComponentManager, m_Entities, m_SharedComponentManager);

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

        void MoveEntitiesFromInternalQuery(EntityManager srcEntities, EntityQuery filter, NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping)
        {
            var srcAccess  = srcEntities.GetCheckedEntityDataAccess();
            var selfAccess = GetCheckedEntityDataAccess();

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (filter._GetImpl()->_Access != srcAccess)
            {
                throw new ArgumentException(
                          "EntityManager.MoveEntitiesFrom failed - srcEntities and filter must belong to the same World)");
            }

            if (srcEntities.m_EntityDataAccess == m_EntityDataAccess)
            {
                throw new ArgumentException("srcEntities must not be the same as this EntityManager.");
            }
#endif
            BeforeStructuralChange();
            srcEntities.BeforeStructuralChange();

            using (var chunks = filter.CreateArchetypeChunkArray(Allocator.TempJob))
            {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                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

                var archetypeChanges = selfAccess->EntityComponentStore->BeginArchetypeChangeTracking();

                MoveChunksFromFiltered(chunks, entityRemapping, srcAccess->EntityComponentStore, srcAccess->ManagedComponentStore);

                selfAccess->EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges, selfAccess->EntityQueryManager);
                selfAccess->EntityComponentStore->InvalidateChunkListCacheForChangedArchetypes();
                srcAccess->EntityComponentStore->InvalidateChunkListCacheForChangedArchetypes();
            }
        }
コード例 #11
0
ファイル: EntityManager.cs プロジェクト: kushinn/RayTracing
        public void MoveEntitiesFrom(EntityManager srcEntities)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (srcEntities == this)
            {
                throw new ArgumentException("srcEntities must not be the same as this EntityManager.");
            }

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

            BeforeStructuralChange();
            srcEntities.BeforeStructuralChange();

            ArchetypeManager.MoveChunks(srcEntities, ArchetypeManager, m_GroupManager, Entities, m_SharedComponentManager, m_CachedComponentTypeInArchetypeArray);

            //@TODO: Need to incrmeent the component versions based the moved chunks...
        }