public static bool Resize <T>(int index, ref T[] arr) { if (arr == null) { arr = PoolArray <T> .Spawn(index + 1); } if (index < arr.Length) { return(false); } var newLength = arr.Length * 2; if (newLength == 0 || newLength <= index) { newLength = index + 1; } var newArr = PoolArray <T> .Spawn(newLength); System.Array.Copy(arr, newArr, arr.Length); PoolArray <T> .Recycle(ref arr); arr = newArr; return(true); }
public void SetCapacity(int min) { if (this.Capacity < min) { var prevLength = this.Capacity; this.Capacity *= 2; if (this.Capacity < min) { this.Capacity = min; } var newArray = PoolArray <T> .Spawn(this.Capacity); if (this.tail > this.head) // If we are not wrapped around... { Array.Copy(this.innerArray.arr, this.head, newArray.arr, 0, this.Count); // ...take from head to head+Count and copy to beginning of new array } else if (this.Count > 0) // Else if we are wrapped around... (tail == head is ambiguous - could be an empty buffer or a full one) { Array.Copy(this.innerArray.arr, this.head, newArray.arr, 0, prevLength - this.head); // ...take head to end and copy to beginning of new array Array.Copy(this.innerArray.arr, 0, newArray.arr, prevLength - this.head, this.tail); // ...take beginning to tail and copy after previously copied elements } this.head = 0; this.tail = this.Count; if (this.innerArray.isNotEmpty == true) { PoolArray <T> .Recycle(ref this.innerArray); } this.innerArray = newArray; } }
public BufferArray <T> ToBufferArray() { var retArray = PoolArray <T> .Spawn(this.Count); System.Array.Copy(this.innerArray.arr, 0, retArray.arr, 0, this.Count); return(retArray); }
public void OnSpawn() { this.innerArray = PoolArray <T> .Spawn(this.Capacity); this.Capacity = 0; this.Initialize(); }
public void OnSpawn() { this.innerArray = PoolArray <T> .Spawn(this.Capacity); this.Capacity = 0; this.Count = 0; }
public void RPC <T1>(object instance, RPCId rpcId, T1 p1) where T1 : struct { var arr = PoolArray <object> .Spawn(1); arr[0] = p1; this.CallRPC(instance, rpcId, true, arr); }
public ListCopyable(int startCapacity) { this.Capacity = startCapacity; this.innerArray = PoolArray <T> .Spawn(this.Capacity); this.Initialize(); }
private void SetCapacity(int capacity) { var newarray = PoolArray <T> .Spawn(capacity); if (this.size > 0) { if (this.head < this.tail) { Array.Copy(this.array.arr, this.head, newarray.arr, 0, this.size); } else { Array.Copy(this.array.arr, this.head, newarray.arr, 0, this.array.Length - this.head); Array.Copy(this.array.arr, 0, newarray.arr, this.array.Length - this.head, this.tail); } } if (this.array.arr != null) { PoolArray <T> .Recycle(ref this.array); } this.array = newarray; this.head = 0; this.tail = this.size == capacity ? 0 : this.size; this.version++; }
private void Resize_INTERNAL(int newLength) { if (newLength > this.capacity) { var oldCapacity = this.capacity; if (this.capacity > 0) { this.capacity *= 2; } else { this.capacity = newLength; oldCapacity = 0; } var arr = PoolArray <T> .Spawn(this.capacity); if (this.arr != null) { System.Array.Copy(this.arr, arr, this.arr.Length); PoolArray <T> .Recycle(ref this.arr); } this.arr = arr; } }
public void RPC <T1, T2>(object instance, RPCId rpcId, T1 p1, T2 p2) where T1 : struct where T2 : struct { var arr = PoolArray <object> .Spawn(2); arr[0] = p1; arr[1] = p2; this.CallRPC(instance, rpcId, true, arr); }
public BufferArrayBool(BufferArrayBool arr, int length) { this.arr = PoolArray <StorageType> .Spawn(length / BufferArrayBool.SIZE + 1); this.Length = length; this.isCreated = true; System.Array.Copy(arr.arr.arr, this.arr.arr, arr.Length); }
public QueueCopyable(int capacity) { this.Capacity = capacity; this.head = 0; this.tail = 0; this.Count = 0; this.innerArray = PoolArray <T> .Spawn(this.Capacity); }
public static BufferArray <T> From(IList <T> arr) { var length = arr.Count; var buffer = PoolArray <T> .Spawn(length); ArrayUtils.Copy(arr, ref buffer); return(buffer); }
public QueueCopyable(int capacity) { this.capacity = capacity; this.array = PoolArray <T> .Spawn(capacity); this.head = 0; this.tail = 0; this.size = 0; }
public static BufferArray <T> From(ListCopyable <T> arr) { var length = arr.Count; var buffer = PoolArray <T> .Spawn(length); System.Array.Copy(arr.innerArray.arr, buffer.arr, length); return(buffer); }
public static BufferArray <T> From(T[] arr) { var length = arr.Length; var buffer = PoolArray <T> .Spawn(length); ArrayUtils.Copy(new BufferArray <T>(arr, length), ref buffer); return(buffer); }
public void RPC <T1, T2, T3>(object instance, RPCId rpcId, T1 p1, T2 p2, T3 p3) where T1 : struct where T2 : struct where T3 : struct { var arr = PoolArray <object> .Spawn(3); arr[0] = p1; arr[1] = p2; arr[2] = p3; this.CallRPC(instance, rpcId, arr); PoolArray <object> .Recycle(ref arr); }
public void RPC <T1, T2, T3, T4>(object instance, RPCId rpcId, T1 p1, T2 p2, T3 p3, T4 p4) where T1 : struct where T2 : struct where T3 : struct where T4 : struct { var arr = PoolArray <object> .Spawn(4); arr[0] = p1; arr[1] = p2; arr[2] = p3; arr[3] = p4; this.CallRPC(instance, rpcId, true, arr); }
//private bool beginSet; public StatesCircularQueue(Tick ticksPerState, uint capacity) { this.dataTicks = PoolArray <Tick> .Spawn((int)capacity); this.data = PoolArray <TState> .Spawn((int)capacity);//PoolDictionary<Tick, TState>.Spawn((int)capacity); this.capacity = capacity; this.ticksPerState = ticksPerState; this.idx = 0; //this.beginSet = false; }
public static bool WillResize <T>(int index, ref T[] arr) { if (arr == null) { arr = PoolArray <T> .Spawn(index + 1); } if (index < arr.Length) { return(false); } return(true); }
public void CopyFrom(EntitiesList <T> other) { if (this.arr != null) { PoolArray <T> .Recycle(ref this.arr); } this.arr = PoolArray <T> .Spawn(other.arr.Length); System.Array.Copy(other.arr, this.arr, other.arr.Length); this.capacity = other.capacity; this.count = other.count; }
public BufferArrayBool(bool[] arr, int length) { this.arr = PoolArray <StorageType> .Spawn(length / BufferArrayBool.SIZE + 1); this.Length = length; this.isCreated = true; if (arr != null) { for (int i = 0; i < length; ++i) { this[i] = arr[i]; } } }
void IModuleBase.OnConstruct() { this.isRequestsDirty = false; this.list = PoolArray <Views> .Spawn(ViewsModule.VIEWS_CAPACITY); this.rendering = PoolHashSet <ViewInfo> .Spawn(ViewsModule.VIEWS_CAPACITY); this.registryPrefabToId = PoolDictionary <IView, ViewId> .Spawn(ViewsModule.REGISTRY_CAPACITY); this.registryIdToPrefab = PoolDictionary <ViewId, IView> .Spawn(ViewsModule.REGISTRY_CAPACITY); this.registryPrefabToProvider = PoolDictionary <ViewId, IViewsProvider> .Spawn(ViewsModule.REGISTRY_PROVIDERS_CAPACITY); this.registryPrefabToProviderInitializer = PoolDictionary <ViewId, IViewsProviderInitializerBase> .Spawn(ViewsModule.REGISTRY_PROVIDERS_CAPACITY); }
public BufferArray <T> ToArray() { var result = PoolArray <T> .Spawn(this.Count); if (this.tail > this.head) { Array.Copy(this.innerArray.arr, this.head, result.arr, 0, this.Count); } else if (this.Count > 0) { Array.Copy(this.innerArray.arr, this.head, result.arr, 0, this.Capacity - this.head); Array.Copy(this.innerArray.arr, 0, result.arr, this.Capacity - this.head, this.tail); } return(result); }
public void CopyFrom(QueueCopyable <T> other) { if (this.array.arr != null) { PoolArray <T> .Recycle(ref this.array); } this.array = PoolArray <T> .Spawn(other.array.Length); System.Array.Copy(other.array.arr, this.array.arr, other.array.Length); this.head = other.head; this.tail = other.tail; this.size = other.size; this.version = other.version; this.capacity = other.capacity; }
public static void Copy <T>(T[] fromArr, ref T[] arr) { if (fromArr == null) { if (arr != null) { PoolArray <T> .Recycle(ref arr); } arr = null; return; } if (arr == null || fromArr.Length != arr.Length) { if (arr != null) { PoolArray <T> .Recycle(ref arr); } arr = PoolArray <T> .Spawn(fromArr.Length); } System.Array.Copy(fromArr, arr, fromArr.Length); }
public void CopyFrom(HashSetCopyable <T> other) { if (this.m_buckets != null) { PoolArray <int> .Recycle(ref this.m_buckets); } if (other.m_buckets != null) { this.m_buckets = PoolArray <int> .Spawn(other.m_buckets.Length); for (int i = 0; i < this.m_buckets.Length; ++i) { this.m_buckets[i] = other.m_buckets[i]; } } if (this.m_slots != null) { PoolArray <Slot> .Recycle(ref this.m_slots); } if (other.m_slots != null) { this.m_slots = PoolArray <Slot> .Spawn(other.m_slots.Length); for (int i = 0; i < this.m_slots.Length; ++i) { this.m_slots[i] = other.m_slots[i]; } } this.m_count = other.m_count; this.m_lastIndex = other.m_lastIndex; this.m_freeList = other.m_freeList; this.m_comparer = other.m_comparer; this.m_version = other.m_version; }
public Path Run <TMod>(LogLevel pathfindingLogLevel, Vector3 from, Vector3 to, Constraint constraint, Graph graph, TMod pathModifier, int threadIndex = 0, bool burstEnabled = true, bool cacheEnabled = false) where TMod : struct, IPathModifier { if (threadIndex < 0) { threadIndex = 0; } threadIndex = threadIndex % Pathfinding.THREADS_COUNT; var constraintStart = constraint; constraintStart.checkWalkability = true; constraintStart.walkable = true; var startNode = graph.GetNearest(from, constraintStart); if (startNode == null) { return(new Path()); } var constraintEnd = constraintStart; constraintEnd.checkArea = true; constraintEnd.areaMask = (1 << startNode.area); var endNode = graph.GetNearest(to, constraintEnd); if (endNode == null) { return(new Path()); } System.Diagnostics.Stopwatch swPath = null; if ((pathfindingLogLevel & LogLevel.Path) != 0) { swPath = System.Diagnostics.Stopwatch.StartNew(); } //UnityEngine.Debug.Log(endNode.worldPosition + " :: " + ((GridNode)endNode).erosion); //UnityEngine.Debug.DrawLine(endNode.worldPosition, endNode.worldPosition + Vector3.up * 10f, Color.red, 3f); var key = MathUtils.GetKey(constraint.GetKey(), endNode.index); //UnityEngine.Debug.Log("Build path cache: " + cacheEnabled + ", burst: " + burstEnabled); if (cacheEnabled == true) { if (PathfindingFlowFieldProcessor.pathCache.TryGetValue(key, out var buffer) == true) { var pathCache = new Path() { graph = graph, result = PathCompleteState.Complete, flowField = buffer, cacheEnabled = cacheEnabled, }; if ((pathfindingLogLevel & LogLevel.Path) != 0) { Logger.Log(string.Format("Path result {0}, cache in {1}ms. \nThread Index: {2}", pathCache.result, swPath.ElapsedMilliseconds, threadIndex)); } return(pathCache); } } var flowField = PoolArray <byte> .Spawn(graph.nodes.Count); int statVisited = 0; if (burstEnabled == true) // burst { this.FlowFieldBurst(ref statVisited, (GridGraph)graph, ref flowField, (GridNode)endNode, constraint, pathModifier); if (cacheEnabled == true) { if (PathfindingFlowFieldProcessor.pathCache.Count > PathfindingFlowFieldProcessor.CACHE_SIZE) { const int size = PathfindingFlowFieldProcessor.CACHE_SIZE / 10; for (int i = 0; i < size; ++i) { var idx = PathfindingFlowFieldProcessor.pathCacheQueue.Dequeue(); PathfindingFlowFieldProcessor.pathCache.Remove(idx); } PathfindingFlowFieldProcessor.pathCacheQueue.Clear(); } PathfindingFlowFieldProcessor.pathCache.Add(key, flowField); PathfindingFlowFieldProcessor.pathCacheQueue.Enqueue(key); } } else // no burst { var visited = PoolListCopyable <Node> .Spawn(10); for (int i = 0; i < graph.nodes.Count; ++i) { graph.nodes[i].Reset(threadIndex); } this.CreateIntegrationField(graph, visited, endNode, constraint, threadIndex); this.CreateFlowField(graph, ref flowField, endNode, constraint, threadIndex); statVisited = visited.Count; for (int i = 0; i < visited.Count; ++i) { visited[i].Reset(threadIndex); } PoolListCopyable <Node> .Recycle(ref visited); } var path = new Path(); path.graph = graph; path.result = PathCompleteState.Complete; path.flowField = flowField; path.cacheEnabled = cacheEnabled; if ((pathfindingLogLevel & LogLevel.Path) != 0) { Logger.Log(string.Format("Path result {0}, built in {1}ms. Path length: (visited: {2})\nThread Index: {3}", path.result, (swPath.ElapsedTicks / (double)System.TimeSpan.TicksPerMillisecond).ToString("0.##"), statVisited, threadIndex)); } return(path); }
void IPoolableSpawn.OnSpawn() { this.array = PoolArray <T> .Spawn(this.capacity); }
public void CompareBoolWithBitArray() { const int size = 100000; var sw = System.Diagnostics.Stopwatch.StartNew(); { var arr = new System.Collections.BitArray(size); for (int i = 0; i < arr.Length; ++i) { arr[i] = true; } for (int i = 0; i < arr.Length; ++i) { NUnit.Framework.Assert.True(arr[i] == true); } for (int i = 0; i < arr.Length; ++i) { arr[i] = false; } for (int i = 0; i < arr.Length; ++i) { NUnit.Framework.Assert.True(arr[i] == false); } for (int i = 0; i < arr.Length; ++i) { arr[i] = i % 2 == 0 ? true : false; } for (int i = 0; i < arr.Length; ++i) { NUnit.Framework.Assert.True(arr[i] == (i % 2 == 0 ? true : false)); } UnityEngine.Debug.Log("BitArray ticks: " + sw.ElapsedTicks); } sw.Restart(); { var arr = new BufferArrayBool(size); for (int i = 0; i < arr.Length; ++i) { arr[i] = true; } for (int i = 0; i < arr.Length; ++i) { NUnit.Framework.Assert.True(arr[i] == true); } for (int i = 0; i < arr.Length; ++i) { arr[i] = false; } for (int i = 0; i < arr.Length; ++i) { NUnit.Framework.Assert.True(arr[i] == false); } for (int i = 0; i < arr.Length; ++i) { arr[i] = i % 2 == 0 ? true : false; } for (int i = 0; i < arr.Length; ++i) { NUnit.Framework.Assert.True(arr[i] == (i % 2 == 0 ? true : false)); } UnityEngine.Debug.Log("BufferArrayBool ticks: " + sw.ElapsedTicks); } sw.Restart(); { var arr = PoolArray <bool> .Spawn(size); for (int i = 0; i < arr.Length; ++i) { arr[i] = true; } for (int i = 0; i < arr.Length; ++i) { NUnit.Framework.Assert.True(arr[i] == true); } for (int i = 0; i < arr.Length; ++i) { arr[i] = false; } for (int i = 0; i < arr.Length; ++i) { NUnit.Framework.Assert.True(arr[i] == false); } for (int i = 0; i < arr.Length; ++i) { arr[i] = i % 2 == 0 ? true : false; } for (int i = 0; i < arr.Length; ++i) { NUnit.Framework.Assert.True(arr[i] == (i % 2 == 0 ? true : false)); } UnityEngine.Debug.Log("BufferArray<bool> ticks: " + sw.ElapsedTicks); } }