Exemplo n.º 1
0
            public static unsafe void Execute(ref JobNativeMultiHashMapVisitKeyMutableValueProducer <TJob, TKey, TValue> producer, 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;
                    }

                    var bucketData = producer.HashMap.GetUnsafeBucketData();
                    var buckets    = (int *)bucketData.buckets;
                    var nextPtrs   = (int *)bucketData.next;
                    var keys       = bucketData.keys;
                    var values     = bucketData.values;

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

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

                            producer.JobData.ExecuteNext(key, ref UnsafeUtility.ArrayElementAsRef <TValue>(values, entryIndex));

                            entryIndex = nextPtrs[entryIndex];
                        }
                    }
                }
            }
Exemplo n.º 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, IJobNativeMultiHashMapVisitKeyMutableValue <TKey, TValue>
            where TKey : struct, IEquatable <TKey>
            where TValue : struct
        {
            var jobProducer = new JobNativeMultiHashMapVisitKeyMutableValueProducer <TJob, TKey, TValue>
            {
                HashMap = hashMap,
                JobData = jobData
            };

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

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