Esempio n. 1
0
        internal bool RemoveTimerTask(TimerTaskInfo taskInfo)
        {
            if (taskInfo == null || taskInfo.wheelIndex < 0 || taskInfo.wheelSlotIndex < 0 || taskInfo.taskListIndex < 0)
            {
                return(false);
            }
            if (!taskInfoDic.ContainsKey(taskInfo.index))
            {
                return(false);
            }

            if (taskInfo.wheelIndex < 0 || taskInfo.wheelIndex >= wheelArr.Length || wheelArr[taskInfo.wheelIndex] == null)
            {
                return(false);
            }

            taskInfoDic.Remove(taskInfo.index);

            int wheelIndex     = taskInfo.wheelIndex;
            int wheelSlotIndex = taskInfo.wheelSlotIndex;
            int taskListIndex  = taskInfo.taskListIndex;

            taskInfo.OnClear();

            return(wheelArr[wheelIndex].RemoveTimerTask(wheelSlotIndex, taskListIndex));
        }
Esempio n. 2
0
        private void OnTimerWheelTrigger(int index, List <TimerTask> taskList)
        {
            for (int i = 0; i < taskList.Count; i++)
            {
                TimerTask task = taskList[i];
                if (task == null)
                {
                    continue;
                }
                TimerTaskInfo taskInfo = null;
                if (!taskInfoDic.TryGetValue(task.index, out taskInfo))
                {
                    continue;
                }
                if (task.remainingWheelInMS == 0)
                {
                    task.OnTrigger();
                }

                if (taskInfo.IsClear())
                {
                    RecycleTimerTask(task);
                }
                else
                {
                    taskInfoDic.Remove(task.index);
                    taskInfo.OnClear();
                    if (task.IsValidTask())
                    {
                        AddTimerTask(task, taskInfo);
                    }
                    else
                    {
                        RecycleTimerTask(task);
                    }
                }
            }
        }