Пример #1
0
            public static unsafe void Execute(ref NativeMultiHashMapVisitKeyValueJobStruct <TJob, TKey, TValue> fullData, IntPtr additionalPtr, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex)
            {
                while (true)
                {
                    int begin;
                    int end;

                    if (!JobsUtility.GetWorkStealingRange(ref ranges, jobIndex, out begin, out end))
                    {
                        return;
                    }

                    UnsafeHashMapData *hashMapData = fullData.HashMap.m_MultiHashMapData.m_Buffer;
                    var buckets  = (int *)hashMapData->buckets;
                    var nextPtrs = (int *)hashMapData->next;
                    var keys     = hashMapData->keys;
                    var values   = hashMapData->values;

                    for (int i = begin; i < end; i++)
                    {
                        int entryIndex = buckets[i];

                        while (entryIndex != -1)
                        {
                            var key   = UnsafeUtility.ReadArrayElement <TKey>(keys, entryIndex);
                            var value = UnsafeUtility.ReadArrayElement <TValue>(values, entryIndex);

                            fullData.JobData.ExecuteNext(key, value);

                            entryIndex = nextPtrs[entryIndex];
                        }
                    }
                }
            }
Пример #2
0
        public static unsafe JobHandle Schedule <TJob, TKey, TValue>(this TJob jobData, NativeMultiHashMap <TKey, TValue> hashMap,
                                                                     int minIndicesPerJobCount, JobHandle dependsOn = new JobHandle())
            where TJob : struct, IJobNativeMultiHashMapVisitKeyValue <TKey, TValue>
            where TKey : struct, IEquatable <TKey>
            where TValue : struct
        {
            var fullData = new NativeMultiHashMapVisitKeyValueJobStruct <TJob, TKey, TValue> .JobMultiHashMap
            {
                HashMap = hashMap,
                JobData = jobData
            };

            var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref fullData),
                                                                       NativeMultiHashMapVisitKeyValueJobStruct <TJob, TKey, TValue> .Initialize(), dependsOn, ScheduleMode.Batched);

            return(JobsUtility.ScheduleParallelFor(ref scheduleParams, hashMap.m_Buffer->bucketCapacityMask + 1,
                                                   minIndicesPerJobCount));
        }