Author SHA1 Message Date
gouki 738b5c4452 tweak(wish-tree): 弹幕各行速度错落,每行屏上2~3条不压着
Publish Mini Program Dev Version / publish (push) Successful in 46s
- 顶部行回到12%
- 每行不同基准速度:树桩三行26/33/40秒、顶部22秒,不再整齐划一
- 同行弹幕速度也带±20%随机错落(seeded保证渲染一致)
- 每行屏上保持约2.5条:间隔=duration/2.5,但不小于完全进入时间
  (duration*0.3,保证下一条不压着前一条)和最小间隔3秒
2026-08-10 21:44:09 +00:00
gouki a45004bfb2 tweak(wish-tree): 弹幕改为自然首尾相接,不再一行一条
Publish Mini Program Dev Version / publish (push) Successful in 1m3s
- 顶部行 12%→14%,树桩3行 68/73/78→70/73/76(间隔3%)
- 核心:从'一行同一时刻只一条'改为'前一条完全进入屏幕后就出下一条'
  同一时刻屏上可有多条,但首尾相接不重叠,更接近真实弹幕
- 每行发射定时器间隔=duration*0.35(完全进入屏幕约需飘总路程35%)
- 弹幕播完后从列表移除,stop时清空屏上弹幕避免残留
2026-08-10 21:28:47 +00:00
gouki f468cf4b94 fix(deploy): add data volume and use port 8081 for lunar-server 2026-08-10 18:01:17 +00:00
gouki d6ce5cd0f3 fix(server): use pure-Go sqlite driver (glebarez/sqlite) for CGO_ENABLED=0 builds
Build and Publish Server / build (push) Successful in 3m22s
2026-08-10 17:47:36 +00:00
6 changed files with 98 additions and 46 deletions
+3 -1
View File
@@ -12,8 +12,10 @@ services:
working_dir: /app
volumes:
- /opt/lunar/production/current:/app
- /opt/lunar/production/data:/app/data
- /opt/lunar/production/.env:/app/.env
ports:
- "127.0.0.1:8080:8080" # 只监听本机,对外由 nginx 反代 lunar.neatcn.com
- "127.0.0.1:8081:8080" # 只监听本机,对外由 nginx 反代 lunar.neatcn.com
env_file:
- /opt/lunar/production/.env
restart: unless-stopped
+55 -34
View File
@@ -244,48 +244,65 @@ Page({
this.startDanmakuScheduler(cache.danmaku);
},
// 启动弹幕调度:每行同一时刻只播一条,前一条飘完再出下一条(循环)
// 启动弹幕调度:每行一个发射定时器,前一条完全进入屏幕后就出下一条,
// 同一行屏上保持 2~3 条,首尾相接不压着;各行速度不同、同行弹幕速度也错落
startDanmakuScheduler(rows) {
this.stopDanmakuScheduler();
this.danmakuRows = rows || [];
this.danmakuTimers = [];
this.danmakuSeq = 0; // 全局自增序号,保证每条 key 唯一
if (!this.danmakuRows.length) {
this.setData({ currentDanmaku: [] });
return;
}
const GAP = 1.5; // 同一行前一条飘完后,间隔再出下一条(秒)
// 屏上目标条数:同一行同时约 2.5 条
const ON_SCREEN = 2.5;
// 弹幕完全进入屏幕约需飘过总路程的 30%(不压着前一条的最小间隔)
const ENTER_RATIO = 0.3;
const MIN_INTERVAL = 3; // 同一行相邻两条最小间隔(秒)
// 每行独立调度:row 行的第 idx 条播完后,隔 GAP 秒播第 idx+1 条
const playRow = (row, idx) => {
// 往某行发射一条弹幕,返回该条的 duration(供调度下一条用)
const emit = (row, idx) => {
const rowData = this.danmakuRows[row];
if (!rowData) return;
if (!rowData) return 0;
const item = rowData.list[idx % rowData.list.length];
// 更新该行当前弹幕(用行号作为 key 保证 setData 局部刷新)
this.setData({
[`currentDanmaku[${row}]`]: {
key: `${row}-${idx % rowData.list.length}-${Date.now()}`,
id: item.id,
content: item.content,
author: item.author,
type: item.type,
top: rowData.top,
duration: rowData.duration,
},
});
// 前一条飘完 + 间隔后,播下一条
const timer = setTimeout(() => {
playRow(row, idx + 1);
}, (rowData.duration + GAP) * 1000);
this.danmakuTimers[row] = timer;
const seq = ++this.danmakuSeq;
const danmaku = {
key: `d${seq}`,
id: item.id,
content: item.content,
author: item.author,
type: item.type,
top: rowData.top,
duration: item.duration,
};
// 追加到屏上弹幕列表(构造新数组,避免索引冲突)
this.setData({ currentDanmaku: this.data.currentDanmaku.concat(danmaku) });
// 动画播完(飘到屏外)后,把这条从列表移除
const removeTimer = setTimeout(() => {
const list = this.data.currentDanmaku.filter((d) => d.key !== danmaku.key);
this.setData({ currentDanmaku: list });
}, item.duration * 1000);
this.danmakuTimers.push(removeTimer);
return item.duration;
};
// 初始化 currentDanmaku 数组长度,并启动每行
this.setData({ currentDanmaku: new Array(this.danmakuRows.length).fill(null) });
this.danmakuRows.forEach((_, row) => {
// 每行独立调度:按刚发射这条的速度决定下一条间隔,循环
this.danmakuRows.forEach((rowData, row) => {
let idx = 0;
const loop = () => {
const duration = emit(row, idx);
idx += 1;
// 下一条间隔:屏上保持约 2.5 条(duration/2.5),
// 但不小于“完全进入”时间(duration*0.3,不压着)和最小间隔
const interval = Math.max(duration / ON_SCREEN, duration * ENTER_RATIO, MIN_INTERVAL);
const timer = setTimeout(loop, interval * 1000);
this.danmakuTimers.push(timer);
};
// 各行错开启动,避免 4 行同时从右侧涌出
const startTimer = setTimeout(() => playRow(row, 0), row * 1200);
const startTimer = setTimeout(loop, row * 1500);
this.danmakuTimers.push(startTimer);
});
},
@@ -296,18 +313,21 @@ Page({
this.danmakuTimers.forEach((t) => clearTimeout(t));
this.danmakuTimers = [];
}
// 清空屏上弹幕,避免恢复时残留未播完的项
if (this.data.currentDanmaku && this.data.currentDanmaku.length) {
this.setData({ currentDanmaku: [] });
}
},
// 构建弹幕:共 4 行(行 0-2 树桩处三行,行 3 顶部置顶轮播下方)
// 按行分组返回,由 JS 定时器控制:同一行一条完毕后再出下一条,不重叠
// 每行速度不同、同行弹幕速度也带随机错落,避免太整齐;前一条完全进入后出下一条
buildDanmaku(list) {
const DURATION_BOTTOM = 30; // 树桩处一条飘完全屏的秒数(慢速)
const DURATION_TOP = 24; // 顶部行稍快一点
// 行位置(屏幕百分比):
// - 行3 顶部行紧贴置顶轮播下方(稍有空隙)
// - 行0-2 树桩处三行,第一条68%,三行紧凑(间隔5%
const ROW_TOPS = [68, 73, 78, 12];
const ROW_DURATIONS = [DURATION_BOTTOM, DURATION_BOTTOM, DURATION_BOTTOM, DURATION_TOP];
// - 行0-2 树桩处三行,第一条70%,三行紧凑(间隔3%
const ROW_TOPS = [70, 73, 76, 12];
// 每行基准速度(秒/次):各行不同,避免整齐划一
const ROW_BASE_DURATION = [26, 33, 40, 22];
// 轮流分配到 4 行
const rows = [[], [], [], []];
@@ -318,12 +338,13 @@ Page({
// 每行存该行的所有弹幕(带位置/时长),供定时器轮流播放
return rows.map((rowList, row) => ({
top: ROW_TOPS[row],
duration: ROW_DURATIONS[row],
list: rowList.map((w) => ({
list: rowList.map((w, i) => ({
id: w.id,
content: w.content,
author: w.author || '匿名',
type: w.type,
// 同行弹幕速度也带 ±20% 错落(seeded 保证每次渲染一致)
duration: Math.round(ROW_BASE_DURATION[row] * (0.8 + seeded(w.id != null ? w.id : i, row + 7) * 0.4)),
})),
})).filter((r) => r.list.length > 0);
},
+7 -7
View File
@@ -45,14 +45,14 @@
</swiper-item>
</swiper>
<!-- 弹幕层(超出30条的心愿缓缓飘过,每行一条完毕再出下一条) -->
<!-- 弹幕层(超出30条的心愿缓缓飘过,一条完全进入后出下一条) -->
<view class="danmaku-layer">
<block wx:for="{{currentDanmaku}}" wx:key="key" wx:if="{{item}}">
<view
class="danmaku-item {{item.type === 'paid' ? 'paid' : ''}}"
style="top: {{item.top}}%; animation-duration: {{item.duration}}s;"
>{{item.content}} · {{item.author}}</view>
</block>
<view
wx:for="{{currentDanmaku}}"
wx:key="key"
class="danmaku-item {{item.type === 'paid' ? 'paid' : ''}}"
style="top: {{item.top}}%; animation-duration: {{item.duration}}s;"
>{{item.content}} · {{item.author}}</view>
</view>
<!-- 边缘暗角 -->
+9 -2
View File
@@ -4,10 +4,10 @@ go 1.22
require (
github.com/gin-gonic/gin v1.9.1
github.com/glebarez/sqlite v1.11.0
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/joho/godotenv v1.5.1
gorm.io/driver/mysql v1.6.0
gorm.io/driver/sqlite v1.6.0
gorm.io/gorm v1.31.2
)
@@ -39,9 +39,16 @@ require (
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
golang.org/x/crypto v0.17.0 // indirect
modernc.org/libc v1.22.5 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.23.1 // indirect
)
+23 -1
View File
@@ -9,12 +9,18 @@ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583j
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw=
github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
@@ -33,6 +39,10 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@@ -59,6 +69,9 @@ github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZ
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -87,8 +100,9 @@ golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
@@ -103,4 +117,12 @@ gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ=
gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8=
gorm.io/gorm v1.31.2 h1:3o8FXNo9v9S858gil+3LlZA1LkCOzgb4g5BL64FgaCo=
gorm.io/gorm v1.31.2/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
+1 -1
View File
@@ -4,8 +4,8 @@ import (
"fmt"
"log"
"github.com/glebarez/sqlite"
"gorm.io/driver/mysql"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"github.com/gouki/lunar-server/internal/model"
)