From c6e0d84c1d4a3aaf4cd3e1b132a556c55e172d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Tue, 11 Nov 2025 01:25:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(fight):=20=E4=BF=AE=E5=A4=8D=E6=88=98?= =?UTF-8?q?=E6=96=97=E6=B1=A0=E6=8F=90=E4=BA=A4=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=88=9D=E5=A7=8B=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整了 Fightpool 的初始化参数以减少资源占用,并优化了战斗循环的提交逻辑, 避免在池满时出现未处理的错误。同时添加了上下文日志记录以便调试。 --- logic/service/fight/fightc.go | 23 ++++++++++++++--------- logic/service/fight/playeraction.go | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index af2ebb81..e6ede778 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -2,11 +2,13 @@ package fight import ( "blazing/common/utils" + "blazing/cool" "blazing/logic/service/common" "blazing/logic/service/fight/action" "blazing/logic/service/fight/info" "blazing/logic/service/fight/input" "blazing/modules/blazing/model" + "context" "fmt" "math/rand" "reflect" @@ -189,18 +191,21 @@ func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.Pla if !ok { return nil } + i := Fightpool.Free() + if i <= 0 { + Fightpool.Tune(Fightpool.Cap() + 1) + cool.Loger.Error(context.Background(), "Fightpool is full") - defer func() { - rr := Fightpool.Submit(f.battleLoop) - if rr != nil { - panic(rr) - } - f.Broadcast(func(ff *input.Input) { + } + rr := Fightpool.Submit(f.battleLoop) + if rr != nil { + panic(rr) + } + f.Broadcast(func(ff *input.Input) { - ff.Player.SendNoteReadyToFightInfo(f.Info) + ff.Player.SendNoteReadyToFightInfo(f.Info) - }) - }() + }) return f } diff --git a/logic/service/fight/playeraction.go b/logic/service/fight/playeraction.go index df017571..631f6688 100644 --- a/logic/service/fight/playeraction.go +++ b/logic/service/fight/playeraction.go @@ -158,6 +158,6 @@ func (f *FightC) ReadyFight(c common.PlayerI) { var Fightpool *ants.MultiPool func init() { - Fightpool, _ = ants.NewMultiPool(100, 10, ants.LeastTasks) + Fightpool, _ = ants.NewMultiPool(1, 1, ants.LeastTasks) //defer p.Release() }