//--------------------------------------------------------------------- void _onTimer(object data) { if (Closed) { return; } LastTimeJeffies += TmSpan; var delta_tm = LastTimeJeffies - TimerShaft.GetTimeJeffies(); var time_ev = new EbTimeEvent() { mExpires = TimerShaft.GetTimeJeffies() + delta_tm, onTime = _onTimer, mData = null }; TimerShaft.AddTimer(time_ev); float tm = (float)Stopwatch.Elapsed.TotalSeconds; Stopwatch.Reset(); Stopwatch.Start(); FuncCb(LuaTable, tm); }
//--------------------------------------------------------------------- // 修改一个时间事件的时间 public int ModTimer(EbTimeEvent time_event, ulong expires) { DelTimer(time_event); time_event.mExpires = expires; AddTimer(time_event); return(0); }
//--------------------------------------------------------------------- // 添加一个时间事件 public void AddTimer(EbTimeEvent time_event) { EbDoubleLinkNode <EbTimeEvent> timer_node = new EbDoubleLinkNode <EbTimeEvent>(); timer_node.mObject = time_event; MapEventNode[time_event] = timer_node; _addTimer(timer_node); }
//--------------------------------------------------------------------- // 删除一个时间事件 public int DelTimer(EbTimeEvent time_event) { if (MapEventNode.ContainsKey(time_event)) { EbDoubleLinkNode <EbTimeEvent> timer_node = MapEventNode[time_event]; MapEventNode.Remove(time_event); _delTimer(timer_node); } return(0); }
//--------------------------------------------------------------------- public EbTimer(TimerShaft timer_shaft, ulong tm, LuaTable lua_table, DelegateLua2 cb) { TimerShaft = timer_shaft; TmSpan = tm; LuaTable = lua_table; FuncCb = cb; LastTimeJeffies = TimerShaft.GetTimeJeffies() + TmSpan; Closed = false; Stopwatch = new Stopwatch(); Stopwatch.Start(); var time_ev = new EbTimeEvent() { mExpires = TimerShaft.GetTimeJeffies() + TmSpan, onTime = _onTimer, mData = null }; TimerShaft.AddTimer(time_ev); }