优化代码结构,移除未使用的依赖和冗余代码
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/gogf/gf/v2/database/gredis"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/i18n/gi18n"
|
||||
"github.com/gogf/gf/v2/os/gbuild"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
@@ -19,9 +18,9 @@ var (
|
||||
CacheEPS = gcache.New() // 定义全局缓存对象 供EPS使用
|
||||
CacheManager = gcache.New() // 定义全局缓存对象 供其他业务使用
|
||||
ProcessFlag = guid.S() // 定义全局进程标识
|
||||
RunMode = "dev" // 定义全局运行模式
|
||||
IsRedisMode = false // 定义全局是否为redis模式
|
||||
I18n = gi18n.New() // 定义全局国际化对象
|
||||
// RunMode = "dev" // 定义全局运行模式
|
||||
IsRedisMode = false // 定义全局是否为redis模式
|
||||
I18n = gi18n.New() // 定义全局国际化对象
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -34,13 +33,13 @@ func init() {
|
||||
redisConfig = &gredis.Config{}
|
||||
)
|
||||
Logger.Debug(ctx, "module cool init start ...", gtime.Now())
|
||||
buildData := gbuild.Data()
|
||||
if _, ok := buildData["mode"]; ok {
|
||||
RunMode = buildData["mode"].(string)
|
||||
}
|
||||
if RunMode == "cool-tools" {
|
||||
return
|
||||
}
|
||||
// buildData := gbuild.Data()
|
||||
// if _, ok := buildData["mode"]; ok {
|
||||
// RunMode = buildData["mode"].(string)
|
||||
// }
|
||||
// if RunMode == "cool-tools" {
|
||||
// return
|
||||
// }
|
||||
redisVar, err := g.Cfg().Get(ctx, "redis.cool")
|
||||
if err != nil {
|
||||
Logger.Error(ctx, "初始化缓存失败,请检查配置文件")
|
||||
@@ -54,7 +53,7 @@ func init() {
|
||||
}
|
||||
CacheManager.SetAdapter(gcache.NewAdapterRedis(redis))
|
||||
IsRedisMode = true
|
||||
g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(redis)) //设置数据库
|
||||
// g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(redis)) //设置数据库
|
||||
}
|
||||
//Logerebug(ctx, "当前运行模式", RunMode)
|
||||
Logger.Debug(ctx, "当前实例ID:", ProcessFlag)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/mhmtszr/concurrent-swiss-map/maphash"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
|
||||
"github.com/mhmtszr/concurrent-swiss-map/swiss"
|
||||
)
|
||||
@@ -17,7 +16,7 @@ type CsMap[K comparable, V any] struct {
|
||||
shards []shard[K, V]
|
||||
shardCount uint64
|
||||
size uint64
|
||||
pool *ants.Pool
|
||||
//pool *ants.Pool
|
||||
}
|
||||
|
||||
type HashShardPair[K comparable, V any] struct {
|
||||
@@ -48,7 +47,7 @@ func New[K comparable, V any](options ...OptFunc[K, V]) *CsMap[K, V] {
|
||||
for i := 0; i < int(m.shardCount); i++ {
|
||||
m.shards[i] = shard[K, V]{items: swiss.NewMap[K, V](uint32((m.size / m.shardCount) + 1)), RWMutex: &sync.RWMutex{}}
|
||||
}
|
||||
m.pool, _ = ants.NewPool(-1)
|
||||
//m.pool, _ = ants.NewPool(-1)
|
||||
return &m
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/player"
|
||||
|
||||
"blazing/cool"
|
||||
@@ -44,7 +43,7 @@ func cleanup() {
|
||||
|
||||
return false
|
||||
})
|
||||
fight.Fightpool.ReleaseTimeout(0)
|
||||
//fight.Fightpool.ReleaseTimeout(0)
|
||||
log.Println("资源清理完成,程序即将退出")
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,9 @@ func isPortAvailable(port uint32) bool {
|
||||
func Start() {
|
||||
serverID := cool.Config.GameOnlineID
|
||||
cool.Config.ServerInfo = config.NewServerService().GetServerID(serverID).ServerList
|
||||
// if cool.Config.ServerInfo.IsVip != 0 {
|
||||
// g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(redis)) //设置数据库
|
||||
// }
|
||||
|
||||
if cool.Config.ServerInfo.IsDebug == 1 {
|
||||
g.DB().SetDebug(true)
|
||||
|
||||
@@ -8,10 +8,8 @@ import (
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
)
|
||||
|
||||
// Compare 比较两个1v1战斗动作的执行优先级(核心逻辑)
|
||||
@@ -157,9 +155,10 @@ func (f *FightC) startBattle(startInfo info.FightStartOutboundInfo) {
|
||||
f.startl.Do(func() {
|
||||
|
||||
// 提交战斗循环到战斗池(处理战斗池容量问题)
|
||||
if err := Fightpool.Submit(f.battleLoop); err != nil {
|
||||
log.Panic(context.Background(), "战斗循环提交失败", "error", err)
|
||||
}
|
||||
// if err := Fightpool.Invoke(f); err != nil {
|
||||
// log.Panic(context.Background(), "战斗循环提交失败", "error", err)
|
||||
// }
|
||||
go f.battleLoop()
|
||||
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
|
||||
@@ -171,9 +170,14 @@ func (f *FightC) startBattle(startInfo info.FightStartOutboundInfo) {
|
||||
|
||||
}
|
||||
|
||||
var Fightpool *ants.Pool
|
||||
// var Fightpool *ants.PoolWithFuncGeneric[*FightC]
|
||||
|
||||
func init() {
|
||||
Fightpool, _ = ants.NewPool(-1)
|
||||
//defer p.Release()
|
||||
}
|
||||
// func init() {
|
||||
// Fightpool, _ = ants.NewPoolWithFuncGeneric(-1, func(f *FightC) {
|
||||
// f.battleLoop()
|
||||
// }, ants.WithPanicHandler(func(a any) {
|
||||
// cool.Logger.Debug(context.Background(), "战斗池发生panic", "error", a)
|
||||
// }),
|
||||
// )
|
||||
// //defer p.Release()
|
||||
// }
|
||||
|
||||
@@ -2,6 +2,7 @@ package fight
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"context"
|
||||
@@ -20,7 +21,25 @@ import (
|
||||
)
|
||||
|
||||
func (f *FightC) battleLoop() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", err)
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
if p, ok := ff.Player.(*player.Player); ok {
|
||||
head := common.NewTomeeHeader(1001, p.Info.UserID)
|
||||
|
||||
head.Result = uint32(errorcode.ErrorCodes.ErrSystemBusyTryLater)
|
||||
|
||||
//实际上这里有个问题,会造成重复保存问题
|
||||
|
||||
p.SendPack(head.Pack(nil))
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}()
|
||||
f.actionChan = make(chan action.BattleActionI, 10)
|
||||
//fmt.Println("战斗开始精灵", f.Our.Player.GetInfo().PetList[0].CatchTime)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user