Example #1
0
        public void AddTimer(Nuid id, string timer_name, long gap_millseconds, int count, NEventCallback callback)
        {
            if (gap_millseconds <= 0)
            {
                return;
            }

            if (count == 0)
            {
                return;
            }

            Tuple <Nuid, string> tuple = new Tuple <Nuid, string>(id, timer_name);

            if (_ObjectDic.ContainsKey(tuple))
            {
                return;
            }

            long now_time   = TimeUtils.NowMilliseconds;
            long start_time = now_time;
            long stop_time  = now_time + gap_millseconds;

            _Serial++;
            Timer timer = Timer.New(_Serial, id, timer_name, gap_millseconds, count, start_time, stop_time, callback);

            _TimerDic.Add(timer.Serial, timer);

            _ObjectDic.Add(tuple, timer.Serial);

            HashSet <int> timers = null;

            if (!_TimerHeap.TryGetValue(stop_time, out timers))
            {
                timers = new HashSet <int>();
                _TimerHeap.Add(stop_time, timers);
            }

            timers.Add(timer.Serial);
        }
Example #2
0
            public static Timer New(int new_serial, Nuid id, string name,
                                    long gap_ticks, int beat_count, long start_ticks, long stop_ticks, NEventCallback func)
            {
                Timer timer = new Timer();

                timer.Id              = id;
                timer.Name            = name;
                timer.GapTicks        = gap_ticks;
                timer.Func            = func;
                timer.RemainBeatCount = beat_count;
                timer.MaxBeatCount    = beat_count;
                timer.Serial          = new_serial;
                timer.StartTicks      = start_ticks;
                timer.StopTicks       = stop_ticks;

                return(timer);
            }
Example #3
0
 public void AddTimer(Nuid id, string timer_name, long over_millseconds, NEventCallback callback)
 {
     AddTimer(id, timer_name, over_millseconds, 1, callback);
 }