public NativeQueue(int size, Unity.Collections.Allocator allocator) { this.arr = new Unity.Collections.NativeList <T>(size, allocator); this.Count = 0; this.head = -1; this.last = -1; }
private Unity.Collections.NativeList <GridNodeData> AstarSearch(ref int statVisited, GridGraph graph, GridNode startNode, GridNode endNode, Constraint constraint, int threadIndex) { var graphSize = graph.size; var graphCenter = graph.graphCenter; var burstConstraint = constraint.GetBurstConstraint(); var resultPath = new Unity.Collections.NativeList <GridNodeData>(10, Unity.Collections.Allocator.Persistent); var arr = new Unity.Collections.NativeArray <GridNodeData>(graph.nodesData, Unity.Collections.Allocator.TempJob); var openList = new PriorityQueueNative <GridNodeData>(Unity.Collections.Allocator.TempJob, 500, true); var results = new Unity.Collections.NativeArray <int>(2, Unity.Collections.Allocator.TempJob); var endNodeIndex = endNode.index; var startNodeIndex = startNode.index; var job = new Job() { graphCenter = graphCenter, graphSize = graphSize, burstConstraint = burstConstraint, resultPath = resultPath, arr = arr, openList = openList, results = results, endNodeIndex = endNodeIndex, startNodeIndex = startNodeIndex, }; job.Schedule().Complete(); statVisited = results[0]; results.Dispose(); openList.Dispose(); arr.Dispose(); return(resultPath); }
public static unsafe bool Resize <T>(int index, ref Unity.Collections.NativeList <T> arr, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : unmanaged { const int offset = 1; if (arr.IsCreated == false) { arr = new Unity.Collections.NativeList <T>(index * offset + 1, allocator); } if (index < arr.Length) { return(false); } var newLength = arr.Length * offset + 1; if (newLength == 0 || newLength <= index) { newLength = index * offset + 1; } var elements = newLength - arr.Length; //var ptr = (void*)((System.IntPtr)arr.GetUnsafePtr() + UnsafeUtility.SizeOf<T>() * arr.Length); for (int i = 0; i < elements; ++i) { arr.Add(default);
public static ref T GetRefRead <T>(this Unity.Collections.NativeList <T> array, int index) where T : unmanaged { CheckArray(index, array.Length); unsafe { var ptr = array.GetUnsafeReadOnlyPtr(); #if UNITY_2020_1_OR_NEWER return(ref UnsafeUtility.ArrayElementAsRef <T>(ptr, index)); #else throw new Exception("UnsafeUtility.ArrayElementAsRef"); #endif } }
public static ref T GetRefRead <T>(this Unity.Collections.NativeList <T> array, int index) where T : struct { if (index < 0 || index >= array.Length) { throw new ArgumentOutOfRangeException(nameof(index)); } unsafe { var ptr = array.GetUnsafeReadOnlyPtr(); #if UNITY_2020_1_OR_NEWER return(ref UnsafeUtility.ArrayElementAsRef <T>(ptr, index)); #else throw new Exception("UnsafeUtility.ArrayElementAsRef"); #endif } }
/// <summary> /// If min queue or max queue /// </summary> /// <param name="isMinPriorityQueue"></param> public PriorityQueueNative(Unity.Collections.Allocator allocator, int capacity = 4, bool isMinPriorityQueue = false) { this.heapSize = -1; this.isMinPriorityQueue = isMinPriorityQueue == true ? (byte)1 : (byte)0; this.queue = new Unity.Collections.NativeList <Node>(capacity, allocator); }