public static JobHandle MergeSlices <T>(
                NativeList <T> result,
                NativeList <T>[] buffers,
                ref SortState state,
                JobHandle inputDeps)
                where T : struct, IComparable <T>
            {
                var proceedToNextBuffer = false;
                var mergeAmount         = state.ProcessAmount * state.ConcurrentSorts;
                var leftIndexUnit       = new NativeUnit <int>(state.LeftIndex, Allocator.TempJob);
                var rightIndexUnit      = new NativeUnit <int>(state.RightIndex, Allocator.TempJob);
                var resultIndexUnit     = new NativeUnit <int>(state.ResultIndex, Allocator.TempJob);

                state.WriteBufferIndex += state.WriteBufferIndex == 0 ? state.BaseSliceCount : 0;
                while (state.WriteBufferIndex < buffers.Length && mergeAmount > 0)
                {
                    var mergeInputDeps = default(JobHandle);
                    if (state.ResultIndex == 0)
                    {
                        mergeInputDeps = buffers[state.WriteBufferIndex].Resize(buffers[state.ReadBufferIndex].Length + buffers[state.ReadBufferIndex + 1].Length, inputDeps);
                    }
                    mergeInputDeps = new Merge <T> {
                        LeftArray     = buffers[state.ReadBufferIndex].AsDeferredJobArray(),
                        RightArray    = buffers[state.ReadBufferIndex + 1].AsDeferredJobArray(),
                        Target        = buffers[state.WriteBufferIndex].AsDeferredJobArray(),
                        LeftIndex     = leftIndexUnit,
                        RightIndex    = rightIndexUnit,
                        ResultIndex   = resultIndexUnit,
                        MaxMergeCount = mergeAmount
                    }.Schedule(mergeInputDeps);
                    mergeInputDeps.Complete();
                    mergeAmount -= resultIndexUnit.Value - state.ResultIndex;
                    // We've reached the end of the write buffer so we can proceed to the next one
                    proceedToNextBuffer = resultIndexUnit.Value == buffers[state.WriteBufferIndex].Length;
                    if (proceedToNextBuffer)
                    {
                        state.ReadBufferIndex += 2;
                        state.WriteBufferIndex++;
                        leftIndexUnit.Value = rightIndexUnit.Value = resultIndexUnit.Value = 0;
                        state.LeftIndex     = state.RightIndex = state.ResultIndex = 0;
                    }
                    else
                    {
                        break;
                    }
                }

                state.LeftIndex   = proceedToNextBuffer ? 0 : leftIndexUnit.Value;
                state.RightIndex  = proceedToNextBuffer ? 0 : rightIndexUnit.Value;
                state.ResultIndex = proceedToNextBuffer ? 0 : resultIndexUnit.Value;

                leftIndexUnit.Dispose();
                rightIndexUnit.Dispose();
                resultIndexUnit.Dispose();
                return(inputDeps);
            }
Ejemplo n.º 2
0
 public static JobHandle DidChange <T>(
     this EntityQuery query,
     ComponentSystemBase system,
     ref NativeUnit <bool> changed,
     JobHandle inputDeps,
     bool changeAll = false)
     where T : struct, IComponentData
 {
     return(new DidChange <T> {
         ChunkType = system.GetArchetypeChunkComponentType <T>(true),
         Changed = changed,
         LastSystemVersion = system.LastSystemVersion,
         ForceChange = changeAll
     }.ScheduleParallel(query, inputDeps));
 }
Ejemplo n.º 3
0
 public CullingLoader()
 {
     _centroidPosition = new NativeUnit <int2>(Allocator.Persistent);
 }