Example #1
0
        public static IEnumerable <string> GetAllFiles(string path, string[] extensions = null, string[] excludedExtensions = null)
        {
            QuickList <string> files = new QuickList <string>();

            files.AddRange(Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories));

            if (extensions != null && extensions.Length > 0)
            {
                for (int i = files.Count; i >= 0; --i)
                {
                    string file = files.Array[i];
                    if (!extensions.Contains(Path.GetExtension(file)))
                    {
                        files.Remove(file);
                    }
                }
            }

            if (excludedExtensions != null && excludedExtensions.Length > 0)
            {
                for (int i = files.Count; i >= 0; --i)
                {
                    string file = files.Array[i];
                    if (excludedExtensions.Contains(Path.GetExtension(file)))
                    {
                        files.Remove(file);
                    }
                }
            }
            return(files);
        }
Example #2
0
 public EmitterFilterer Include(Func <Emitter, bool> predicate)
 {
     Emitter[] arr = emitters.Array;
     for (int i = emitters.Count - 1; i >= 0; i--)
     {
         Emitter e = arr[i];
         if (!predicate.Invoke(e))
         {
             emitters.Remove(e);
         }
     }
     return(this);
 }
Example #3
0
        public void ElementRemoveNotNullElementTest()
        {
            var master = new QuickList <object>(3);
            var result = new List <object> {
                null, 1, 2, null, 3
            };

            foreach (var r in result)
            {
                master.Push(r);
            }
            master.Remove(1);
            Assert.AreEqual(4, master.Count);
            var index = 0;

            if (master.Pop() == null)
            {
                index++;
            }
            if (master.Pop() == null)
            {
                index++;
            }
            if (master.Pop() == null)
            {
                index++;
            }
            if (master.Pop() == null)
            {
                index++;
            }

            Assert.AreEqual(0, master.Count);
            Assert.AreEqual(2, index);
        }
Example #4
0
        public void NullElementRemoveAllWithNum()
        {
            var master = new QuickList <object>(3);
            var result = new List <object> {
                null, 1, 2, null, 3
            };

            foreach (var r in result)
            {
                master.Push(r);
            }

            master.Remove(null, 5);

            Assert.AreEqual(3, master.Count);

            var index = 0;

            if (master.Pop() == null)
            {
                index++;
            }
            if (master.Pop() == null)
            {
                index++;
            }
            if (master.Pop() == null)
            {
                index++;
            }

            Assert.AreEqual(0, master.Count);
            Assert.AreEqual(0, index);
        }
Example #5
0
 public void Unsubscribe(T subscriber)
 {
     if (Subscribers.Remove(subscriber))
     {
         IsDirty = true;
     }
 }
Example #6
0
        public void ReverseRemove()
        {
            var master = new QuickList <int>(20);

            for (var i = 0; i < 256; i++)
            {
                master.Push(i);
            }

            master.Remove(5, -999);
            master.Remove(6, -999);

            Assert.AreEqual(7, master[5]);
            Assert.AreEqual(8, master[6]);
            Assert.AreEqual(254, master.Count);
        }
Example #7
0
        /// <summary>
        /// 轮询时要处理的事件
        /// </summary>
        public void IntervalEvent()
        {
            // 统计已经过期的对象
            expireItems.Clear();

            for (int index = 0; index < FreePools.Count; index++)
            {
                var poolEntity = FreePools[index];
                if (null == poolEntity)
                {
                    continue;
                }

                if (Time.time - poolEntity.LastRecoverTime > expiredTime) // 已经过期
                {
                    expireItems.Add(poolEntity);
                }
            }

            // 清理已经过期的对象,并从队列中删除
            if (expireItems.Count > 0)
            {
                for (int index = 0; index < expireItems.Count; index++)
                {
                    var expireItem = expireItems[index];
                    expireItem.PoolDisposeEvent(); // 发送Dispose事件
                    expireItem.IsDestroyTag = true;
                    FreePools.Remove(expireItem);                  // 从队列中移除
                    rawResResponse.Destroy(expireItem.gameObject); // 销毁
                }

                expireItems.Clear();
            }
        }
