From 6aa5ba1546beb17e9dc6055fe672dce1d4164686 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Aug 2023 17:55:34 +0800 Subject: [PATCH] 1 --- app.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app.go b/app.go index 3d48f14..7edb974 100644 --- a/app.go +++ b/app.go @@ -29,9 +29,11 @@ type App_ struct { imMsgHandlers [1024]func(int16,*q5.XParams) maxRunDelay int64 maxScheduleTime int64 + updateFunc func () } -func (this *App_) Init() { +func (this *App_) Init(updateFunc func ()) { + this.updateFunc = updateFunc this.nowTime = time.Now() atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano()) _Timer = &q5.Timer{} @@ -86,18 +88,13 @@ func (this *App_) Run() { beginTick := q5.GetTickCount() _Timer.Update() this.dispatchIMMsg() + this.updateFunc() + this.schedule() endTick := q5.GetTickCount() if this.maxRunDelay < endTick - beginTick { this.maxRunDelay = endTick - beginTick } - - this.schedule() - endTick = q5.GetTickCount() - if this.maxScheduleTime < endTick - beginTick { - this.maxScheduleTime = endTick - beginTick - } - } } @@ -172,6 +169,10 @@ func (this *App_) schedule() { this.loopCond.L.Unlock() } +func (this *App_) NotifyLoopCond() { + this.loopCond.Broadcast() +} + func (this *App_) NowUnix() int64 { return this.nowUnixNano / int64(time.Second) }