Ejemplo n.º 1
0
        public static void InnerDelete(Timer tm, bool removeFromMap)
        {
            tm.Delete = true;
            if (tm.Container != null)
            {
                tm.Container.Remove(tm);
                tm.Container = null;
            }

            if (removeFromMap)
            {
                MapSnTimer.Remove(tm.SN);
            }
        }
Ejemplo n.º 2
0
        public static void Tick(float deltaTime)
        {
            if (ExecuteTimers == null)
            {
                return;
            }

            NowTime  += deltaTime;
            PileSecs += deltaTime;
            int cycle = 0;

            while (PileSecs >= JiffiesSec)
            {
                PileSecs -= JiffiesSec;
                cycle++;
            }

            for (int i = 0; i < cycle; ++i)
            {
                LinkedList <Timer>     timers = Wheels[0].NextDial();
                LinkedListNode <Timer> node   = timers.First;
                for (int j = 0; j < timers.Count; ++j)
                {
                    Timer tm = node.Value;
                    ExecuteTimers.AddLast(tm);
                    node = node.Next;
                }

                timers.Clear();

                for (int j = 0; j < Wheels.Length; ++j)
                {
                    Wheel wheel = Wheels[j];
                    if (wheel.Head == Wheel.DialScale)
                    {
                        wheel.Head = 0;
                        if (wheel.NextWheel != null)
                        {
                            LinkedList <Timer>     tms     = wheel.NextWheel.NextDial();
                            LinkedListNode <Timer> tmsNode = tms.First;
                            for (int k = 0; k < tms.Count; ++k)
                            {
                                Timer tm = tmsNode.Value;
                                if (tm.Delete)
                                {
                                    MapSnTimer.Remove(tm.SN);
                                }
                                else
                                {
                                    InnerAdd(tm.Deadline, tm);
                                }

                                tmsNode = tmsNode.Next;
                            }

                            tms.Clear();
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            while (ExecuteTimers.Count > 0)
            {
                Timer tm = ExecuteTimers.First.Value;
                ExecuteTimers.Remove(tm);

                if (!tm.Delete && tm.Handler(tm.SN) && tm.Cycle > 0)
                {
                    InnerAdd(Now() + tm.Cycle, tm);
                }
                else
                {
                    MapSnTimer.Remove(tm.SN);
                }
            }
        }