Ejemplo n.º 1
0
        /// <summary>
        /// Adds a component to each of the chunks identified by a EntityQuery and set the component values.
        /// </summary>
        /// <remarks>
        /// This function finds all chunks whose archetype satisfies the EntityQuery and adds the specified
        /// component to them.
        ///
        /// A chunk component is common to all entities in a chunk. You can access a chunk <see cref="IComponentData"/>
        /// instance through either the chunk itself or through an entity stored in that chunk.
        ///
        /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
        /// currently running Jobs to complete before adding the component 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="entityQuery">The EntityQuery identifying the chunks to modify.</param>
        /// <param name="componentData">The data to set.</param>
        /// <typeparam name="T">The type of component, which must implement IComponentData.</typeparam>
        public void AddChunkComponentData <T>(EntityQuery entityQuery, T componentData) where T : struct, IComponentData
        {
            using (var chunks = entityQuery.CreateArchetypeChunkArray(Allocator.TempJob))
            {
                if (chunks.Length == 0)
                {
                    return;
                }
                BeforeStructuralChange();
                var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

                EntityComponentStore->AssertCanAddChunkComponent(chunks, ComponentType.ChunkComponent <T>());

                var type      = ComponentType.ReadWrite <T>();
                var chunkType = ComponentType.FromTypeIndex(TypeManager.MakeChunkComponentTypeIndex(type.TypeIndex));

                using (var entityBatchList = m_EntityComponentStore->CreateEntityBatchList(chunks))
                {
                    EntityManagerChangeArchetypeUtility.AddComponentFromMainThread(entityBatchList, chunkType, 0,
                                                                                   EntityComponentStore, ManagedComponentStore);
                    m_EntityComponentStore->SetChunkComponent <T>(entityBatchList, componentData);
                }

                var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);
                EntityGroupManager.AddAdditionalArchetypes(changedArchetypes);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Removes a component from the chunks identified by a EntityQuery.
 /// </summary>
 /// <remarks>
 /// A chunk component is common to all entities in a chunk. You can access a chunk <see cref="IComponentData"/>
 /// instance through either the chunk itself or through an entity stored in that chunk.
 ///
 /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
 /// currently running Jobs to complete before removing the component 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="entityQuery">The EntityQuery identifying the chunks to modify.</param>
 /// <typeparam name="T">The type of component to remove.</typeparam>
 public void RemoveChunkComponentData <T>(EntityQuery entityQuery)
 {
     using (var chunks = entityQuery.CreateArchetypeChunkArray(Allocator.TempJob))
     {
         if (chunks.Length == 0)
         {
             return;
         }
         BeforeStructuralChange();
         EntityManagerChangeArchetypeUtility.RemoveComponent(chunks, ComponentType.ChunkComponent <T>(),
                                                             EntityComponentStore, ManagedComponentStore, EntityGroupManager);
     }
 }
Ejemplo n.º 3
0
            public void Execute(int index)
            {
                var           typeHash  = TypeHashes[index];
                var           typeIndex = TypeManager.GetTypeIndexFromStableTypeHash(typeHash.StableTypeHash);
                var           type      = TypeManager.GetType(typeIndex);
                ComponentType componentType;

                if ((typeHash.Flags & ComponentTypeFlags.ChunkComponent) == ComponentTypeFlags.ChunkComponent)
                {
                    componentType = ComponentType.ChunkComponent(type);
                }
                else
                {
                    componentType = new ComponentType(type);
                }
                PackedTypes[index] = componentType;
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes a component from the chunks identified by a EntityQuery.
        /// </summary>
        /// <remarks>
        /// A chunk component is common to all entities in a chunk. You can access a chunk <see cref="IComponentData"/>
        /// instance through either the chunk itself or through an entity stored in that chunk.
        ///
        /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
        /// currently running Jobs to complete before removing the component 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="entityQuery">The EntityQuery identifying the chunks to modify.</param>
        /// <typeparam name="T">The type of component to remove.</typeparam>
        public void RemoveChunkComponentData <T>(EntityQuery entityQuery)
        {
            using (var chunks = entityQuery.CreateArchetypeChunkArray(Allocator.TempJob))
            {
                if (chunks.Length == 0)
                {
                    return;
                }
                BeforeStructuralChange();
                var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

                EntityManagerChangeArchetypeUtility.RemoveComponent(chunks, ComponentType.ChunkComponent <T>(),
                                                                    EntityComponentStore, ManagedComponentStore);

                var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);
                EntityGroupManager.AddAdditionalArchetypes(changedArchetypes);
            }
        }
Ejemplo n.º 5
0
 public bool HasChunkComponent <T>(Entity entity)
 {
     return(GetCheckedEntityDataAccess()->HasComponent(entity, ComponentType.ChunkComponent <T>()));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds a chunk component to the specified entity.
 /// </summary>
 /// <remarks>
 /// Adding a chunk component to an entity changes that entity's archetype and results in the entity being moved
 /// to a different chunk, either one that already has an archetype containing the chunk component or a new
 /// chunk.
 ///
 /// A chunk component is common to all entities in a chunk. You can access a chunk <see cref="IComponentData"/>
 /// instance through either the chunk itself or through an entity stored in that chunk. In either case, getting
 /// or setting the component reads or writes the same data.
 ///
 /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
 /// currently running Jobs to complete before adding the component 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="entity">The entity.</param>
 /// <typeparam name="T">The type of component, which must implement IComponentData.</typeparam>
 public void AddChunkComponentData <T>(Entity entity) where T : struct, IComponentData
 {
     AddComponent(entity, ComponentType.ChunkComponent <T>());
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Removes a chunk component from the specified entity.
 /// </summary>
 /// <remarks>
 /// A chunk component is common to all entities in a chunk. Removing the chunk component from an entity changes
 /// that entity's archetype and results in the entity being moved to a different chunk (that does not have the
 /// removed component).
 ///
 /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
 /// currently running Jobs to complete before removing the component 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="entity">The entity.</param>
 /// <typeparam name="T">The type of component to remove.</typeparam>
 public void RemoveChunkComponent <T>(Entity entity)
 {
     RemoveComponent(entity, ComponentType.ChunkComponent <T>());
 }
 /// <summary>
 /// Removes a component from the chunks identified by a EntityQuery.
 /// </summary>
 /// <remarks>
 /// A chunk component is common to all entities in a chunk. You can access a chunk <see cref="IComponentData"/>
 /// instance through either the chunk itself or through an entity stored in that chunk.
 ///
 /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
 /// currently running Jobs to complete before removing the component 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="entityQuery">The EntityQuery identifying the chunks to modify.</param>
 /// <typeparam name="T">The type of component to remove.</typeparam>
 public void RemoveChunkComponentData <T>(EntityQuery entityQuery)
 {
     RemoveComponent(entityQuery, ComponentType.ChunkComponent <T>());
 }