diff --git a/app.go b/app.go index e7f0f7b..da6b5f1 100644 --- a/app.go +++ b/app.go @@ -59,15 +59,7 @@ func (this *app) init(userApp UserApp) { this.nowTime = time.Now() atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano()) _Timer = &Timer{} - /* - _Timer.Init( - func (context interface{}) int64 { - return q5.GetTickCount() - }, - nil, - 1000 * 60, - 5000) - */ + _Timer.init() _SysLog = new(SysLog_) _SysLog.Init() _TgLog = new(TGLog_) @@ -95,7 +87,7 @@ func (this *app) init(userApp UserApp) { func (this *app) unInit() { this.chGoLoopTimerExit <- 1 - //_Timer.UnInit() + _Timer.unInit() _Timer = nil this.userApp.UnInit() } @@ -106,7 +98,7 @@ func (this *app) run() { atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano()) beginTick := q5.GetTickCount() - _Timer.Update() + _Timer.update() this.dispatchIMMsg() this.userApp.Update() this.schedule() diff --git a/timer.go b/timer.go index 2c9895e..2f15c0c 100644 --- a/timer.go +++ b/timer.go @@ -9,23 +9,43 @@ type TimerWp struct { } type TimerAttacher struct { - q5.XTimerAttacher + *q5.XTimerAttacher } type Timer struct { timer *q5.XTimer } -func (this *Timer) Update() { +func (this *Timer) init() { + this.timer.Init( + func (context interface{}) int64 { + return q5.GetTickCount() + }, + nil, + 1000 * 60, + 5000) +} + +func (this *Timer) update() { this.timer.Update() } +func (this *Timer) unInit() { + this.timer.UnInit() +} + +func (this *Timer) NewTimerAttacher() *TimerAttacher { + ac := TimerAttacher{} + ac.XTimerAttacher = this.timer.NewTimerAttacher() + return &ac +} + func (this *Timer) SetTimeout(expireTime int32, cb q5.TimerCb) { this.timer.SetTimeout(expireTime, cb) } func (this *Timer) SetTimeoutEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) { - this.timer.SetTimeoutEx(expireTime, cb, &ac.XTimerAttacher) + this.timer.SetTimeoutEx(expireTime, cb, ac.XTimerAttacher) } func (this *Timer) SetTimeoutWp(expireTime int32, cb q5.TimerCb) *TimerWp { @@ -36,7 +56,7 @@ func (this *Timer) SetTimeoutWp(expireTime int32, cb q5.TimerCb) *TimerWp { func (this *Timer) SetTimeoutExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp { wp := TimerWp{} - wp.XTimerWp = this.timer.SetTimeoutExWp(expireTime, cb, &ac.XTimerAttacher) + wp.XTimerWp = this.timer.SetTimeoutExWp(expireTime, cb, ac.XTimerAttacher) return &wp } @@ -45,7 +65,7 @@ func (this *Timer) SetInterval(expireTime int32, cb q5.TimerCb) { } func (this *Timer) SetIntervalEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) { - this.timer.SetIntervalEx(expireTime, cb, &ac.XTimerAttacher) + this.timer.SetIntervalEx(expireTime, cb, ac.XTimerAttacher) } func (this *Timer) SetIntervalWp(expireTime int32, cb q5.TimerCb) *TimerWp { @@ -56,10 +76,22 @@ func (this *Timer) SetIntervalWp(expireTime int32, cb q5.TimerCb) *TimerWp { func (this *Timer) SetIntervalExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp { wp := TimerWp{} - wp.XTimerWp = this.timer.SetIntervalExWp(expireTime, cb, &ac.XTimerAttacher) + wp.XTimerWp = this.timer.SetIntervalExWp(expireTime, cb, ac.XTimerAttacher) return &wp } func (this *Timer) GetIdleTime() int64 { - return this.GetIdleTime() + return this.timer.GetIdleTime() +} + +func (this *Timer) ModifyTimer(timerWp *TimerWp, expireTime int32) { + this.timer.ModifyTimer(timerWp.XTimerWp, expireTime) +} + +func (this *Timer) Delete(timerWp *TimerWp) { + this.timer.Delete(timerWp.XTimerWp) +} + +func (this *Timer) GetRemainTime(timerWp *TimerWp) int64 { + return this.timer.GetRemainTime(timerWp.XTimerWp) }