Example #8
0
        public void ReverseRemoveRandom()
        {
            var master = new QuickList <int>(8);

            for (var i = 0; i < 256; i++)
            {
                master.Push(i);
            }

            var lst = new List <int>();

            for (var i = 255; i >= 0; i--)
            {
                if (!lst.Contains(i))
                {
                    lst.Add(i);
                    master.Remove(i, -999);
                }
            }

            foreach (var v in master)
            {
                if (lst.Contains(v))
                {
                    Assert.Fail();
                }
            }
        }
        protected override void OnRemoved(int collectionIndex, int index, TSource value)
        {
            var sourcePair = _rightKeys[index];

            _rightKeys.Remove(index);
            Remove(sourcePair.Key, sourcePair.Value, _rightCount, _leftCount, OnRemovedFromRight);
        }
 private void RemoveIndex(int index, bool updateOnly)
 {
     if (updateOnly)
     {
         _indexList[index] = -1;
     }
     else
     {
         _indexList.Remove(index);
     }
     for (int i = index; i < _indexList.Count; ++i)
     {
         if (_indexList[i] >= 0)
         {
             --_indexList[i];
         }
     }
 }
        protected override void OnRemoved(int index, TSource value)
        {
            var itemSet = _sourceList[index];

            _sourceList.Remove(itemSet.SourceIndex);
            ResultList.Remove(itemSet.TargetIndex);

            UpdateSourceIndexes(itemSet.SourceIndex);
            UpdateTargetIndexes(itemSet.TargetIndex);
        }
Example #12
0
        private static void ReturnToPool(SpatialPartition partition)
        {
            partitions.Remove(partition);

            // Return the partition to the pool, if there's enough room.
            if (partitionPool.Count + 1 < MaxPoolSize)
            {
                partitionPool.Add(partition);
            }
            partition.IsActive = false;
        }
        protected override void OnRemoved(int collectionIndex, int index, int value)
        {
            var item = _indexes[index];

            _indexes.Remove(index);
            if (item.InList)
            {
                RecalculateIndexes(index, _indexes.Count - 1);
                ResultList.Remove(item.Index);
            }
        }
Example #14
0
 /// <summary>
 /// Unregisters a GameObject from the engine.
 /// </summary>
 /// <param name="go">GameObject which was destroyed.</param>
 /// <param name="destroyed">If the GameObject was destroyed.</param>
 internal static void RemoveGameObject(GameObject go, bool destroyed = false)
 {
     lock (gameObjectHandlerLock) {
         DynamicGameObjects.Remove(go);
         CurrentScene.GameObjectsToRemove.Add(go);
         SpatialPartitionManager.Remove(go);
         if (destroyed)
         {
             AllGameObjects.Remove(go);
         }
         go.AddedToGameManager = false;
         EngineUtility.TransformHierarchyDirty = true;
     }
 }
Example #15
0
        public void InsertNodeAtTailTest()
        {
            var master = new QuickList <int>(5);

            for (var i = 0; i < 255; i++)
            {
                master.Push(i);
            }

            master.Remove(5);
            master.InsertAfter(4, 999);

            Assert.AreEqual(999, master[5]);
        }
Example #16
0
        public void InsertNodeAtHeaderTest()
        {
            var master = new QuickList <int>(5);

            for (var i = 0; i < 255; i++)
            {
                master.Push(i);
            }

            master.Remove(4);
            master.InsertBefore(5, 999);

            Assert.AreEqual(999, master[4]);
        }
Example #17
0
 public void HandleCoroutineStop(BaseCoroutine baseCor)
 {
     if (baseCor is Coroutine)
     {
         var cor = baseCor as Coroutine;
         _activeCoroutines.Remove(cor);
         _pendingCoroutines.Add(cor);
     }
     else if (baseCor is ExecuteAfterDelay)
     {
         var exec = baseCor as ExecuteAfterDelay;
         _activeDelayedExecutes.Remove(exec);
         _pendingDelayedExecutes.Add(exec);
     }
 }
Example #18
0
        protected override void OnRemoved(int index, TSource value)
        {
            var item = _sourceData[index];

            _sourceData.Remove(index);

            item.SourceIndex = -1;

            for (int i = index; i < _sourceData.Count; ++i)
            {
                _sourceData[i].SourceIndex = i;
            }

            RemoveFromGroup(item);
        }
Example #19
0
    /// <summary>
    /// 销毁一个对象
    /// </summary>
    /// <param name="key"></param>
    private void DestroyOneObject(int key)
    {
        object      target     = m_hashTableObjs[key];
        IDisposable disposable = target as IDisposable;

        if (disposable != null)
        {
            disposable.Dispose();
        }
        if (this.m_hashTableStatus[key])
        {
            this.m_idleObjCount--;
        }
        m_hashTableObjs.Remove(key);
        m_hashTableStatus.Remove(key);
        m_keyList.Remove(key);
    }
