Exemplo n.º 1
0
            internal void add(int delay, LuaTimer.Timer tm)
            {
                int num = (this.head + (delay - (this.dialSize - LuaTimer.jiffies_msec)) / this.dialSize) % LuaTimer.Wheel.dial_scale;
                LinkedList <LuaTimer.Timer> linkedList = this.vecDial[num];

                linkedList.AddLast(LuaTimer.GetTimerNodeFormPool(tm));
                tm.container = linkedList;
            }
Exemplo n.º 2
0
 internal static int add(int delay, int cycle, Func <int, bool> handler)
 {
     LuaTimer.Timer timer = new LuaTimer.Timer();
     timer.sn      = LuaTimer.fetchSn();
     timer.cycle   = cycle;
     timer.handler = handler;
     timer.delete  = false;
     LuaTimer.mapSnTimer[timer.sn] = timer;
     LuaTimer.innerAdd(LuaTimer.now() + delay, timer);
     return(timer.sn);
 }
Exemplo n.º 3
0
        private static LinkedListNode <LuaTimer.Timer> GetTimerNodeFormPool(LuaTimer.Timer timer)
        {
            LinkedListNode <LuaTimer.Timer> linkedListNode;

            if (LuaTimer.TIMER_NODE_POOL.Count == 0)
            {
                linkedListNode = new LinkedListNode <LuaTimer.Timer>(timer);
            }
            else
            {
                linkedListNode       = LuaTimer.TIMER_NODE_POOL.Dequeue();
                linkedListNode.Value = timer;
            }
            return(linkedListNode);
        }
Exemplo n.º 4
0
        private static void innerAdd(int deadline, LuaTimer.Timer tm)
        {
            tm.deadline = deadline;
            int num = Math.Max(0, deadline - LuaTimer.now());

            LuaTimer.Wheel wheel = LuaTimer.wheels[LuaTimer.wheels.Length - 1];
            for (int i = 0; i < LuaTimer.wheels.Length; i++)
            {
                LuaTimer.Wheel wheel2 = LuaTimer.wheels[i];
                if (num < wheel2.timeRange)
                {
                    wheel = wheel2;
                    break;
                }
            }
            wheel.add(num, tm);
        }
Exemplo n.º 5
0
 private static void innerDel(LuaTimer.Timer tm, bool removeFromMap)
 {
     tm.delete = true;
     if (tm.container != null)
     {
         LinkedListNode <LuaTimer.Timer> linkedListNode = tm.container.Find(tm);
         if (linkedListNode != null)
         {
             tm.container.Remove(linkedListNode);
             LuaTimer.RecycleTimerNodeToPool(linkedListNode);
         }
         tm.container = null;
     }
     if (removeFromMap)
     {
         LuaTimer.mapSnTimer.Remove(tm.sn);
     }
 }
Exemplo n.º 6
0
        internal static void tick(float deltaTime)
        {
            LuaTimer.nowTime  += deltaTime;
            LuaTimer.pileSecs += deltaTime;
            int num = 0;

            while (LuaTimer.pileSecs >= LuaTimer.jiffies_sec)
            {
                LuaTimer.pileSecs -= LuaTimer.jiffies_sec;
                num++;
            }
            for (int i = 0; i < num; i++)
            {
                LinkedList <LuaTimer.Timer>     linkedList     = LuaTimer.wheels[0].nextDial();
                LinkedListNode <LuaTimer.Timer> linkedListNode = linkedList.First;
                for (int j = 0; j < linkedList.Count; j++)
                {
                    LuaTimer.Timer value = linkedListNode.Value;
                    LuaTimer.executeTimers.AddLast(LuaTimer.GetTimerNodeFormPool(value));
                    linkedListNode = linkedListNode.Next;
                }
                while (linkedList.Count > 0)
                {
                    LinkedListNode <LuaTimer.Timer> first = linkedList.First;
                    linkedList.RemoveFirst();
                    LuaTimer.RecycleTimerNodeToPool(first);
                }
                for (int k = 0; k < LuaTimer.wheels.Length; k++)
                {
                    LuaTimer.Wheel wheel = LuaTimer.wheels[k];
                    if (wheel.head != LuaTimer.Wheel.dial_scale)
                    {
                        break;
                    }
                    wheel.head = 0;
                    if (wheel.nextWheel != null)
                    {
                        LinkedList <LuaTimer.Timer>     linkedList2     = wheel.nextWheel.nextDial();
                        LinkedListNode <LuaTimer.Timer> linkedListNode2 = linkedList2.First;
                        for (int l = 0; l < linkedList2.Count; l++)
                        {
                            LuaTimer.Timer value2 = linkedListNode2.Value;
                            if (value2.delete)
                            {
                                LuaTimer.mapSnTimer.Remove(value2.sn);
                            }
                            else
                            {
                                LuaTimer.innerAdd(value2.deadline, value2);
                            }
                            linkedListNode2 = linkedListNode2.Next;
                        }
                        while (linkedList2.Count > 0)
                        {
                            LinkedListNode <LuaTimer.Timer> first2 = linkedList2.First;
                            linkedList2.RemoveFirst();
                            LuaTimer.RecycleTimerNodeToPool(first2);
                        }
                    }
                }
            }
            while (LuaTimer.executeTimers.Count > 0)
            {
                LinkedListNode <LuaTimer.Timer> first3 = LuaTimer.executeTimers.First;
                LuaTimer.Timer value3 = first3.Value;
                LuaTimer.RecycleTimerNodeToPool(first3);
                LuaTimer.executeTimers.RemoveFirst();
                if (!value3.delete && value3.handler(value3.sn) && value3.cycle > 0)
                {
                    LuaTimer.innerAdd(LuaTimer.now() + value3.cycle, value3);
                }
                else
                {
                    LuaTimer.mapSnTimer.Remove(value3.sn);
                }
            }
        }
Exemplo n.º 7
0
 private static void innerDel(LuaTimer.Timer tm)
 {
     LuaTimer.innerDel(tm, true);
 }