예제 #1
0
파일: PoolArray.cs 프로젝트: Jlabarca/ecs
        public static void Recycle(ref BufferArray <T> buffer)
        {
            //buffer = new BufferArray<T>(null, 0);
            //return;

            T[] arr = buffer.arr;
            PoolArray <T> .Release(ref arr);

            buffer = new BufferArray <T>(null, 0);
        }
예제 #2
0
        public static BufferArray <T> Spawn(int length, bool realSize = false)
        {
            var arr = PoolArray <T> .Claim(length);

            var size   = (realSize == true ? arr.Length : length);
            var buffer = new BufferArray <T>(arr, length, realSize == true ? arr.Length : -1);

            System.Array.Clear(buffer.arr, 0, size);

            return(buffer);
        }
예제 #3
0
        public static BufferArray <T> Spawn(int length)
        {
            //return new BufferArray<T>(new T[length], length);

            //UnityEngine.Debug.Log("Spawn request: " + length);
            var buffer = new BufferArray <T>(PoolArray <T> .Claim(length), length);

            System.Array.Clear(buffer.arr, 0, length);

            return(buffer);
        }
예제 #4
0
        public static void Recycle(ref BufferArray <T> buffer)
        {
            T[] arr = buffer.arr;
            if (arr != null)
            {
                System.Array.Clear(arr, 0, arr.Length);
            }
            PoolArray <T> .Release(ref arr);

            buffer = new BufferArray <T>(null, 0);
        }
예제 #5
0
        void IPoolableRecycle.OnRecycle()
        {
            PoolHashSetCopyable <EntityId> .Recycle(ref this.dataContains);

            PoolHashSetCopyable <Entity> .Recycle(ref this.data);

            PoolArray <IFilterNode> .Recycle(ref this.nodes);

            PoolHashSet <Entity> .Recycle(ref this.requestsRemoveEntity);

            PoolHashSet <Entity> .Recycle(ref this.requests);
        }
예제 #6
0
        void IPoolableSpawn.OnSpawn()
        {
            this.requests = PoolHashSet <Entity> .Spawn(Filter <TState, TEntity> .REQUESTS_CAPACITY);

            this.requestsRemoveEntity = PoolHashSet <Entity> .Spawn(Filter <TState, TEntity> .REQUESTS_CAPACITY);

            this.nodes = PoolArray <IFilterNode> .Spawn(Filter <TState, TEntity> .NODES_CAPACITY);

            this.data = PoolHashSetCopyable <Entity> .Spawn();

            this.dataContains = PoolHashSetCopyable <EntityId> .Spawn();
        }
예제 #7
0
        public static void Recycle(BufferArray <T> buffer)
        {
            if (Pools.isActive == false)
            {
                buffer = default;
                return;
            }

            T[] arr = buffer.arr;
            //if (arr != null) System.Array.Clear(arr, 0, arr.Length);
            PoolArray <T> .Release(ref arr);
        }
예제 #8
0
        public static NativeBufferArray <T> Spawn(int length, bool realSize = false, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent)
        {
            var arrSize = PoolArray <T> .GetSize(length);

            var arr    = new Unity.Collections.NativeArray <T>(arrSize, allocator);
            var size   = (realSize == true ? arr.Length : length);
            var buffer = new NativeBufferArray <T>(arr, length, realSize == true ? arr.Length : -1);

            NativeArrayUtils.Clear(buffer, 0, size);

            return(buffer);
        }
예제 #9
0
        public static void Recycle <T, TCopy>(ref T[] item, TCopy copy) where TCopy : IArrayElementCopy <T>
        {
            if (item != null)
            {
                for (int i = 0; i < item.Length; ++i)
                {
                    copy.Recycle(item[i]);
                }

                PoolArray <T> .Recycle(ref item);
            }
        }
예제 #10
0
        public void Dispose()
        {
            for (int i = 0; i < this.itemsContains.Length; ++i)
            {
                this.itemsContains.arr[i].Dispose();
            }
            PoolArray <Item> .Recycle(ref this.itemsContains);

            for (int i = 0; i < this.itemsNotContains.Length; ++i)
            {
                this.itemsNotContains.arr[i].Dispose();
            }
            PoolArray <Item> .Recycle(ref this.itemsNotContains);
        }