Example #20
0
        private static SpatialPartition TakeFromPool(Point position)
        {
            // Create new partition if there's none in the pool.
            if (partitionPool.Count < 1)
            {
                return(CreateNewPartition(position, true));
            }

            // Otherwise, return a partition that's in the pool.
            SpatialPartition partition = partitionPool.Array[partitionPool.Count - 1];

            partitions.Add(partition);
            partitionPool.Remove(partition);
            partition.UpdatePosition(position);
            partition.IsActive = true;
            return(partition);
        }
Example #21
0
        public void RemoveReturnNumTest()
        {
            var master = new QuickList <int>(8);

            master.Push(111);
            master.Push(111);
            master.Push(111);
            master.Push(222);
            master.Push(333);
            master.Push(111);
            master.Push(111);
            master.Push(444);
            master.Push(333);

            var removeNum = master.Remove(111);

            Assert.AreEqual(5, removeNum);
        }
        protected void RemoveSourceCollection(int collectionIndex)
        {
            if (collectionIndex < 0 || collectionIndex >= _sourceLists.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(collectionIndex));
            }

            var wrapper = _sourceLists[collectionIndex];

            _sourceLists.Remove(collectionIndex);
            for (int i = collectionIndex; i < _sourceLists.Count; ++i)
            {
                _sourceLists[i].CollectionIndex = i;
            }
            wrapper.Dispose();
            OnCollectionRemoved(collectionIndex);
            OnReset(collectionIndex, new TOtherSources[0]);
        }
Example #23
0
        public void RemovWithCountByTail()
        {
            var master = new QuickList <int>(5);

            for (var i = 0; i < 255; i++)
            {
                master.Push(i);
            }

            master.Push(255);
            master.Push(255);
            master.Push(255);
            master.Push(255);

            master.Remove(255, -3);

            Assert.AreEqual(255, master[255]);
            Assert.AreEqual(256, master.Count);
        }
Example #24
0
        public void RemoveReturnNumLimitTest()
        {
            var master = new QuickList <int>(8);

            master.Push(111);
            master.Push(111);
            master.Push(111);
            master.Push(222);
            master.Push(333);
            master.Push(111);
            master.Push(111);
            master.Push(444);
            master.Push(333);

            var removeNum = master.Remove(111, 3);

            Assert.AreEqual(3, removeNum);
            Assert.AreEqual(222, master[0]);
            Assert.AreEqual(111, master[2]);
        }
Example #25
0
        public void NullElementRemoveOne()
        {
            var master = new QuickList <object>(3);
            var result = new List <object> {
                null, 1, 2, null, 3
            };

            foreach (var r in result)
            {
                master.Add(r); // alias name of Push
            }

            master.Remove(null, 1);

            Assert.AreEqual(4, master.Count);

            var index = 0;

            if (master.Pop() == null)
            {
                index++;
            }
            if (master.Pop() == null)
            {
                index++;
            }
            if (master.Pop() == null)
            {
                index++;
            }
            if (master.Pop() == null)
            {
                index++;
            }

            Assert.AreEqual(0, master.Count);
            Assert.AreEqual(1, index);
        }
Example #26
0
        private void OnJoinerRemoved(ActiveListJoinerData <TLeft, TRight, TResult, TKey> data)
        {
            if (data.IsLeftJoiner)
            {
                _leftJoiners.Remove(data.SourceIndex);

                for (int i = data.SourceIndex; i < _leftJoiners.Count; ++i)
                {
                    _leftJoiners[i].SourceIndex = i;
                }
            }
            else
            {
                _rightJoiners.Remove(data.SourceIndex);

                for (int i = data.SourceIndex; i < _rightJoiners.Count; ++i)
                {
                    _rightJoiners[i].SourceIndex = i;
                }
            }

            UpdateIndices(data.GetTargetIndex(_leftJoiners.Count));
        }
