Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
0
        public static int Add(IntPtr l)
        {
            int result;

            try
            {
                int num = LuaDLL.pua_gettop(l);
                if (num == 2)
                {
                    int delay;
                    LuaObject.checkType(l, 1, out delay);
                    LuaDelegate ld;
                    LuaObject.checkType(l, 2, out ld);
                    Action <int> action;
                    if (ld.d != null)
                    {
                        action = (Action <int>)ld.d;
                    }
                    else
                    {
                        IntPtr ml = LuaState.get(l).L;
                        action = delegate(int id)
                        {
                            int num2 = LuaObject.pushTry(ml);
                            LuaObject.pushValue(ml, id);
                            ld.pcall(1, num2);
                            LuaDLL.pua_settop(ml, num2 - 1);
                        };
                    }
                    ld.d = action;
                    LuaObject.pushValue(l, true);
                    LuaObject.pushValue(l, LuaTimer.add(delay, action));
                    result = 2;
                }
                else if (num == 3)
                {
                    int delay2;
                    LuaObject.checkType(l, 1, out delay2);
                    int cycle;
                    LuaObject.checkType(l, 2, out cycle);
                    LuaDelegate ld;
                    LuaObject.checkType(l, 3, out ld);
                    Func <int, bool> func;
                    if (ld.d != null)
                    {
                        func = (Func <int, bool>)ld.d;
                    }
                    else
                    {
                        IntPtr ml = LuaState.get(l).L;
                        func = delegate(int id)
                        {
                            int num2 = LuaObject.pushTry(ml);
                            LuaObject.pushValue(ml, id);
                            ld.pcall(1, num2);
                            bool result2 = LuaDLL.pua_toboolean(ml, -1);
                            LuaDLL.pua_settop(ml, num2 - 1);
                            return(result2);
                        };
                    }
                    ld.d = func;
                    LuaObject.pushValue(l, true);
                    LuaObject.pushValue(l, LuaTimer.add(delay2, cycle, func));
                    result = 2;
                }
                else
                {
                    result = LuaObject.error(l, "Argument error");
                }
            }
            catch (Exception e)
            {
                result = LuaObject.error(l, e);
            }
            return(result);
        }
Ejemplo n.º 3
0
 private static void innerDel(LuaTimer.Timer tm)
 {
     LuaTimer.innerDel(tm, true);
 }