This commit is contained in:
flswld
2023-04-15 20:48:30 +08:00
parent 094ad5add0
commit 7fe19297e3
5 changed files with 57 additions and 33 deletions

View File

@@ -150,7 +150,7 @@ func (m *MessageQueue) parseNetMsg(rawData []byte) *NetMsg {
} }
if netMsg.EventId == NormalMsg { if netMsg.EventId == NormalMsg {
// protobuf PayloadMessage // protobuf PayloadMessage
payloadMessage := m.cmdProtoMap.GetProtoObjCacheByCmdId(gameMsg.CmdId) payloadMessage := m.cmdProtoMap.GetProtoObjFastNewByCmdId(gameMsg.CmdId)
if payloadMessage == nil { if payloadMessage == nil {
logger.Error("get protobuf obj by cmd id error: %v", err) logger.Error("get protobuf obj by cmd id error: %v", err)
return nil return nil

View File

@@ -505,6 +505,8 @@ func (w *World) InitPlayerWorldAvatar(player *model.Player) {
if !player.SceneJump && (worldAvatar.avatarEntityId != 0 || worldAvatar.weaponEntityId != 0) { if !player.SceneJump && (worldAvatar.avatarEntityId != 0 || worldAvatar.weaponEntityId != 0) {
continue continue
} }
scene.DestroyEntity(worldAvatar.avatarEntityId)
scene.DestroyEntity(worldAvatar.weaponEntityId)
worldAvatar.avatarEntityId = scene.CreateEntityAvatar(player, worldAvatar.avatarId) worldAvatar.avatarEntityId = scene.CreateEntityAvatar(player, worldAvatar.avatarId)
worldAvatar.weaponEntityId = scene.CreateEntityWeapon() worldAvatar.weaponEntityId = scene.CreateEntityWeapon()
} }

View File

@@ -437,14 +437,12 @@ func (g *Game) GetOnlinePlayerInfoReq(player *model.Player, payloadMsg pb.Messag
func (g *Game) PacketOnlinePlayerInfo(player *model.Player) *proto.OnlinePlayerInfo { func (g *Game) PacketOnlinePlayerInfo(player *model.Player) *proto.OnlinePlayerInfo {
world := WORLD_MANAGER.GetWorldByID(player.WorldId) world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return new(proto.OnlinePlayerInfo)
}
worldPlayerNum := uint32(1) worldPlayerNum := uint32(1)
// TODO 远程玩家的世界内人数
if world != nil { if world != nil {
worldPlayerNum = uint32(world.GetWorldPlayerNum()) worldPlayerNum = uint32(world.GetWorldPlayerNum())
} else {
// TODO 远程玩家的世界内人数
worldPlayerNum = 1
} }
onlinePlayerInfo := &proto.OnlinePlayerInfo{ onlinePlayerInfo := &proto.OnlinePlayerInfo{
Uid: player.PlayerID, Uid: player.PlayerID,

View File

@@ -191,7 +191,7 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID) logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return return
} }
if !world.GetMultiplayer() || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 { if WORLD_MANAGER.IsBigWorld(world) || !world.GetMultiplayer() || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 {
g.SendError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{}) g.SendError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{})
return return
} }

View File

@@ -17,6 +17,7 @@ type CmdProtoMap struct {
cmdIdCmdNameMap map[uint16]string cmdIdCmdNameMap map[uint16]string
cmdNameCmdIdMap map[string]uint16 cmdNameCmdIdMap map[string]uint16
cmdIdProtoObjCacheMap map[uint16]*sync.Pool cmdIdProtoObjCacheMap map[uint16]*sync.Pool
cmdIdProtoObjFastNewMap map[uint16]func() any
} }
func NewCmdProtoMap() (r *CmdProtoMap) { func NewCmdProtoMap() (r *CmdProtoMap) {
@@ -27,6 +28,7 @@ func NewCmdProtoMap() (r *CmdProtoMap) {
r.cmdIdCmdNameMap = make(map[uint16]string) r.cmdIdCmdNameMap = make(map[uint16]string)
r.cmdNameCmdIdMap = make(map[string]uint16) r.cmdNameCmdIdMap = make(map[string]uint16)
r.cmdIdProtoObjCacheMap = make(map[uint16]*sync.Pool) r.cmdIdProtoObjCacheMap = make(map[uint16]*sync.Pool)
r.cmdIdProtoObjFastNewMap = make(map[uint16]func() any)
r.registerAllMessage() r.registerAllMessage()
return r return r
} }
@@ -344,26 +346,36 @@ func (c *CmdProtoMap) registerAllMessage() {
c.regMsg(QuestGlobalVarNotify, func() any { return new(proto.QuestGlobalVarNotify) }) // 任务全局变量通知 c.regMsg(QuestGlobalVarNotify, func() any { return new(proto.QuestGlobalVarNotify) }) // 任务全局变量通知
// 家园 // 家园
c.regMsg(GetPlayerHomeCompInfoReq, func() any { return new(proto.GetPlayerHomeCompInfoReq) }) // 请求 c.regMsg(GetPlayerHomeCompInfoReq, func() any { return new(proto.GetPlayerHomeCompInfoReq) })
c.regMsg(HomeGetBasicInfoReq, func() any { return new(proto.HomeGetBasicInfoReq) }) // 请求 c.regMsg(HomeGetBasicInfoReq, func() any { return new(proto.HomeGetBasicInfoReq) })
c.regMsg(GetHomeExchangeWoodInfoReq, func() any { return new(proto.GetHomeExchangeWoodInfoReq) }) // 请求 c.regMsg(GetHomeExchangeWoodInfoReq, func() any { return new(proto.GetHomeExchangeWoodInfoReq) })
c.regMsg(GetHomeExchangeWoodInfoRsp, func() any { return new(proto.GetHomeExchangeWoodInfoRsp) }) // 响应 c.regMsg(GetHomeExchangeWoodInfoRsp, func() any { return new(proto.GetHomeExchangeWoodInfoRsp) })
c.regMsg(HomeGetOnlineStatusReq, func() any { return new(proto.HomeGetOnlineStatusReq) }) // 请求 c.regMsg(HomeGetOnlineStatusReq, func() any { return new(proto.HomeGetOnlineStatusReq) })
c.regMsg(HomeGetOnlineStatusRsp, func() any { return new(proto.HomeGetOnlineStatusRsp) }) // 响应 c.regMsg(HomeGetOnlineStatusRsp, func() any { return new(proto.HomeGetOnlineStatusRsp) })
c.regMsg(TryEnterHomeReq, func() any { return new(proto.TryEnterHomeReq) }) // 请求 c.regMsg(TryEnterHomeReq, func() any { return new(proto.TryEnterHomeReq) })
c.regMsg(TryEnterHomeRsp, func() any { return new(proto.TryEnterHomeRsp) }) // 响应 c.regMsg(TryEnterHomeRsp, func() any { return new(proto.TryEnterHomeRsp) })
c.regMsg(HomeGetArrangementInfoReq, func() any { return new(proto.HomeGetArrangementInfoReq) }) // 请求 c.regMsg(HomeGetArrangementInfoReq, func() any { return new(proto.HomeGetArrangementInfoReq) })
c.regMsg(HomeGetArrangementInfoRsp, func() any { return new(proto.HomeGetArrangementInfoRsp) }) // 响应 c.regMsg(HomeGetArrangementInfoRsp, func() any { return new(proto.HomeGetArrangementInfoRsp) })
c.regMsg(HomeSceneInitFinishReq, func() any { return new(proto.HomeSceneInitFinishReq) }) // 请求 c.regMsg(HomeSceneInitFinishReq, func() any { return new(proto.HomeSceneInitFinishReq) })
c.regMsg(HomeSceneInitFinishRsp, func() any { return new(proto.HomeSceneInitFinishRsp) }) // 响应 c.regMsg(HomeSceneInitFinishRsp, func() any { return new(proto.HomeSceneInitFinishRsp) })
c.regMsg(HomeGetBlueprintSlotInfoReq, func() any { return new(proto.HomeGetBlueprintSlotInfoReq) }) // 请求 c.regMsg(HomeGetBlueprintSlotInfoReq, func() any { return new(proto.HomeGetBlueprintSlotInfoReq) })
c.regMsg(HomeGetBlueprintSlotInfoRsp, func() any { return new(proto.HomeGetBlueprintSlotInfoRsp) }) // 响应 c.regMsg(HomeGetBlueprintSlotInfoRsp, func() any { return new(proto.HomeGetBlueprintSlotInfoRsp) })
c.regMsg(HomeChangeEditModeReq, func() any { return new(proto.HomeChangeEditModeReq) }) // 请求 c.regMsg(HomeChangeEditModeReq, func() any { return new(proto.HomeChangeEditModeReq) })
c.regMsg(HomeChangeEditModeRsp, func() any { return new(proto.HomeChangeEditModeRsp) }) // 响应 c.regMsg(HomeChangeEditModeRsp, func() any { return new(proto.HomeChangeEditModeRsp) })
c.regMsg(HomeEnterEditModeFinishReq, func() any { return new(proto.HomeEnterEditModeFinishReq) }) // 请求 c.regMsg(HomeEnterEditModeFinishReq, func() any { return new(proto.HomeEnterEditModeFinishReq) })
c.regMsg(HomeEnterEditModeFinishRsp, func() any { return new(proto.HomeEnterEditModeFinishRsp) }) // 响应 c.regMsg(HomeEnterEditModeFinishRsp, func() any { return new(proto.HomeEnterEditModeFinishRsp) })
c.regMsg(HomeUpdateArrangementInfoReq, func() any { return new(proto.HomeUpdateArrangementInfoReq) }) // 请求 c.regMsg(HomeUpdateArrangementInfoReq, func() any { return new(proto.HomeUpdateArrangementInfoReq) })
c.regMsg(HomeUpdateArrangementInfoRsp, func() any { return new(proto.HomeUpdateArrangementInfoRsp) }) // 响应 c.regMsg(HomeUpdateArrangementInfoRsp, func() any { return new(proto.HomeUpdateArrangementInfoRsp) })
// 乱七八糟
c.regMsg(GMShowNavMeshReq, func() any { return new(proto.GMShowNavMeshReq) })
c.regMsg(GMShowNavMeshRsp, func() any { return new(proto.GMShowNavMeshRsp) })
c.regMsg(NavMeshStatsNotify, func() any { return new(proto.NavMeshStatsNotify) })
c.regMsg(GMShowObstacleReq, func() any { return new(proto.GMShowObstacleReq) })
c.regMsg(GMShowObstacleRsp, func() any { return new(proto.GMShowObstacleRsp) })
c.regMsg(GmTalkReq, func() any { return new(proto.GmTalkReq) })
c.regMsg(GmTalkRsp, func() any { return new(proto.GmTalkRsp) })
c.regMsg(GmTalkNotify, func() any { return new(proto.GmTalkNotify) })
} }
func (c *CmdProtoMap) regMsg(cmdId uint16, protoObjNewFunc func() any) { func (c *CmdProtoMap) regMsg(cmdId uint16, protoObjNewFunc func() any) {
@@ -389,6 +401,8 @@ func (c *CmdProtoMap) regMsg(cmdId uint16, protoObjNewFunc func() any) {
c.cmdIdProtoObjCacheMap[cmdId] = &sync.Pool{ c.cmdIdProtoObjCacheMap[cmdId] = &sync.Pool{
New: protoObjNewFunc, New: protoObjNewFunc,
} }
// cmdId -> protoObjNewFunc
c.cmdIdProtoObjFastNewMap[cmdId] = protoObjNewFunc
} }
// 性能优化专用方法 若不满足使用条件 请老老实实的用下面的反射方法 // 性能优化专用方法 若不满足使用条件 请老老实实的用下面的反射方法
@@ -414,6 +428,16 @@ func (c *CmdProtoMap) PutProtoObjCache(cmdId uint16, protoObj pb.Message) {
cachePool.Put(protoObj) cachePool.Put(protoObj)
} }
func (c *CmdProtoMap) GetProtoObjFastNewByCmdId(cmdId uint16) pb.Message {
fn, exist := c.cmdIdProtoObjFastNewMap[cmdId]
if !exist {
logger.Error("unknown cmd id: %v", cmdId)
return nil
}
protoObj := fn().(pb.Message)
return protoObj
}
// 反射方法 // 反射方法
func (c *CmdProtoMap) GetProtoObjByCmdId(cmdId uint16) pb.Message { func (c *CmdProtoMap) GetProtoObjByCmdId(cmdId uint16) pb.Message {