Beispiel #1
0
    /// <summary>
    /// EntityManager.BeforeStructuralChange must be called before invoking this.
    /// ManagedComponentStore.Playback must be called after invoking this.
    /// ManagedComponentStore.RemoveReference() must be called after Playback for each newSharedComponentDataIndex added
    /// EntityQueryManager.AddAdditionalArchetypes must be called after invoking this.
    /// Invoking this must be wrapped in ArchetypeChangeTracking.
    /// </summary>
    /// <param name="archetypeList"></param>
    /// <param name="filter"></param>
    /// <param name="typeIndex"></param>
    /// <param name="hashCode"></param>
    /// <param name="componentData"></param>
    /// <exception cref="InvalidOperationException"></exception>
    public void AddSharedComponentDataBoxedDefaultMustBeNullDuringStructuralChange(UnsafeMatchingArchetypePtrList archetypeList, EntityQueryFilter filter, int typeIndex, int hashCode, object componentData, UnsafeList *managedReferenceIndexRemovalCount)
    {
        if (!m_IsMainThread)
        {
            throw new InvalidOperationException("Must be called from the main thread");
        }

        ComponentType componentType = ComponentType.FromTypeIndex(typeIndex);

        using (var chunks = ChunkIterationUtility.CreateArchetypeChunkArray(archetypeList, Allocator.TempJob, ref filter, DependencyManager))
        {
            if (chunks.Length == 0)
            {
                return;
            }
            var newSharedComponentDataIndex = 0;
            if (componentData != null) // null means default
            {
                newSharedComponentDataIndex = ManagedComponentStore.InsertSharedComponentAssumeNonDefault(typeIndex, hashCode, componentData);
            }

            AddSharedComponentDataDuringStructuralChange(chunks, newSharedComponentDataIndex, componentType);
            managedReferenceIndexRemovalCount->Add(newSharedComponentDataIndex);
        }
    }
Beispiel #2
0
    public void AddComponent(UnsafeMatchingArchetypePtrList archetypeList, EntityQueryFilter filter,
                             ComponentType componentType)
    {
        if (!m_IsMainThread)
        {
            throw new InvalidOperationException("Must be called from the main thread");
        }

        EntityComponentStore->AssertCanAddComponent(archetypeList, componentType);

        using (var chunks =
                   ChunkIterationUtility.CreateArchetypeChunkArray(archetypeList, Allocator.TempJob, ref filter,
                                                                   DependencyManager))
        {
            if (chunks.Length == 0)
            {
                return;
            }

            EntityComponentStore->AssertCanAddComponent(chunks, componentType);

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

            //@TODO the fast path for a chunk that contains a single entity is only possible if the chunk doesn't have a Locked Entity Order
            //but we should still be allowed to add zero sized components to chunks with a Locked Entity Order, even ones that only contain a single entity

            EntityComponentStore->AddComponentWithValidation(archetypeList, filter, componentType, DependencyManager);

            EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges, EntityQueryManager);
            ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker);
        }
    }
Beispiel #3
0
    /// <summary>
    /// EntityManager.BeforeStructuralChange must be called before invoking this.
    /// ManagedComponentStore.Playback must be called after invoking this.
    /// EntityQueryManager.AddAdditionalArchetypes must be called after invoking this.
    /// Invoking this must be wrapped in ArchetypeChangeTracking.
    /// </summary>
    /// <param name="archetypeList"></param>
    /// <param name="filter"></param>
    /// <exception cref="InvalidOperationException"></exception>
    public void DestroyEntityDuringStructuralChange(UnsafeMatchingArchetypePtrList archetypeList, EntityQueryFilter filter)
    {
        if (!m_IsMainThread)
        {
            throw new InvalidOperationException("Must be called from the main thread");
        }

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

        Profiler.BeginSample("GetAllMatchingChunks");
        using (var chunks = ChunkIterationUtility.CreateArchetypeChunkArray(archetypeList, Allocator.TempJob, ref filter, DependencyManager))
        {
            Profiler.EndSample();

            if (chunks.Length != 0)
            {
                Profiler.BeginSample("EditorOnlyChecks");
                EntityComponentStore->AssertCanDestroy(chunks);
                EntityComponentStore->AssertWillDestroyAllInLinkedEntityGroup(chunks, EntityManager.GetArchetypeChunkBufferType <LinkedEntityGroup>(false));
                Profiler.EndSample();

                // #todo @macton DestroyEntities should support IJobChunk. But internal writes need to be handled.
                Profiler.BeginSample("DeleteChunks");
                new DestroyChunks {
                    EntityComponentStore = EntityComponentStore, Chunks = chunks
                }.Run();
                Profiler.EndSample();
            }
        }

        Profiler.EndSample();
    }
