]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
消息队列优化
authorqydysky <qydysky@foxmail.com>
Sun, 13 Dec 2020 12:12:44 +0000 (20:12 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 13 Dec 2020 12:12:44 +0000 (20:12 +0800)
CV/Var.go
README.md
Reply/F.go
Reply/Reply.go
Reply/gtk.go
bili_danmu.go
demo/go.mod
demo/go.sum
demo/ui/1.glade
ws.go

index a9240b8905c851bf18104a803594b5461954981e..c439ee1034e107c63c5bf5c5ad190f3acdeb50f3 100644 (file)
--- 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
 /*
index 7c954cab1319ce1bf563169c0761aded563c516c..e94e7056a4d49bafae740346340e30eeb3e53d7f 100644 (file)
--- 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`)。
 ```
index 0c159c52259a2f5e3e3c720113448d703e2512f9..729f0e6b60adb0972d8e0c35c86b06ba7f8cc666 100644 (file)
@@ -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(){
index 5f37655efd9520c85250af4819c56a57e5f2d731..c59a5bfb7d6b33742c61c69afe6efd202ff100f9 100644 (file)
@@ -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
index 0fa13ebefebdc97a211a24ab58c3fb0d4bb42211..4b307955340280a9030f8f97ec666dd8c7b6b55a 100644 (file)
@@ -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
                                }
index a6ba32a4dbba96bceca7054d4629187e4ea3ac60..84d7aa50542a7282dbe6b8b5b8379ad2364c9f8d 100644 (file)
@@ -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)
index eac7380af8a5249ff28ae6528e2b43d4e68c79de..152c5be1d4b7929dde63fc16e80ef87ad89ad2f9 100644 (file)
@@ -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
index d37f73c3b6e554110707898087de8b1f56b435cc..e415130d608eba5fd05b3400109adbc6fc880e46 100644 (file)
@@ -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=
index 733d2eb4a52209e11eccb020b098fff83d008c2b..7b2ab3f20ea08d7d37bfc669eed8f94d731a1cab 100644 (file)
@@ -8,6 +8,9 @@
     <property name="window_position">mouse</property>
     <property name="default_width">400</property>
     <property name="default_height">500</property>
+    <child>
+      <placeholder/>
+    </child>
     <child>
       <object class="GtkGrid">
         <property name="visible">True</property>
@@ -52,6 +55,7 @@
               <object class="GtkGrid" id="grid1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="margin_top">2</property>
                 <property name="orientation">vertical</property>
                 <property name="row_spacing">3</property>
                 <property name="column_spacing">2</property>
diff --git a/ws.go b/ws.go
index 5fe6a1c0ffb650c2fe2301956cc541bd60338f65..50bc63f208731a2fb14804d0b2436c77d6eb4772 100644 (file)
--- 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 == \"\"")