From 401a6ba2d423d48bafb5022c80910e06b3a1f736 Mon Sep 17 00:00:00 2001 From: qydysky Date: Wed, 20 Jan 2021 16:53:01 +0800 Subject: [PATCH] =?utf8?q?Gtk=5Fdanmu=20=E4=BD=BF=E7=94=A8chan?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/gtk.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Reply/gtk.go b/Reply/gtk.go index c8285d6..3c16841 100644 --- a/Reply/gtk.go +++ b/Reply/gtk.go @@ -49,8 +49,8 @@ var keep_key = map[string]int{ var ( Gtk_on bool Gtk_img_path string = "face" - Gtk_danmu_pool_index uint - Gtk_danmu_pool = make(map[uint]Danmu_mq_t) + Gtk_danmu_chan = make(chan Danmu_mq_t,100) + imgbuf = struct{ b map[string](*gdk.Pixbuf) sync.Mutex @@ -72,9 +72,7 @@ func init(){ //使用带tag的消息队列在功能间传递消息 Danmu_mq.Pull_tag(map[string]func(interface{})(bool){ `danmu`:func(data interface{})(bool){//弹幕 - if int(Gtk_danmu_pool_index) - len(Gtk_danmu_pool) > 1e5 {Gtk_danmu_pool_index = 0} - Gtk_danmu_pool_index += 1 - Gtk_danmu_pool[Gtk_danmu_pool_index] = data.(Danmu_mq_t) + Gtk_danmu_chan <- data.(Danmu_mq_t) return false }, }) @@ -329,13 +327,14 @@ func Gtk_danmu() { } return }) - glib.TimeoutAdd(uint(1000 / (len(Gtk_danmu_pool) + 1)),func()(bool){ - for id,item := range Gtk_danmu_pool { - delete(Gtk_danmu_pool,id) + glib.TimeoutAdd(uint(1000 / (len(Gtk_danmu_chan) + 1)),func()(bool){ + select{ + case item := <- Gtk_danmu_chan: show(item.msg,load_face(item.uid)) return true + default: + return false } - return false }) } }() -- 2.39.2