예제 #11
0
파일: PoolArray.cs 프로젝트: myth326/ecs
        /// <summary>
        /// Returns an array with at least the specified length.
        /// Warning: Returned arrays may contain arbitrary data.
        /// You cannot rely on it being zeroed out.
        /// </summary>
        internal static T[] Claim(int minimumLength)
        {
            //return new T[minimumLength];

            if (minimumLength <= 0)
            {
                return(PoolArray <T> .empty);              //PoolArray<T>.ClaimWithExactLength(0);
            }

            var bucketIndex = 0;

            while (1 << bucketIndex < minimumLength && bucketIndex < 30)
            {
                ++bucketIndex;
            }

            if (bucketIndex == 30)
            {
                throw new System.ArgumentException("Too high minimum length");
            }

            if (PoolArray <T> .pool[0] == null)
            {
                PoolArray <T> .Initialize();
            }

            if (PoolArray <T> .pool[bucketIndex].TryPop(out var result) == true)
            {
                return(result);
            }

            /*lock (PoolArray<T>.pool) {
             *
             *      if (PoolArray<T>.pool[bucketIndex] == null) {
             *              PoolArray<T>.pool[bucketIndex] = new System.Collections.Generic.Stack<T[]>();
             *      }
             *
             *      if (PoolArray<T>.pool[bucketIndex].Count > 0) {
             *              var array= PoolArray<T>.pool[bucketIndex].Pop();
             *              outArrays.Add(array);
             *              return array;
             *      }
             *
             * }
             *
             * var arr = new T[1 << bucketIndex];
             * outArrays.Add(arr);
             * return arr;*/
            return(new T[1 << bucketIndex]);
        }
예제 #12
0
        internal void Deconstruct()
        {
            for (int i = 0; i < this.systems.Count; ++i)
            {
                this.systems.arr[i].OnDeconstruct();
                if (this.systems.arr[i] is ISystemFilter systemFilter)
                {
                    systemFilter.filter = null;
                }
                PoolSystems.Recycle(this.systems.arr[i]);
            }
            PoolArray <ISystemBase> .Recycle(ref this.systems);

            PoolArray <ModuleState> .Recycle(ref this.statesSystems);
        }
예제 #13
0
        public static void Copy <T, TCopy>(T[] fromArr, ref T[] arr, TCopy copy) where TCopy : IArrayElementCopy <T>
        {
            if (fromArr == null)
            {
                if (arr != null)
                {
                    for (int i = 0; i < arr.Length; ++i)
                    {
                        copy.Recycle(arr[i]);
                    }

                    PoolArray <T> .Recycle(ref arr);
                }

                arr = null;
                return;
            }

            if (arr == null || fromArr.Length != arr.Length)
            {
                if (arr != null)
                {
                    ArrayUtils.Recycle(ref arr, copy);
                }
                arr = new T[fromArr.Length];
            }

            var cnt = arr.Length;

            for (int i = 0; i < fromArr.Length; ++i)
            {
                var isDefault = i >= cnt;

                T item = (isDefault ? default : arr[i]);
                copy.Copy(fromArr[i], ref item);
                arr[i] = item;
            }
        }
예제 #14
0
 public void Recycle()
 {
     PoolArray <ushort> .Recycle(ref this.values);
 }
예제 #15
0
        internal static T[] Claim(int minimumLength)
        {
            //return new T[minimumLength];

            if (minimumLength <= 0)
            {
                return(PoolArray <T> .empty);              //PoolArray<T>.ClaimWithExactLength(0);
            }

            var bucketIndex = 0;

            while (1 << bucketIndex < minimumLength && bucketIndex < 30)
            {
                ++bucketIndex;
            }

            if (bucketIndex == 30)
            {
                throw new System.ArgumentException("Too high minimum length");
            }

            if (PoolArray <T> .pool[0] == null)
            {
                PoolArray <T> .Initialize();
            }

                        #if MULTITHREAD_SUPPORT
            if (PoolArray <T> .pool[bucketIndex].TryPop(out var result) == true)
            {
                return(result);
            }
                        #else
            var pool = PoolArray <T> .pool[bucketIndex];
            if (pool.Count > 0)
            {
                var arrPooled = pool.Pop();
                                #if UNITY_EDITOR
                if (PoolArray <T> .outArrays.Contains(arrPooled) == true)
                {
                    UnityEngine.Debug.LogError("You are trying to pool array that has been already in pool");
                }
                PoolArray <T> .outArrays.Add(arrPooled);
                                #endif

                //UnityEngine.Debug.Log("Spawn array: " + arrPooled + " :: " + arrPooled.GetHashCode());
                return(arrPooled);
            }
                        #endif

            /*lock (PoolArray<T>.pool) {
             *
             *      if (PoolArray<T>.pool[bucketIndex] == null) {
             *              PoolArray<T>.pool[bucketIndex] = new System.Collections.Generic.Stack<T[]>();
             *      }
             *
             *      if (PoolArray<T>.pool[bucketIndex].Count > 0) {
             *              var array= PoolArray<T>.pool[bucketIndex].Pop();
             *              outArrays.Add(array);
             *              return array;
             *      }
             *
             * }
             *
             * var arr = new T[1 << bucketIndex];
             * outArrays.Add(arr);
             * return arr;*/
            var arr = new T[1 << bucketIndex];
                        #if UNITY_EDITOR
            PoolArray <T> .outArrays.Add(arr);
                        #endif
            //UnityEngine.Debug.Log("Spawn new array: " + arr + " :: " + arr.GetHashCode());
            return(arr);
        }