Example #27
0
        /// <summary>
        /// 回收
        /// </summary>
        /// <param name="_t"></param>
        public void Recover(GameObject _t)
        {
            if (null == _t)
            {
                this.Warr("回收的对象为空,放弃回收");
                return;
            }

            ItemEntity poolEntity = _t.GetComponent<ItemEntity>();
            if (null == poolEntity)
            {
                this.Error("pool entity组件为空,无法回收");
                return;
            }

            if (FreePools.Count < MaxCount)
            {
                poolEntity.PoolRecoverEvent(); // 回收之前执行的事件
                // 执行回收事件
                OnRecoverAction(poolEntity);

                // push到Free队列中
                FreePools.Push(poolEntity);
            }
            else
            {
                poolEntity.IsDestroyTag = true; // 做一个标记,判断是否是非法销毁
                if (null != rawResResponse)
                {
                    rawResResponse.Destroy(_t);
                }
            }

            // 从使用队列中移除
            UsePools.Remove(poolEntity);
        }
Example #28
0
        public override void Update(Window window, Camera camera, Input input, float dt)
        {
            base.Update(window, camera, input, dt);
            #region  KeyInput

            //Delete all boxes;
            if (input.WasPushed(Key.Z))
            {
                for (var i = _createdObjects.Count - 1; i > 0; --i)
                {
                    var bodiIndex = _createdObjects[i];
                    var reference = new BodyReference(bodiIndex, Simulation.Bodies);
                    if (reference.LocalInertia.InverseMass > 0)
                    {
                        Simulation.Bodies.Remove(bodiIndex);
                        _createdObjects.RemoveAt(i);
                    }
                }
            }

            if (input.WasPushed(Key.X))
            {
                for (var j = 0; j < _numberOfLevels; j++)
                {
                    var startPosition = new Vector3(0, _floorHeight * j, _verticalHalfLenght * j);
                    for (int i = 0; i < _numberOfLoops * 2; i++)
                    {
                        CreateBoxes(startPosition);
                        startPosition.Z += _verticalHalfLenght * 2;
                    }
                }
            }
            var random = new Random(Guid.NewGuid().GetHashCode());


            //Randomly destroy
            if (input.WasPushed(Key.C))
            {
                for (var i = _createdObjects.Count - 1; i > 0; --i)
                {
                    var bodiIndex = _createdObjects[i];
                    var reference = new BodyReference(bodiIndex, Simulation.Bodies);
                    if ((reference.LocalInertia.InverseMass > 0) && random.Next(100) > 50)
                    {
                        Simulation.Bodies.Remove(bodiIndex);
                        _createdObjects.RemoveAt(i);
                    }
                }
            }

            _spawnCount += dt;
            if (_spawnCount >= _spawnTime)
            {
                _spawnCount -= _spawnTime;
                var boxPosition = new Vector3(-_horizontalHalfLenght + 1, 2, 0);
                var identity    = Quaternion.Identity;
                Instantiate(_boxDescription, ref boxPosition, ref identity);



                var deleteObject = random.Next(_createdObjects.Count - 1);
                var reference    = new BodyReference(deleteObject, Simulation.Bodies);
                if ((reference.LocalInertia.InverseMass > 0))
                {
                    Simulation.Bodies.Remove(deleteObject);
                    _createdObjects.Remove(deleteObject);
                }
            }


            for (var i = 0; i < _movingObjects.Count; i++)
            {
                ref var movingObject = ref _movingObjects[i];


                if (movingObject.IsMoving)
                {
                    var bodyReference  = new BodyReference(movingObject.BodyIndex, Simulation.Bodies);
                    var targetPosition = movingObject.StartPosition;
                    if (movingObject.IsMovingToOffset)
                    {
                        targetPosition += MovingOffset;
                    }

                    var linearError = targetPosition - bodyReference.Pose.Position;

                    if (linearError.LengthSquared() < .0001f)
                    {
                        bodyReference.Velocity.Linear = Vector3.Zero;
                        movingObject.IsMoving         = false;
                        movingObject.IsMovingToOffset = !movingObject.IsMovingToOffset;
                    }
                    else
                    {
                        var linearVelocity = linearError / dt;
                        bodyReference.Velocity.Linear = linearVelocity;
                        Simulation.Awakener.AwakenBody(bodyReference.Handle);
                    }
                }
                else
                {
                    movingObject.ToggleSleepTimer += dt;
                    if (movingObject.ToggleSleepTimer > SleepTime)
                    {
                        movingObject.ToggleSleepTimer = SleepTime * (float)random.NextDouble();
                        movingObject.IsMoving         = true;
                    }
                }
            }