Ejemplo n.º 1
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="chunks"></param>
    /// <param name="sharedComponentIndex"></param>
    /// <param name="componentType"></param>
    internal void AddSharedComponentDataDuringStructuralChange(NativeArray <ArchetypeChunk> chunks, int sharedComponentIndex, ComponentType componentType)
    {
        Assert.IsTrue(componentType.IsSharedComponent);
        EntityComponentStore->AssertCanAddComponent(chunks, componentType);

        StructuralChange.AddSharedComponentChunks(EntityComponentStore, (ArchetypeChunk *)NativeArrayUnsafeUtility.GetUnsafePtr(chunks), chunks.Length, componentType.TypeIndex, sharedComponentIndex);
    }
Ejemplo n.º 2
0
    public bool AddComponent(Entity entity, ComponentType componentType)
    {
        if (HasComponent(entity, componentType))
        {
            return(false);
        }

        EntityComponentStore->AssertCanAddComponent(entity, componentType);

        if (m_IsMainThread)
        {
            EntityManager.BeforeStructuralChange();
        }

        var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

        StructuralChange.AddComponentEntity(EntityComponentStore, &entity, componentType.TypeIndex);

        var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);

        EntityQueryManager.AddAdditionalArchetypes(changedArchetypes);
        ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker);

        return(true);
    }
Ejemplo n.º 3
0
 internal void CreateEntity(EntityArchetype archetype, Entity *outEntities, int count)
 {
     if (m_IsMainThread)
     {
         BeforeStructuralChange();
     }
     StructuralChange.CreateEntity(EntityComponentStore, archetype.Archetype, outEntities, count);
     Assert.IsTrue(EntityComponentStore->ManagedChangesTracker.Empty);
 }
Ejemplo n.º 4
0
 internal void CreateEntity(EntityArchetype archetype, Entity *outEntities, int count)
 {
     if (m_IsMainThread)
     {
         EntityManager.BeforeStructuralChange();
     }
     StructuralChange.CreateEntity(EntityComponentStore, archetype.Archetype, outEntities, count);
     ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker);
 }
Ejemplo n.º 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="entity"></param>
    /// <param name="componentType"></param>
    /// <returns></returns>
    public bool AddComponentDuringStructuralChange(Entity entity, ComponentType componentType)
    {
        if (HasComponent(entity, componentType))
        {
            return(false);
        }

        var result = StructuralChange.AddComponentEntity(EntityComponentStore, &entity, componentType.TypeIndex);

        return(result);
    }
 internal void InstantiateInternal(Entity srcEntity, Entity *outputEntities, int count)
 {
     if (m_IsMainThread)
     {
         BeforeStructuralChange();
     }
     EntityComponentStore->AssertEntitiesExist(&srcEntity, 1);
     EntityComponentStore->AssertCanInstantiateEntities(srcEntity, outputEntities, count);
     StructuralChange.InstantiateEntities(EntityComponentStore, &srcEntity, outputEntities, count);
     PlaybackManagedChanges();
 }
Ejemplo n.º 7
0
    public Entity CreateEntity(EntityArchetype archetype)
    {
        Entity entity;

        if (m_IsMainThread)
        {
            EntityManager.BeforeStructuralChange();
        }
        StructuralChange.CreateEntity(EntityComponentStore, archetype.Archetype, &entity, 1);
        ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker);
        return(entity);
    }
Ejemplo n.º 8
0
    internal void RemoveComponent(NativeArray <ArchetypeChunk> chunks, ComponentType componentType)
    {
        if (m_IsMainThread)
        {
            BeforeStructuralChange();
        }
        var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

        StructuralChange.RemoveComponentChunks(EntityComponentStore, (ArchetypeChunk *)NativeArrayUnsafeUtility.GetUnsafePtr(chunks), chunks.Length, componentType.TypeIndex);

        EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges, EntityQueryManager);
        PlaybackManagedChanges();
    }
Ejemplo n.º 9
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);
        }
    }
Ejemplo n.º 10
0
    public Entity CreateEntity(EntityArchetype archetype)
    {
        Unity.Entities.EntityComponentStore.AssertValidArchetype(EntityComponentStore, archetype);

        Entity entity;

        if (m_IsMainThread)
        {
            BeforeStructuralChange();
        }
        StructuralChange.CreateEntity(EntityComponentStore, archetype.Archetype, &entity, 1);
        Assert.IsTrue(EntityComponentStore->ManagedChangesTracker.Empty);

        return(entity);
    }
Ejemplo n.º 11
0
    internal void AddSharedComponentData(NativeArray <ArchetypeChunk> chunks, int sharedComponentIndex, ComponentType componentType)
    {
        Assert.IsTrue(componentType.IsSharedComponent);
        EntityComponentStore->AssertCanAddComponent(chunks, componentType);

        if (m_IsMainThread)
        {
            BeforeStructuralChange();
        }
        var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

        StructuralChange.AddSharedComponentChunks(EntityComponentStore, (ArchetypeChunk *)NativeArrayUnsafeUtility.GetUnsafePtr(chunks), chunks.Length, componentType.TypeIndex, sharedComponentIndex);

        EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges, EntityQueryManager);
        PlaybackManagedChanges();
    }
Ejemplo n.º 12
0
    public bool RemoveComponent(Entity entity, ComponentType componentType)
    {
        EntityComponentStore->ValidateEntity(entity);
        EntityComponentStore->AssertCanRemoveComponent(entity, componentType);
        if (m_IsMainThread)
        {
            BeforeStructuralChange();
        }

        var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

        var removed = StructuralChange.RemoveComponentEntity(EntityComponentStore, &entity, componentType.TypeIndex);

        EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges, EntityQueryManager);
        PlaybackManagedChanges();

        return(removed);
    }
Ejemplo n.º 13
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);
        }
    }
Ejemplo n.º 14
0
    internal void RemoveComponent(NativeArray <ArchetypeChunk> chunks, ComponentType componentType)
    {
        if (chunks.Length == 0)
        {
            return;
        }

        EntityComponentStore->AssertCanRemoveComponent(chunks, componentType);

        if (m_IsMainThread)
        {
            EntityManager.BeforeStructuralChange();
        }
        var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

        StructuralChange.RemoveComponentChunks(EntityComponentStore, (ArchetypeChunk *)NativeArrayUnsafeUtility.GetUnsafePtr(chunks), chunks.Length, componentType.TypeIndex);

        var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);

        EntityQueryManager.AddAdditionalArchetypes(changedArchetypes);
        ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker);
    }