Beispiel #4
0
    public void RemoveComponent(UnsafeMatchingArchetypePtrList archetypeList, EntityQueryFilter filter, ComponentType componentType)
    {
        if (!m_IsMainThread)
        {
            throw new InvalidOperationException("Must be called from the main thread");
        }

        using (var chunks = ChunkIterationUtility.CreateArchetypeChunkArray(archetypeList, Allocator.TempJob, ref filter, EntityManager.DependencyManager))
        {
            RemoveComponent(chunks, componentType);
        }
    }
Beispiel #5
0
    /// <summary>
    /// EntityManager.BeforeStructuralChange must be called before invoking this.
    /// ManagedComponentStore.Playback must be called after invoking this.
    /// EntityQueryManager.AddAdditionalArchetypes must be called after invoking this.
    /// Invoking this must be wrapped in ArchetypeChangeTracking.
    /// </summary>
    /// <param name="archetypeList"></param>
    /// <param name="filter"></param>
    /// <param name="componentType"></param>
    /// <exception cref="InvalidOperationException"></exception>
    public void RemoveComponentDuringStructuralChange(UnsafeMatchingArchetypePtrList archetypeList, EntityQueryFilter filter, ComponentType componentType)
    {
        if (!m_IsMainThread)
        {
            throw new InvalidOperationException("Must be called from the main thread");
        }

        using (var chunks = ChunkIterationUtility.CreateArchetypeChunkArray(archetypeList, Allocator.TempJob,
                                                                            ref filter, DependencyManager))
        {
            StructuralChange.RemoveComponentChunks(EntityComponentStore, (ArchetypeChunk *)NativeArrayUnsafeUtility.GetUnsafePtr(chunks), chunks.Length, componentType.TypeIndex);
        }
    }
Beispiel #6
0
    public void AddComponent(UnsafeMatchingArchetypePtrList archetypeList, EntityQueryFilter filter, ComponentType componentType)
    {
        if (!m_IsMainThread)
        {
            throw new InvalidOperationException("Must be called from the main thread");
        }

        EntityComponentStore->AssertCanAddComponent(archetypeList, componentType);

        using (var chunks = ChunkIterationUtility.CreateArchetypeChunkArray(archetypeList, Allocator.TempJob, ref filter, EntityManager.DependencyManager))
        {
            if (chunks.Length == 0)
            {
                return;
            }

            EntityComponentStore->AssertCanAddComponent(chunks, componentType);

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

            //@TODO the fast path for a chunk that contains a single entity is only possible if the chunk doesn't have a Locked Entity Order
            //but we should still be allowed to add zero sized components to chunks with a Locked Entity Order, even ones that only contain a single entity

            /*
             * if ((chunks.Length == 1) && (chunks[0].Count == 1))
             * {
             *  var entityPtr = (Entity*) chunks[0].m_Chunk->Buffer;
             *  StructuralChange.AddComponentEntity(EntityComponentStore, entityPtr, componentType.TypeIndex);
             * }
             * else
             * {
             */
            StructuralChange.AddComponentChunks(EntityComponentStore, (ArchetypeChunk *)NativeArrayUnsafeUtility.GetUnsafePtr(chunks), chunks.Length, componentType.TypeIndex);

            /*
             * }
             */

            var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);
            EntityQueryManager.AddAdditionalArchetypes(changedArchetypes);
            ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker);
        }
    }