void IPoolableRecycle.OnRecycle() { PoolArray <T> .Recycle(ref this.arr); PoolQueueCopyable <int> .Recycle(ref this.freePeek); PoolHashSetCopyable <int> .Recycle(ref this.free); PoolHashSetCopyable <int> .Recycle(ref this.freePrepared); }
public void RPC <T1, T2, T3, T4, T5>(object instance, RPCId rpcId, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) where T1 : struct where T2 : struct where T3 : struct where T4 : struct where T5 : struct { var arr = PoolArray <object> .Spawn(5); arr[0] = p1; arr[1] = p2; arr[2] = p3; arr[3] = p4; arr[4] = p5; 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 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, arr); PoolArray <object> .Recycle(ref arr); }
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 Recycle() { foreach (var item in this.data) { var st = item; WorldUtilities.ReleaseState(ref st); } PoolArray <TState> .Recycle(ref this.data); PoolArray <Tick> .Recycle(ref this.dataTicks); }
public override void OnRecycle() { this.isTag = default; PoolArray <TComponent> .Recycle(ref this.components); PoolArray <byte> .Recycle(ref this.componentsStates); if (this.lifetimeIndexes != null) { PoolList <int> .Recycle(ref this.lifetimeIndexes); } }
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]; } } }
public void OnRecycle() { for (int i = 0; i < this.array.Length; ++i) { if (this.array[i] != null) { PoolArray <T> .Release(ref this.array[i]); } } this.index = 0; this.count = 0; this.fuzzyCount = 0; }
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 Recycle() { if (this.nodes != null) { PoolListCopyable <Node> .Recycle(ref this.nodes); } if (this.nodesModified != null) { PoolListCopyable <Node> .Recycle(ref this.nodesModified); } if (this.cacheEnabled == false && this.flowField.arr != null) { PoolArray <byte> .Recycle(ref this.flowField); } }
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; }
private void CallRPC(object instance, RPCId rpcId, bool storeInHistory, params object[] parameters) { Key key; if (this.objectToKey.TryGetValue(instance, out key) == true) { if (this.transporter.IsConnected() == false) { return; } var evt = new ME.ECS.StatesHistory.HistoryEvent(); evt.tick = this.world.GetStateTick() + Tick.One; // Call RPC on next tick evt.order = this.GetRPCOrder(); evt.localOrder = ++this.localOrderIndex; evt.parameters = parameters; evt.rpcId = rpcId; evt.objId = key.objId; evt.groupId = key.groupId; evt.storeInHistory = storeInHistory; var storedInHistory = false; if (storeInHistory == true && (this.GetNetworkType() & NetworkType.RunLocal) != 0) { this.statesHistoryModule.AddEvent(evt); storedInHistory = true; } if ((this.GetNetworkType() & NetworkType.SendToNet) != 0) { if (this.transporter != null && this.serializer != null) { this.transporter.Send(this.serializer.Serialize(evt)); } } if (storedInHistory == false && parameters != null) { // Return parameters into pool if we are not storing them locally PoolArray <object> .Recycle(ref parameters); } } else { throw new RegisterObjectMissingException(instance, rpcId); } }
void IModuleBase.OnDeconstruct() { //this.maxTick = Tick.Zero; this.prewarmed = false; //this.beginAddEventsTick = Tick.Zero; this.beginAddEventsCount = 0; this.beginAddEvents = false; this.statEventsAdded = 0; this.statPlayedEvents = 0; this.oldestTick = Tick.Invalid; this.lastSavedStateTick = Tick.Invalid; this.pauseStoreStateSinceTick = Tick.Invalid; this.statesHistory.DiscardAll(); this.world.SetStatesHistoryModule(null); foreach (var item in this.events) { var values = item.Value.Values; for (int i = 0, cnt = values.Count; i < cnt; ++i) { var val = values[i]; if (val.parameters != null) { PoolArray <object> .Recycle(ref val.parameters); } } item.Value.Clear(); PoolSortedList <long, HistoryEvent> .Recycle(item.Value); } PoolDictionary <Tick, ME.ECS.Collections.SortedList <long, HistoryEvent> > .Recycle(ref this.events); foreach (var kv in this.syncHashTable) { PoolDictionary <int, int> .Recycle(kv.Value); } PoolDictionary <Tick, Dictionary <int, int> > .Recycle(ref this.syncHashTable); //this.states.Recycle(); //this.states = null; }
void IModuleBase.OnDeconstruct() { this.isRequestsDirty = true; this.UpdateRequests(); var temp = PoolList <IView> .Spawn(this.registryPrefabToId.Count); foreach (var prefab in this.registryIdToPrefab) { temp.Add(prefab.Value); } foreach (var prefab in temp) { this.UnRegisterViewSource(prefab); } PoolList <IView> .Recycle(ref temp); PoolDictionary <ViewId, IViewsProvider> .Recycle(ref this.registryPrefabToProvider); PoolDictionary <ViewId, IViewsProviderInitializerBase> .Recycle(ref this.registryPrefabToProviderInitializer); PoolDictionary <ViewId, IView> .Recycle(ref this.registryIdToPrefab); PoolDictionary <IView, ViewId> .Recycle(ref this.registryPrefabToId); PoolHashSet <ViewInfo> .Recycle(ref this.rendering); for (int i = 0; i < this.list.Length; ++i) { var views = this.list.arr[i]; if (views.otherViews != null) { PoolList <IView> .Recycle(views.otherViews); } } //PoolDictionary<int, List<IView<TEntity>>>.Recycle(ref this.list); PoolArray <Views> .Recycle(ref this.list); }
void IModuleBase.OnDeconstruct() { this.statesHistory.DiscardAll(); this.world.SetStatesHistoryModule(null); foreach (var item in this.events) { foreach (var hItem in item.Value) { var val = hItem.Value; PoolArray <object> .Recycle(ref val.parameters); } item.Value.Clear(); } PoolDictionary <Tick, SortedList <long, HistoryEvent> > .Recycle(ref this.events); PoolDictionary <Tick, int> .Recycle(ref this.syncHash); //this.states.Recycle(); //this.states = null; }
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 void InitialCopyOf(CCList <T> other) { for (int i = 0; i < other.array.Length; ++i) { if (other.array[i] != null) { if (this.array[i] != null) { PoolArray <T> .Release(ref this.array[i]); } this.array[i] = PoolArray <T> .Claim(other.array[i].Length); } else { PoolArray <T> .Release(ref this.array[i]); } ArrayUtils.Clear(this.array[i]); } this.index = other.index; this.count = other.count; this.fuzzyCount = other.fuzzyCount; }
public BufferArray <T> Clear() { PoolArray <T> .Recycle(this); return(new BufferArray <T>(null, 0)); }
void IPoolableRecycle.OnRecycle() { PoolArray <DrawMeshViewBase.Item> .Recycle(ref this.items); }
public void Return(PoolArray array) { array.Data.Clear(); _arrays.Enqueue(array); }
void IPoolableRecycle.OnRecycle() { PoolArray <T> .Recycle(ref this.array); }
void IPoolableRecycle.OnRecycle() { PoolArray <ParticleViewBase.Item> .Recycle(ref this.items); }
private void CallRPC(object instance, RPCId rpcId, bool storeInHistory, object[] parameters) { if (this.world.HasStep(WorldStep.LogicTick) == true) { InStateException.ThrowWorldStateCheck(); } if (this.objectToKey.TryGetValue(instance, out var key) == true) { var evt = new ME.ECS.StatesHistory.HistoryEvent(); evt.tick = this.world.GetStateTick() + this.statesHistoryModule.GetEventForwardTick(); // Call RPC on next N tick evt.parameters = parameters; evt.rpcId = rpcId; evt.objId = key.objId; evt.groupId = key.groupId; // If event run only on local machine // we need to write data through all states and run this event immediately on each // then return current state back // so we don't need to store this event in history, we just need to rewrite reset data var runLocalOnly = this.runLocalOnly.Contains(rpcId); if (runLocalOnly == true) { { // Apply data to current state this.statesHistoryModule.RunEvent(evt); } var currentState = this.world.GetState(); var resetState = this.world.GetResetState(); this.world.SetStateDirect(resetState); { this.statesHistoryModule.RunEvent(evt); } foreach (var entry in this.statesHistoryModule.GetDataStates().GetEntries()) { if (entry.isEmpty == false) { this.world.SetStateDirect(entry.state); this.statesHistoryModule.RunEvent(evt); } } this.world.SetStateDirect(currentState); return; } // Set up other event data evt.order = this.GetRPCOrder(); evt.localOrder = ++this.localOrderIndex; evt.storeInHistory = storeInHistory; var storedInHistory = false; if (this.GetNetworkType() == NetworkType.RunLocal && storeInHistory == true) { this.statesHistoryModule.AddEvent(evt); storedInHistory = true; } if (storedInHistory == false && storeInHistory == true && (this.GetNetworkType() & NetworkType.RunLocal) != 0) { //var dEvt = this.serializer.Deserialize(this.serializer.Serialize(evt)); this.statesHistoryModule.AddEvent(evt); storedInHistory = true; } if (this.transporter != null && this.transporter.IsConnected() == true) { if (runLocalOnly == false && (this.GetNetworkType() & NetworkType.SendToNet) != 0) { if (this.transporter != null && this.serializer != null) { if (storeInHistory == false) { this.transporter.SendSystem(this.serializer.Serialize(evt)); } else { this.transporter.Send(this.serializer.Serialize(evt)); } } } } if (storedInHistory == false && parameters != null) { // Return parameters into pool if we are not storing them locally PoolArray <object> .Recycle(ref parameters); } } else { throw new RegisterObjectMissingException(instance, rpcId); } }
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); } }
public BufferArrayBool Dispose() { PoolArray <StorageType> .Recycle(this.arr); return(new BufferArrayBool(null, 0)); }
public ListCopyable() { this.innerArray = PoolArray <T> .Spawn(this.Capacity); this.Initialize(); }