mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-12 23:52:27 +08:00
多人世界ability转发优化
This commit is contained in:
59
gs/model/invoke_handler.go
Normal file
59
gs/model/invoke_handler.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/proto"
|
||||
)
|
||||
|
||||
// 泛型通用转发器
|
||||
|
||||
type InvokeType interface {
|
||||
proto.AbilityInvokeEntry | proto.CombatInvokeEntry
|
||||
}
|
||||
|
||||
type InvokeHandler[T InvokeType] struct {
|
||||
EntryListForwardAll []*T
|
||||
EntryListForwardAllExceptCur []*T
|
||||
EntryListForwardHost []*T
|
||||
}
|
||||
|
||||
func NewInvokeHandler[T InvokeType]() (r *InvokeHandler[T]) {
|
||||
r = new(InvokeHandler[T])
|
||||
r.InitInvokeHandler()
|
||||
return r
|
||||
}
|
||||
|
||||
func (i *InvokeHandler[T]) InitInvokeHandler() {
|
||||
i.EntryListForwardAll = make([]*T, 0)
|
||||
i.EntryListForwardAllExceptCur = make([]*T, 0)
|
||||
i.EntryListForwardHost = make([]*T, 0)
|
||||
}
|
||||
|
||||
func (i *InvokeHandler[T]) AddEntry(forward proto.ForwardType, entry *T) {
|
||||
switch forward {
|
||||
case proto.ForwardType_FORWARD_TYPE_TO_ALL:
|
||||
i.EntryListForwardAll = append(i.EntryListForwardAll, entry)
|
||||
case proto.ForwardType_FORWARD_TYPE_TO_ALL_EXCEPT_CUR:
|
||||
fallthrough
|
||||
case proto.ForwardType_FORWARD_TYPE_TO_ALL_EXIST_EXCEPT_CUR:
|
||||
i.EntryListForwardAllExceptCur = append(i.EntryListForwardAllExceptCur, entry)
|
||||
case proto.ForwardType_FORWARD_TYPE_TO_HOST:
|
||||
i.EntryListForwardHost = append(i.EntryListForwardHost, entry)
|
||||
default:
|
||||
if forward != proto.ForwardType_FORWARD_TYPE_ONLY_SERVER {
|
||||
logger.LOG.Error("forward: %v, entry: %v", forward, entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InvokeHandler[T]) AllLen() int {
|
||||
return len(i.EntryListForwardAll)
|
||||
}
|
||||
|
||||
func (i *InvokeHandler[T]) AllExceptCurLen() int {
|
||||
return len(i.EntryListForwardAllExceptCur)
|
||||
}
|
||||
|
||||
func (i *InvokeHandler[T]) HostLen() int {
|
||||
return len(i.EntryListForwardHost)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"hk4e/protocol/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -65,7 +66,8 @@ type Player struct {
|
||||
SceneLoadState int `bson:"-"` // 场景加载状态
|
||||
CoopApplyMap map[uint32]int64 `bson:"-"` // 敲门申请的玩家uid及时间
|
||||
StaminaInfo *StaminaInfo `bson:"-"` // 耐力临时数据
|
||||
ClientSeq uint32 `bson:"-"`
|
||||
ClientSeq uint32 `bson:"-"` // 客户端发包请求的序号
|
||||
AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry]
|
||||
}
|
||||
|
||||
func (p *Player) GetNextGameObjectGuid() uint64 {
|
||||
|
||||
Reference in New Issue
Block a user