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)); }
private bool AddTimerTask(TimerTask task, TimerTaskInfo taskInfo) { if (!task.IsValidTask()) { return(false); } for (int i = 0; i < wheelArr.Length; i++) { if (wheelArr[i].AddTimerTask(task, ref taskInfo.wheelSlotIndex, ref taskInfo.taskListIndex)) { taskInfo.wheelIndex = i; break; } } if (taskInfo.wheelIndex < 0 || taskInfo.wheelSlotIndex < 0 || taskInfo.taskListIndex < 0) { return(false); } taskIndex++; task.index = taskIndex; taskInfo.index = taskIndex; taskInfoDic.Add(taskInfo.index, taskInfo); return(true); }
public void RemoveTimer(int index) { if (timerTasks.ContainsKey(index)) { TimerTaskInfo taskInfo = timerTasks[index]; TimerManager.GetInstance().RemoveTimerTask(taskInfo); ClearTimer(index); } }
internal TimerTaskInfo AddTimerTask(TimerTask task) { TimerTaskInfo taskInfo = new TimerTaskInfo(); if (AddTimerTask(task, taskInfo)) { task.OnTaskStart(); return(taskInfo); } else { return(null); } }
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); } } } }
public int AddTimer(LuaTable timer, float interval, float total, LuaFunction startFun, LuaFunction intervalFun, LuaFunction endFun, object userData) { int infoIndex = timerIndex; LuaTimerData timerData = new LuaTimerData(); timerData.luaTimer = timer; timerData.startFunc = startFun; timerData.intervalFunc = intervalFun; timerData.endFunc = endFun; timerData.userData = userData; timerDatas.Add(infoIndex, timerData); TimerTaskInfo taskInfo = TimerManager.GetInstance().AddTimerTask(interval, total, OnTimerStart, OnTimerInterval, OnTimerEnd, infoIndex); timerTasks.Add(infoIndex, taskInfo); timerIndex++; return(infoIndex); }
public bool RemoveTimerTask(TimerTaskInfo taskInfo) { return(hTimerWheel.RemoveTimerTask(taskInfo)); }