public void Update() { TimeItem item = null; m_CurrentUnScaleTime = Time.unscaledTime; m_CurrentScaleTime = Time.time; #region 受缩放影响定时器更新 while ((item = m_UnScaleTimeHeap.Top()) != null) { if (!item.isEnable) { m_UnScaleTimeHeap.Pop(); item.Recycle2Cache(); continue; } if (item.sortScore < m_CurrentUnScaleTime) { m_UnScaleTimeHeap.Pop(); item.OnTimeTick(); if (item.isEnable && item.NeedRepeat()) { Post2Really(item); } else { item.Recycle2Cache(); } } else { break; } } #endregion #region 受缩放影响定时器更新 while ((item = m_ScaleTimeHeap.Top()) != null) { if (!item.isEnable) { m_ScaleTimeHeap.Pop(); item.Recycle2Cache(); continue; } if (item.sortScore < m_CurrentScaleTime) { m_ScaleTimeHeap.Pop(); item.OnTimeTick(); if (item.isEnable && item.NeedRepeat()) { Post2Scale(item); } else { item.Recycle2Cache(); } } else { break; } } #endregion }
public override void StartTest() { //测试范围:1创建,2,数组创建,3.插入,4,弹出,重建,指定位置重建,指定位置删除 BinaryHeap <IntWrap> heap1 = new BinaryHeap <IntWrap>(10, eBinaryHeapSortMode.kMin); BinaryHeap <IntWrap> heap2 = new BinaryHeap <IntWrap>(10, eBinaryHeapSortMode.kMin); IntWrap[] mTestData = BuildRandomIntWrapArray(20);//BuildIntWrapArray(new int[]{ 10, 121, 11, 15, 18, 21, 7, 99, 182, 0, 87, 26, 21 }); //TimeDebugger.S.Begin("Insert:NLog"); heap1.Insert(mTestData, eBinaryHeapBuildMode.kNLog); //TimeDebugger.S.End(); //TimeDebugger.S.Begin("Insert:N"); heap2.Insert(mTestData, eBinaryHeapBuildMode.kN); //TimeDebugger.S.End(); //TimeDebugger.S.Dump(); WriteBegin("BinaryHeap"); IntWrap insertItem = new IntWrap(39); heap1.Insert(insertItem); int oldIndex = insertItem.heapIndex; IntWrap findResult = heap1.GetElement(oldIndex); if (insertItem.Equals(findResult)) { WriteLine("## Success: Find Old Element In Index"); } insertItem.sortScore = 7; insertItem.RebuildHeap(heap1); int newIndex = insertItem.heapIndex; findResult = heap1.GetElement(newIndex); if (insertItem.Equals(findResult)) { WriteLine("## Success: Find New Element In Index"); } WriteLine("## InserTest: OldIndex:{0}, newIndex:{1}", oldIndex, insertItem.heapIndex); IntWrap element = null; int processCount = 0; heap1.Sort(eBinaryHeapSortMode.kMax); newIndex = insertItem.heapIndex; WriteLine("## InsertTest: NewIndex After Sort:{0}", newIndex); heap1.RemoveAt(insertItem.heapIndex); while (heap1.HasValue() && ++processCount < 100) { element = heap1.Pop(); if (element != null) { Write(" " + element.sortScore); } else { Write(" NULL"); } } WriteLine(""); WriteEnd("BinaryHeap"); }