コード例 #1
0
        /// <summary>
        /// Schedules an attribute job
        /// </summary>
        /// <param name="inputDependencies">JobHandle</param>
        /// <param name="query">The EntityQuery used for filtering group</param>
        /// <param name="AttributeHash">Attribute MultiHashMap mapping entity to attribute value</param>
        /// <param name="job">Returned job handle</param>
        /// <typeparam name="TOper">The type of operator for this attribute job</typeparam>
        private void ScheduleAttributeJob <TOper>(ref JobHandle inputDependencies, ref EntityQuery query, ref NativeMultiHashMap <Entity, float> AttributeHash, out JobHandle job)
            where TOper : struct, IAttributeOperator, IComponentData
        {
            var nEntities    = query.CalculateEntityCount();
            var hashCapacity = AttributeHash.Capacity;

            AttributeHash.Clear();
            if (nEntities == 0)
            {
                job = inputDependencies;
                return;
            }
            ;
            if (hashCapacity < nEntities)   // We need to increase hash capacity
            {
                AttributeHash.Capacity = (int)(nEntities * 1.1);
            }
            else if (hashCapacity > nEntities * 4)     // We need to reduce hash capacity
            {
                AttributeHash.Dispose();
                AttributeHash = new NativeMultiHashMap <Entity, float>(nEntities, Allocator.Persistent);
            }
            // // AttributeHash = new NativeMultiHashMap<Entity, float>(query.CalculateEntityCount(), Allocator.TempJob);
            inputDependencies = new GetAttributeValuesJob_Sum <TOper, TAttributeTag>
            {
                owners                  = GetArchetypeChunkComponentType <AttributesOwnerComponent>(false),
                attributeModifiers      = GetArchetypeChunkComponentType <AttributeModifier <TOper, TAttributeTag> >(false),
                AttributeModifierValues = AttributeHash.AsParallelWriter()
            }.Schedule(query, inputDependencies);
            job = inputDependencies;
        }
コード例 #2
0
 /// <summary>
 /// Schedules an attribute job
 /// </summary>
 /// <param name="inputDependencies">JobHandle</param>
 /// <param name="query">The EntityQuery used for filtering group</param>
 /// <param name="AttributeHash">Attribute MultiHashMap mapping entity to attribute value</param>
 /// <param name="job">Returned job handle</param>
 /// <typeparam name="TOper">The type of operator for this attribute job</typeparam>
 private void ScheduleAttributeJob <TOper>(JobHandle inputDependencies, EntityQuery query, out NativeMultiHashMap <Entity, float> AttributeHash, out JobHandle job)
     where TOper : struct, IAttributeOperator, IComponentData
 {
     AttributeHash = new NativeMultiHashMap <Entity, float>(query.CalculateEntityCount(), Allocator.TempJob);
     job           = new GetAttributeValuesJob_Sum <TOper, TAttributeTag>
     {
         AttributeModifierValues = AttributeHash.AsParallelWriter()
     }.Schedule(query, inputDependencies);
 }