internal void DestroyEntity(MatchingArchetypeList archetypeList, EntityQueryFilter filter)
        {
            Profiler.BeginSample("DestroyEntity(EntityQuery entityQueryFilter)");

            Profiler.BeginSample("GetAllMatchingChunks");
            var jobHandle = new JobHandle();

            using (var chunks = ComponentChunkIterator.CreateArchetypeChunkArray(archetypeList, Allocator.TempJob, out jobHandle, ref filter))
            {
                jobHandle.Complete();
                Profiler.EndSample();

                if (chunks.Length != 0)
                {
                    BeforeStructuralChange();

                    Profiler.BeginSample("EditorOnlyChecks");
                    EntityComponentStore->AssertCanDestroy(chunks);
                    EntityComponentStore->AssertWillDestroyAllInLinkedEntityGroup(chunks, GetArchetypeChunkBufferType <LinkedEntityGroup>(false));
                    Profiler.EndSample();

                    Profiler.BeginSample("DeleteChunks");
                    EntityManagerCreateDestroyEntitiesUtility.DestroyEntities(chunks, EntityComponentStore, ManagedComponentStore);
                    Profiler.EndSample();
                }
            }

            Profiler.EndSample();
        }
        /// <summary>
        /// Destroy all entities having a common set of component types.
        /// </summary>
        /// <remarks>Since entities in the same chunk share the same component structure, this function effectively destroys
        /// the chunks holding any entities identified by the `entityQueryFilter` parameter.</remarks>
        /// <param name="entityQueryFilter">Defines the components an entity must have to qualify for destruction.</param>
        public void DestroyEntity(EntityQuery entityQueryFilter)
        {
            //@TODO: When destroying entities with entityQueryFilter we assume that any LinkedEntityGroup also get destroyed
            //       We should have some sort of validation that everything is included, and either give an error message or have a fast enough path to handle it...

            //@TODO: Locked checks...

            Profiler.BeginSample("DestroyEntity(EntityQuery entityQueryFilter)");

            Profiler.BeginSample("GetAllMatchingChunks");
            using (var chunks = entityQueryFilter.CreateArchetypeChunkArray(Allocator.TempJob))
            {
                Profiler.EndSample();

                Profiler.BeginSample("EditorOnlyChecks");
                EntityComponentStore->AssertCanDestroy(chunks);
                Profiler.EndSample();

                Profiler.BeginSample("DeleteChunks");
                EntityManagerCreateDestroyEntitiesUtility.DestroyEntities(chunks, EntityComponentStore, ManagedComponentStore, EntityGroupManager);
                Profiler.EndSample();
            }

            Profiler.EndSample();
        }
Пример #3
0
        public static void MoveChunks(
            NativeArray <ArchetypeChunk> chunks,
            NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping,
            EntityComponentStore *srcEntityComponentStore,
            ManagedComponentStore srcManagedComponentStore,
            EntityComponentStore *dstEntityComponentStore,
            ManagedComponentStore dstManagedComponentStore)
        {
            new MoveChunksJob
            {
                srcEntityComponentStore = srcEntityComponentStore,
                dstEntityComponentStore = dstEntityComponentStore,
                entityRemapping         = entityRemapping,
                chunks = chunks
            }.Run();

            int chunkCount  = chunks.Length;
            var remapChunks = new NativeArray <RemapChunk>(chunkCount, Allocator.TempJob);

            for (int i = 0; i < chunkCount; ++i)
            {
                var chunk     = chunks[i].m_Chunk;
                var archetype = chunk->Archetype;

                //TODO: this should not be done more than once for each archetype
                var dstArchetype =
                    EntityManagerCreateArchetypeUtility.GetOrCreateArchetype(archetype->Types, archetype->TypesCount,
                                                                             dstEntityComponentStore);

                remapChunks[i] = new RemapChunk {
                    chunk = chunk, dstArchetype = dstArchetype
                };
                chunk->SequenceNumber = dstEntityComponentStore->AssignSequenceNumber(chunk);

                if (archetype->MetaChunkArchetype != null)
                {
                    Entity srcEntity = chunk->metaChunkEntity;
                    Entity dstEntity;

                    EntityManagerCreateDestroyEntitiesUtility.CreateEntities(dstArchetype->MetaChunkArchetype,
                                                                             &dstEntity, 1,
                                                                             dstEntityComponentStore, dstManagedComponentStore);

                    srcEntityComponentStore->GetChunk(srcEntity, out var srcChunk, out var srcIndex);
                    dstEntityComponentStore->GetChunk(dstEntity, out var dstChunk, out var dstIndex);

                    ChunkDataUtility.SwapComponents(srcChunk, srcIndex, dstChunk, dstIndex, 1,
                                                    srcEntityComponentStore->GlobalSystemVersion, dstEntityComponentStore->GlobalSystemVersion);
                    EntityRemapUtility.AddEntityRemapping(ref entityRemapping, srcEntity, dstEntity);

                    EntityManagerCreateDestroyEntitiesUtility.DestroyEntities(&srcEntity, 1,
                                                                              srcEntityComponentStore, srcManagedComponentStore);
                }
            }

            k_ProfileMoveSharedComponents.Begin();
            var remapShared =
                dstManagedComponentStore.MoveSharedComponents(srcManagedComponentStore, chunks,
                                                              entityRemapping,
                                                              Allocator.TempJob);

            k_ProfileMoveSharedComponents.End();

            var remapChunksJob = new RemapChunksJob
            {
                dstEntityComponentStore = dstEntityComponentStore,
                remapChunks             = remapChunks,
                entityRemapping         = entityRemapping
            }.Schedule(remapChunks.Length, 1);

            var moveChunksBetweenArchetypeJob = new MoveChunksBetweenArchetypeJob
            {
                remapChunks         = remapChunks,
                remapShared         = remapShared,
                globalSystemVersion = dstEntityComponentStore->GlobalSystemVersion
            }.Schedule(remapChunksJob);

            moveChunksBetweenArchetypeJob.Complete();

            remapShared.Dispose();
            remapChunks.Dispose();
        }
Пример #4
0
 private void DestroyEntityInternal(Entity *entities, int count)
 {
     CheckAccess();
     m_EntityComponentStore->AssertCanDestroy(entities, count);
     EntityManagerCreateDestroyEntitiesUtility.DestroyEntities(entities, count, EntityComponentStore, ManagedComponentStore);
 }
        // ----------------------------------------------------------------------------------------------------------
        // INTERNAL
        // ----------------------------------------------------------------------------------------------------------

        internal void DestroyEntityInternal(Entity *entities, int count)
        {
            BeforeStructuralChange();
            EntityComponentStore->AssertCanDestroy(entities, count);
            EntityManagerCreateDestroyEntitiesUtility.DestroyEntities(entities, count, EntityComponentStore, ManagedComponentStore);
        }