diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index af2ebb819..e6ede7780 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 df0175713..631f6688f 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() }