Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
0
        public void EmptyListPop()
        {
            var master = new QuickList <object>();

            ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                master.Pop();
            });
        }
Exemple #4
0
    ///------------ Implementation ------------------
    private void _updateTickables(float fTime, float fRealTime)
    {
        int iLastDeadIndex = -1;
        int nCount         = _arrInQueueTickers.Count;

        Tickable[] arrTickers = _arrInQueueTickers._Buffer;
        __AliveTickableCount = 0;

        for (int i = 0; i < nCount; ++i)
        {
            Tickable pTicker = arrTickers[i];

            if (pTicker._IsDead)
            {
                iLastDeadIndex = i;
                continue;
            }

            __AliveTickableCount++;

            if (pTicker.status == TickerStatus.PUASED)
            {
                continue;
            }

            pTicker._Tick(pTicker._Scalable ? fTime : fRealTime);
        }

        if (iLastDeadIndex != -1)
        {
            Tickable lastDeadTicker = _arrInQueueTickers[iLastDeadIndex];

            lastDeadTicker._InQueue = false;

            if (iLastDeadIndex != _arrInQueueTickers.Count - 1)
            {
                _arrInQueueTickers[iLastDeadIndex] = _arrInQueueTickers.Pop();
            }
            else
            {
                _arrInQueueTickers.Pop();
            }
        }
    }
Exemple #5
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);
        }
Exemple #6
0
        public void NullElementPopTest()
        {
            var master = new QuickList <object>(3);
            var result = new List <object> {
                null, 1, 2, null, 3
            };

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

            result.Reverse();
            foreach (var r in result)
            {
                Assert.AreEqual(r, master.Pop());
            }
        }
Exemple #7
0
        public void UnShiftPopTest()
        {
            var num  = 50000;
            var lst  = new QuickList <int>();
            var rand = new System.Random();
            var lst2 = new List <int>();

            for (var i = 0; i < num; i++)
            {
                var v = rand.Next();
                lst.UnShift(v);
                lst2.Add(v);
            }
            foreach (var v in lst2)
            {
                Assert.AreEqual(v, lst.Pop());
            }
            Assert.AreEqual(0, lst.Count);
            Assert.AreEqual(0, lst.Length);
        }
Exemple #8
0
        public void FirstLastTest()
        {
            var master = new QuickList <int>(5);

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

            Assert.AreEqual(0, master.First());
            Assert.AreEqual(254, master.Last());

            for (var i = 0; i < 255; i++)
            {
                master.Shift();
                if (i < 254)
                {
                    Assert.AreEqual(i + 1, master.First());
                }
            }

            Assert.AreEqual(0, master.Count);

            master = new QuickList <int>(5);
            for (var i = 0; i < 255; i++)
            {
                master.Push(i);
            }

            for (var i = 0; i < 255; i++)
            {
                if (i < 254)
                {
                    Assert.AreEqual(254 - i, master.Last());
                }
                Assert.AreEqual(254 - i, master.Pop());
            }
        }
Exemple #9
0
        /// <summary>
        /// 获取一个空闲对象
        /// </summary>
        /// <returns></returns>
        public GameObject GetFree()
        {
            if (null == rawResResponse)
            {
                return null;
            }

            ItemEntity result = null;

            if (FreePools.Count <= 0)
            {
                result = CreateNewItem();
                if (null != result)
                {
                    result.transform.parent = groupNodeTransform; // 默认放在内存池节点下
                }
            }
            else
            {
                // 先从尾部pop出去
                result = FreePools.Pop();
                if (null == result) // 如果是回收时的对象已经是空对象,被Destroy掉了,那么取出来的时候,仍然可能是空的
                {
                    result = CreateNewItem(); // new的时候已经插入到链表头部了
                }
            }

            if (null != result)
            {
                result.PoolInitEvent();
                result.gameObject.SetActive(true); // 默认显示出来
                result.hideFlags = HideFlags.None;
                UsePools.Push(result); // 添加到使用队列中
                return result.gameObject;
            }

            return null;
        }
Exemple #10
0
        public void EmptyListPop()
        {
            var master = new QuickList <object>();

            Assert.AreEqual(null, master.Pop());
        }
Exemple #11
0
        public void Update(float timestamp)
        {
            if (m_pStatePoped != null)
            {
                m_pStatePoped.Pause();
                m_pStatePoped.Release();
                m_stateIndex--;

                if (m_stateIndex >= 0)
                {
                    m_pStateStack[m_stateIndex].Resume();
                }
                ResetTouch();

                m_pStatePoped = null;
            }

            if (m_pStatePushed.Count > 0)
            {
                gxGameState pState = m_pStatePushed.Pop();

                if (pState == null)
                {
                    Common.UDebug.Assert(false, "Tried to add a NULL state !!!");
                    ClearStateStack();
                }

                Common.UDebug.Assert(m_stateIndex < GAME_STATES_STACK_SIZE);

                gxGameState oldState = CurrentState();
                if (oldState != null)
                {
                    oldState.Pause();
                }
                m_stateIndex++;
                m_pStateStack[m_stateIndex] = pState;

                if (pState.Initalize() < 0)
                {
                    Common.UDebug.Assert(false, "Failed to create the current state!!!!");
                    ClearStateStack();
                }
                else
                {
                    pState.Resume();
                    pState.SetLoading(true);
                }
                ResetTouch();
            }

            if (m_stateIndex < 0)
            {
                return;
            }
            if (m_pStateStack[m_stateIndex].IsLoading())
            {
                m_pStateStack[m_stateIndex].SetLoading(m_pStateStack[m_stateIndex].Load());
            }
            else
            {
                m_pStateStack[m_stateIndex].Update(timestamp);
            }
        }