示例#1
0
文件: BTimer.cs 项目: WhitePetal/ARPG
        private void RemoveFrameListItem(int index)
        {
            if (frameTaskList.Count == 0 && tempFrameTaskList.Count == 0)
            {
                return;
            }

            FrameTask task = frameTaskList[index];

            RemoveListItem_FrameTask(frameTaskList, index);
            if (index < frameTaskList.Count)
            {
                FrameTask indexTask = frameTaskList[index];
                TaskFlag  flag      = new TaskFlag
                {
                    id     = indexTask.id,
                    index  = index,
                    active = true
                };
                idDic[indexTask.id] = flag;
            }

            delIds.Add(task.id);
            //idDic.Remove(task.id);
        }
示例#2
0
文件: BTimer.cs 项目: WhitePetal/ARPG
        public bool ReplaceFrameTask(int id, Action <int> callBack, int delay, int count = 1)
        {
            int       destFrame = sinceframeCount + delay;
            FrameTask task      = new FrameTask
            {
                id        = id,
                delay     = delay,
                destFrame = destFrame,
                callBack  = callBack,
                count     = count
            };

            if (idDic.ContainsKey(id) && idDic[id].active)
            {
                frameTaskList[idDic[id].index] = task;
                return(true);
            }
            else
            {
                for (int i = 0; i < tempFrameTaskList.Count; i++)
                {
                    if (tempFrameTaskList[i].id == id)
                    {
                        tempFrameTaskList[i] = task;
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#3
0
文件: BTimer.cs 项目: WhitePetal/ARPG
        public IDPack AddFrameTask(Action <int> callBack, int delay, int count = 1)
        {
            int destFrame = sinceframeCount + delay;

            int id = GetId();

            if (id == -1)
            {
                return(new IDPack(id, TaskType.FrameTask));
            }

            idDic[id] = new TaskFlag(idDic[id], TaskType.FrameTask);
            FrameTask task = new FrameTask
            {
                id        = id,
                delay     = delay,
                destFrame = destFrame,
                callBack  = callBack,
                count     = count
            };

            lock (lockFrame)
            {
                tempFrameTaskList.Add(task);
            }

            return(new IDPack(id, TaskType.FrameTask));
        }
示例#4
0
文件: BTimer.cs 项目: WhitePetal/ARPG
        private void FrameTaskTick()
        {
            if (tempFrameTaskList.Count > 0)
            {
                lock (lockFrame)
                {
                    for (int i = 0; i < tempFrameTaskList.Count; i++)
                    {
                        AddFrameListItem(tempFrameTaskList[i]);
                    }
                    tempFrameTaskList.Clear();
                }
            }


            for (int i = 0; i < frameTaskList.Count; i++)
            {
                FrameTask task = frameTaskList[i];
                if (sinceframeCount < task.destFrame)
                {
                    continue;
                }
                else
                {
                    Action <int> cb = task.callBack;
                    try
                    {
                        if (cb != null && taskHandle != null)
                        {
                            taskHandle.Invoke(cb, task.id);
                        }
                        else if (cb != null)
                        {
                            cb.Invoke(task.id);
                        }
                    }
                    catch (Exception e)
                    {
                        LogInfo(e.ToString(), LogLevel.Error);
                    }
                }

                if (task.count == 1)
                {
                    RemoveFrameListItem(i);
                    //deleteIds.Add(task.id);
                }
                else
                {
                    if (task.count > 0)
                    {
                        --task.count;
                    }
                    task.destFrame  += task.delay;
                    frameTaskList[i] = task;
                }
            }

            ++sinceframeCount;
        }
示例#5
0
文件: BTimer.cs 项目: WhitePetal/ARPG
        private void RemoveListItem_FrameTask(List <FrameTask> list, int index)
        {
            int       last = list.Count - 1;
            FrameTask temp = list[index];

            list[index] = list[last];
            list[last]  = temp;
            list.RemoveAt(last);
        }
示例#6
0
文件: BTimer.cs 项目: WhitePetal/ARPG
        private void AddFrameListItem(FrameTask task)
        {
            TaskFlag flag = new TaskFlag
            {
                id     = task.id,
                index  = frameTaskList.Count,
                active = true
            };

            idDic[task.id] = flag;
            frameTaskList.Add(task);
        }