fix(fight): 修复战斗池提交逻辑并调整初始配置

调整了 Fightpool 的初始化参数以减少资源占用,并优化了战斗循环的提交逻辑,
避免在池满时出现未处理的错误。同时添加了上下文日志记录以便调试。
This commit is contained in:
2025-11-11 01:25:20 +08:00
parent da9286d3d8
commit c6e0d84c1d
2 changed files with 15 additions and 10 deletions

View File

@@ -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
}

View File

@@ -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()
}