From: qydysky Date: Sun, 13 Dec 2020 12:12:44 +0000 (+0800) Subject: 消息队列优化 X-Git-Tag: v0.5.4~1^2~5 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=3707436bd81c8ee49a0da2dc804471cfc7d54a1c;p=bili_danmu%2F.git 消息队列优化 --- diff --git a/CV/Var.go b/CV/Var.go index a9240b8..c439ee1 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -24,7 +24,7 @@ type Danmu_Main_mq_item struct { Class string Data interface{} } -var Danmu_Main_mq = mq.New() +var Danmu_Main_mq = mq.New(10) //from player-loader-2.0.11.min.js /* diff --git a/README.md b/README.md index 7c954ca..e94e705 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,20 @@ gtk弹幕窗自定义人/事件消息停留/房间切换/弹幕格式化发送 ### 构建 本项目使用github action自动构建,构建过程详见[yml](https://github.com/qydysky/bili_danmu/blob/master/.github/workflows/go.yml) +构建tts需要ffplay,先行安装[ffmpeg](http://ffmpeg.org/download.html) + +``` +编译命令 +cd demo +go build -v -tags `tts` -o demo.exe -i main.go +``` + +构建gtk需要gtk3,先行安装[gtk](https://www.gtk.org/) +``` +编译命令 +cd demo +go build -v -tags `gtk gtk_3_24` -o demo.exe -i main.go +``` ### demo 前往[releases](https://github.com/qydysky/bili_danmu/releases)页下载对应系统版本。解压后进入`demo`目录(文件夹),运行`demo.run`(`demo.exe`)。 ``` diff --git a/Reply/F.go b/Reply/F.go index 0c159c5..729f0e6 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -14,6 +14,7 @@ import ( F "github.com/qydysky/bili_danmu/F" "github.com/christopher-dG/go-obs-websocket" p "github.com/qydysky/part" + s "github.com/qydysky/part/signal" ) /* @@ -211,8 +212,8 @@ func dtos(t time.Duration) string { //直播流保存 type Saveflv struct { path string - wait p.Signal - cancel p.Signal + wait *s.Signal + cancel *s.Signal } var saveflv = Saveflv { @@ -232,8 +233,8 @@ func Saveflvf(){ saveflv.path = strconv.Itoa(c.Roomid) + "_" + time.Now().Format("2006_01_02_15:04:05.000") - saveflv.wait.Init() - saveflv.cancel.Init() + saveflv.wait = s.Init() + saveflv.cancel = s.Init() rr := p.Req() go func(){ diff --git a/Reply/Reply.go b/Reply/Reply.go index 5f37655..c59a5bf 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -117,6 +117,7 @@ func (replyF) user_toast_msg(s string){ price := p.Json().GetValFromS(s, "data.price"); var sh []interface{} + var sh_log []interface{} if username != nil { sh = append(sh, username) @@ -135,7 +136,7 @@ func (replyF) user_toast_msg(s string){ } } if num != nil { - sh = append(sh, num, "x") + sh = append(sh, num, "个") } if unit != nil { sh = append(sh, unit) @@ -144,7 +145,7 @@ func (replyF) user_toast_msg(s string){ sh = append(sh, role_name) } if price != nil { - sh = append(sh, "ï¿¥", int(price.(float64)) / 1000) + sh_log = append(sh, "ï¿¥", int(price.(float64)) / 1000)//不在界面显示价格 c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//传入消息队列 Class:`c.Rev_add`, Data:price.(float64) / 1000, @@ -164,7 +165,7 @@ func (replyF) user_toast_msg(s string){ Gui_show(Itos(sh), "0buyguide") // Gui_show("====\n") - msglog.Base(1, "礼").Fileonly(true).I(sh...).Fileonly(false) + msglog.Base(1, "礼").Fileonly(true).I(sh_log...).Fileonly(false) } //HeartBeat-心跳用来传递人气值 @@ -226,6 +227,7 @@ func (replyF) guard_buy(s string){ price := p.Json().GetValFromS(s, "data.price"); var sh []interface{} + var sh_log []interface{} if username != nil { sh = append(sh, username) @@ -234,7 +236,7 @@ func (replyF) guard_buy(s string){ sh = append(sh, "购买了", gift_name) } if price != nil { - sh = append(sh, "ï¿¥", int(price.(float64)) / 1000) + sh_log = append(sh, "ï¿¥", int(price.(float64)) / 1000)//不在界面显示价格 } {//额外 ass Assf(fmt.Sprintln(sh...)) @@ -242,8 +244,8 @@ func (replyF) guard_buy(s string){ fmt.Println("\n====") fmt.Println(sh...) fmt.Print("====\n\n") + msglog.Base(1, "礼").Fileonly(true).I(sh_log...).Fileonly(false) - msglog.Base(1, "礼").Fileonly(true).I(sh...).Fileonly(false) } //Msg-房间信息改变,标题等 @@ -305,6 +307,7 @@ func (replyF) send_gift(s string){ total_coin := p.Json().GetValFromS(s, "data.total_coin"); var sh []interface{} + var sh_log []interface{} var allprice float64 if uname != nil { @@ -314,14 +317,14 @@ func (replyF) send_gift(s string){ sh = append(sh, action) } if num != nil { - sh = append(sh, num, "x") + sh = append(sh, num, "个") } if giftName != nil { sh = append(sh, giftName) } if total_coin != nil { allprice = total_coin.(float64) / 1000 - sh = append(sh, fmt.Sprintf("ï¿¥%.1f",allprice)) + sh_log = append(sh, fmt.Sprintf("ï¿¥%.1f",allprice))//不在界面显示价格 c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//传入消息队列 Class:`c.Rev_add`, Data:allprice, @@ -329,7 +332,7 @@ func (replyF) send_gift(s string){ } if len(sh) == 0 {return} - msglog.Base(1, "礼").Fileonly(true).I(sh...).Fileonly(false) + msglog.Base(1, "礼").Fileonly(true).I(sh_log...).Fileonly(false) //小于3万金瓜子 if allprice < 30 {msglog.T(sh...);return} @@ -436,7 +439,7 @@ func (replyF) super_chat_message(s string){ } logg := sh if price != nil { - sh = append(sh, "ï¿¥", price, "\n") + sh = append(sh, "\n")//界面不显示价格 logg = append(logg, "ï¿¥", price) c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//传入消息队列 Class:`c.Rev_add`, @@ -598,7 +601,7 @@ type Danmu_mq_t struct { uid string msg string } -var Danmu_mq = mq.New() +var Danmu_mq = mq.New(10) func Gui_show(m ...string){ //m[0]:msg m[1]:uid diff --git a/Reply/gtk.go b/Reply/gtk.go index 0fa13eb..4b30795 100644 --- a/Reply/gtk.go +++ b/Reply/gtk.go @@ -429,17 +429,17 @@ func Gtk_danmu() { var old_cu float64 {//平滑滚动效果 tmp := scrolledwindow0.GetVAdjustment() - h := viewport0.GetViewWindow().WindowGetHeight() glib.TimeoutAdd(uint(30),func()(true_value bool){ true_value = true if !in_smooth_roll {return} - g1h := viewport1.GetViewWindow().WindowGetHeight() - max := tmp.GetUpper() - float64(h - g1h) + h := viewport0.GetViewWindow().WindowGetHeight() + // g1h := viewport1.GetViewWindow().WindowGetHeight() + max := tmp.GetUpper() - float64(h) cu := tmp.GetValue() //用户在回看 if old_cu != 0 &&//非初始 - max - 100 > cu &&//当前位置低于max-100 + max - cu > 100 &&//当前位置低于100 old_cu != cu {//上一次滚动有移动 return } diff --git a/bili_danmu.go b/bili_danmu.go index a6ba32a..84d7aa5 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -70,6 +70,7 @@ func Demo(roomid ...int) { case `change_room`: c.Rev = 0.0 //营收 c.Renqi = 1//人气置1 + c.Title = `` change_room_chan <- true case `c.Rev_add`: c.Rev += d.Data.(float64) diff --git a/demo/go.mod b/demo/go.mod index eac7380..152c5be 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -10,7 +10,8 @@ require ( github.com/miekg/dns v1.1.35 // indirect github.com/mitchellh/mapstructure v1.4.0 // indirect github.com/qydysky/bili_danmu v0.5.2 - github.com/qydysky/part v0.3.1 // indirect + github.com/qydysky/part v0.3.3 // indirect + github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad // indirect github.com/shirou/gopsutil v3.20.11+incompatible // indirect golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c // indirect golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb // indirect diff --git a/demo/go.sum b/demo/go.sum index d37f73c..e415130 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -68,6 +68,12 @@ github.com/qydysky/part v0.2.2-0.20201119032922-a6f2c3476095 h1:xMahJIwZcpiRWg3L github.com/qydysky/part v0.2.2-0.20201119032922-a6f2c3476095/go.mod h1:93s9ohLtzULet5ZPEUUWrT9BELC30oDZgRpgGSiDye4= github.com/qydysky/part v0.3.1 h1:pyRSZQCWPsMSmn3XcEGFdwfhTdMczDomHi2+pfoiBdU= github.com/qydysky/part v0.3.1/go.mod h1:93s9ohLtzULet5ZPEUUWrT9BELC30oDZgRpgGSiDye4= +github.com/qydysky/part v0.3.2 h1:P+OKyv2doQoXlTQev2AjSL2MvoX2PLcJBRRDlSnpm94= +github.com/qydysky/part v0.3.2/go.mod h1:93s9ohLtzULet5ZPEUUWrT9BELC30oDZgRpgGSiDye4= +github.com/qydysky/part v0.3.3 h1:Xbz61YzHfEbeNZ5Fz1IxS6ktkV0Nk9bDsrxGWsKD9hE= +github.com/qydysky/part v0.3.3/go.mod h1:93s9ohLtzULet5ZPEUUWrT9BELC30oDZgRpgGSiDye4= +github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad h1:Jtzf509lQrkUMGTV0Sc6IDCAiR1VrBcHrIban7hpye4= +github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg= github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v2.20.8+incompatible h1:8c7Atn0FAUZJo+f4wYbN0iVpdWniCQk7IYwGtgdh1mY= github.com/shirou/gopsutil v2.20.8+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= diff --git a/demo/ui/1.glade b/demo/ui/1.glade index 733d2eb..7b2ab3f 100644 --- a/demo/ui/1.glade +++ b/demo/ui/1.glade @@ -8,6 +8,9 @@ mouse 400 500 + + + True @@ -52,6 +55,7 @@ True False + 2 vertical 3 2 diff --git a/ws.go b/ws.go index 5fe6a1c..50bc63f 100644 --- a/ws.go +++ b/ws.go @@ -7,10 +7,11 @@ import ( c "github.com/qydysky/bili_danmu/CV" p "github.com/qydysky/part" + s "github.com/qydysky/part/signal" ) type ws struct { - Signal p.Signal + Signal *s.Signal SendChan chan []byte RecvChan chan []byte TO int @@ -36,7 +37,7 @@ func (i *ws) Handle() (o *ws) { defer l.Block() if o.Signal.Islive() {return} - o.Signal.Init() + o.Signal = s.Init() if o.url == "" { l.E("o.url == \"\"")