Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        //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;
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
        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];
                }
            }
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        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;
        }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
0
        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;
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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;
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
        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;
        }
Exemplo n.º 21
0
        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;
        }
Exemplo n.º 22
0
        public BufferArray <T> Clear()
        {
            PoolArray <T> .Recycle(this);

            return(new BufferArray <T>(null, 0));
        }
Exemplo n.º 23
0
 void IPoolableRecycle.OnRecycle()
 {
     PoolArray <DrawMeshViewBase.Item> .Recycle(ref this.items);
 }
Exemplo n.º 24
0
 public void Return(PoolArray array)
 {
     array.Data.Clear();
     _arrays.Enqueue(array);
 }
Exemplo n.º 25
0
 void IPoolableRecycle.OnRecycle()
 {
     PoolArray <T> .Recycle(ref this.array);
 }
Exemplo n.º 26
0
 void IPoolableRecycle.OnRecycle()
 {
     PoolArray <ParticleViewBase.Item> .Recycle(ref this.items);
 }
Exemplo n.º 27
0
        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);
            }
        }
Exemplo n.º 28
0
        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);
            }
        }
Exemplo n.º 29
0
        public BufferArrayBool Dispose()
        {
            PoolArray <StorageType> .Recycle(this.arr);

            return(new BufferArrayBool(null, 0));
        }
Exemplo n.º 30
0
        public ListCopyable()
        {
            this.innerArray = PoolArray <T> .Spawn(this.Capacity);

            this.Initialize();
        }