예제 #16
0
 partial void OnSpawnComponents()
 {
     this.componentsCache = PoolArray <IComponents <TState> > .Spawn(World <TState> .COMPONENTS_CAPACITY); //PoolDictionary<int, IComponents<TState>>.Spawn(World<TState>.COMPONENTS_CAPACITY);
 }
예제 #17
0
 public void Initialize(int capacity)
 {
     this.buckets = PoolArray <Bucket> .Spawn(capacity);
 }
예제 #18
0
 public void Dispose()
 {
     PoolArray <int> .Recycle(ref this.filters);
 }
예제 #19
0
        public static void Copy <T, TCopy>(CCList <T> fromArr, ref CCList <T> arr, TCopy copy) where TCopy : IArrayElementCopy <T>
        {
            if (fromArr == null)
            {
                if (arr != null)
                {
                    for (int i = 0; i < arr.Count; ++i)
                    {
                        copy.Recycle(arr[i]);
                    }
                    PoolCCList <T> .Recycle(ref arr);
                }

                arr = null;
                return;
            }

            if (arr != null)
            {
                for (int i = 0; i < arr.Count; ++i)
                {
                    copy.Recycle(arr[i]);
                }

                PoolCCList <T> .Recycle(ref arr);
            }

            arr = PoolCCList <T> .Spawn();

            arr.InitialCopyOf(fromArr);

            for (int i = 0; i < fromArr.array.Length; ++i)
            {
                if (fromArr.array[i] == null && arr.array[i] != null)
                {
                    for (int k = 0; k < arr.array[i].Length; ++k)
                    {
                        copy.Recycle(arr.array[i][k]);
                    }

                    PoolArray <T> .Release(ref arr.array[i]);
                }
                else if (fromArr.array[i] != null && arr.array[i] == null)
                {
                    arr.array[i] = PoolArray <T> .Claim(fromArr.array[i].Length);
                }
                else if (fromArr.array[i] == null && arr.array[i] == null)
                {
                    continue;
                }

                var cnt = fromArr.array[i].Length;
                for (int j = 0; j < cnt; ++j)
                {
                    copy.Copy(fromArr.array[i][j], ref arr.array[i][j]);
                }
            }

            /*
             * if (arr == null || fromArr.Count != arr.Count) {
             *
             *  if (arr != null) {
             *
             *      for (int i = 0; i < arr.Count; ++i) {
             *
             *          copy.Recycle(arr[i]);
             *
             *      }
             *
             *      PoolCCList<T>.Recycle(ref arr);
             *
             *  }
             *
             *  arr = PoolCCList<T>.Spawn();
             *  arr.InitialCopyOf(fromArr);
             *
             * }
             *
             * for (int i = 0; i < fromArr.array.Length; ++i) {
             *
             *  if (fromArr.array[i] == null && arr.array[i] != null) {
             *
             *      for (int k = 0; k < arr.array[i].Length; ++k) {
             *
             *          copy.Recycle(arr.array[i][k]);
             *
             *      }
             *
             *      PoolArray<T>.Release(ref arr.array[i]);
             *
             *  } else if (fromArr.array[i] != null && arr.array[i] == null) {
             *
             *      arr.array[i] = PoolArray<T>.Claim(fromArr.array[i].Length);
             *
             *  } else if (fromArr.array[i] == null && arr.array[i] == null) {
             *
             *      continue;
             *
             *  }
             *
             *  var cnt = fromArr.array[i].Length;
             *  for (int j = 0; j < cnt; ++j) {
             *
             *      copy.Copy(fromArr.array[i][j], ref arr.array[i][j]);
             *
             *  }
             *
             * }*/
        }
예제 #20
0
        partial void OnRecycleComponents()
        {
            PoolArray <IComponents <TState> > .Recycle(ref this.componentsCache);

            //PoolDictionary<int, IComponents<TState>>.Recycle(ref this.componentsCache);
        }
예제 #21
0
파일: Archetypes.cs 프로젝트: Jlabarca/ecs
        public void OnRecycle()
        {
            PoolArray <Archetype> .Recycle(ref this.prevTypes);

            PoolArray <Archetype> .Recycle(ref this.types);
        }
예제 #22
0
 public void OnRecycle()
 {
     PoolArray <uint> .Recycle(ref this.values);
 }