优化ability转发

This commit is contained in:
huangxiaolei
2022-12-05 00:20:25 +08:00
parent b5b7a2b47a
commit 447aeeb672
15 changed files with 267 additions and 218 deletions

View File

@@ -8,13 +8,14 @@ import (
// 泛型通用转发器
type InvokeType interface {
proto.AbilityInvokeEntry | proto.CombatInvokeEntry
proto.CombatInvokeEntry | proto.AbilityInvokeEntry
}
type InvokeHandler[T InvokeType] struct {
EntryListForwardAll []*T
EntryListForwardAllExceptCur []*T
EntryListForwardHost []*T
EntryListForwardServer []*T
}
func NewInvokeHandler[T InvokeType]() (r *InvokeHandler[T]) {
@@ -27,6 +28,7 @@ func (i *InvokeHandler[T]) InitInvokeHandler() {
i.EntryListForwardAll = make([]*T, 0)
i.EntryListForwardAllExceptCur = make([]*T, 0)
i.EntryListForwardHost = make([]*T, 0)
i.EntryListForwardServer = make([]*T, 0)
}
func (i *InvokeHandler[T]) AddEntry(forward proto.ForwardType, entry *T) {
@@ -39,10 +41,11 @@ func (i *InvokeHandler[T]) AddEntry(forward proto.ForwardType, entry *T) {
i.EntryListForwardAllExceptCur = append(i.EntryListForwardAllExceptCur, entry)
case proto.ForwardType_FORWARD_TYPE_TO_HOST:
i.EntryListForwardHost = append(i.EntryListForwardHost, entry)
case proto.ForwardType_FORWARD_TYPE_ONLY_SERVER:
i.EntryListForwardServer = append(i.EntryListForwardServer, entry)
logger.LOG.Error("fwd server entry: %v", entry)
default:
if forward != proto.ForwardType_FORWARD_TYPE_ONLY_SERVER {
logger.LOG.Error("forward: %v, entry: %v", forward, entry)
}
logger.LOG.Error("forward: %v, entry: %v", forward, entry)
}
}
@@ -57,3 +60,14 @@ func (i *InvokeHandler[T]) AllExceptCurLen() int {
func (i *InvokeHandler[T]) HostLen() int {
return len(i.EntryListForwardHost)
}
func (i *InvokeHandler[T]) ServerLen() int {
return len(i.EntryListForwardServer)
}
func (i *InvokeHandler[T]) Clear() {
i.EntryListForwardAll = make([]*T, 0)
i.EntryListForwardAllExceptCur = make([]*T, 0)
i.EntryListForwardHost = make([]*T, 0)
i.EntryListForwardServer = make([]*T, 0)
}

View File

@@ -53,21 +53,23 @@ type Player struct {
ChatMsgMap map[uint32][]*ChatMsg `bson:"chatMsgMap"` // 聊天信息
IsGM uint8 `bson:"isGM"` // 管理员权限等级
// 在线数据
EnterSceneToken uint32 `bson:"-"` // 玩家的世界进入令牌
DbState int `bson:"-"` // 数据库存档状态
WorldId uint32 `bson:"-"` // 所在的世界id
PeerId uint32 `bson:"-"` // 多人世界的玩家编号
GameObjectGuidCounter uint64 `bson:"-"` // 游戏对象guid计数器
ClientTime uint32 `bson:"-"` // 玩家客户端的本地时钟
ClientRTT uint32 `bson:"-"` // 玩家客户端往返时延
GameObjectGuidMap map[uint64]GameObject `bson:"-"` // 游戏对象guid映射表
Online bool `bson:"-"` // 在线状态
Pause bool `bson:"-"` // 暂停状态
SceneLoadState int `bson:"-"` // 场景加载状态
CoopApplyMap map[uint32]int64 `bson:"-"` // 敲门申请的玩家uid及时间
StaminaInfo *StaminaInfo `bson:"-"` // 耐力临时数据
ClientSeq uint32 `bson:"-"` // 客户端发包请求的序号
AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry]
EnterSceneToken uint32 `bson:"-"` // 玩家的世界进入令牌
DbState int `bson:"-"` // 数据库存档状态
WorldId uint32 `bson:"-"` // 所在的世界id
PeerId uint32 `bson:"-"` // 多人世界的玩家编号
GameObjectGuidCounter uint64 `bson:"-"` // 游戏对象guid计数器
ClientTime uint32 `bson:"-"` // 玩家客户端的本地时钟
ClientRTT uint32 `bson:"-"` // 玩家客户端往返时延
GameObjectGuidMap map[uint64]GameObject `bson:"-"` // 游戏对象guid映射表
Online bool `bson:"-"` // 在线状态
Pause bool `bson:"-"` // 暂停状态
SceneLoadState int `bson:"-"` // 场景加载状态
CoopApplyMap map[uint32]int64 `bson:"-"` // 敲门申请的玩家uid及时间
StaminaInfo *StaminaInfo `bson:"-"` // 耐力临时数据
ClientSeq uint32 `bson:"-"` // 客户端发包请求的序号
CombatInvokeHandler *InvokeHandler[proto.CombatInvokeEntry]
AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry]
ClientAbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry]
}
func (p *Player) GetNextGameObjectGuid() uint64 {