Documentation
¶
Index ¶
- Constants
- Variables
- func DispatchPkt(e IEntity, pkt *nets.Packet)
- func NotMyMethod(err error) bool
- func RegisterBbqSysEntity(etyMgr *EntityManager, impl BbqSysEntity)
- func RegisterCallback(c Context, requestID string, cb Callback)
- func Run(e IEntity)
- func SetEntityDesc(e IEntity, desc *EntityDesc)
- func SetProxy(c Context, rem Proxy)
- func SetServiceDesc(s IService, desc *EntityDesc)
- type BbqSys
- type BbqSysEntity
- type Callback
- type Context
- type Empty
- type Entity
- func (e *Entity) AddCallback(d time.Duration, callback timer.CallbackFunc)
- func (e *Entity) AddTimer(d time.Duration, callback timer.TimerCallbackFunc)
- func (e *Entity) Context() Context
- func (e *Entity) EntityDesc() *EntityDesc
- func (e *Entity) EntityID() EntityID
- func (e *Entity) OnDestroy()
- func (e *Entity) OnInit()
- func (e *Entity) OnMessage(c Context, pkt *nets.Packet) bool
- func (e *Entity) OnMigrateIn()
- func (e *Entity) OnMigrateOut()
- func (e *Entity) OnNotify(w NotifyInfo)
- func (e *Entity) OnTick()
- func (e *Entity) Redirect(c Context, pkt *nets.Packet, dst EntityID) error
- func (e *Entity) SetTickIntervel(t time.Duration)
- func (e *Entity) Stop()
- func (e *Entity) SysNotify(c Context, req *WatchRequest) error
- func (e *Entity) SysUnwatch(c Context, req *WatchRequest) error
- func (e *Entity) SysWatch(c Context, req *WatchRequest) error
- func (e *Entity) Unwatch(id EntityID)
- func (e *Entity) Watch(id EntityID)
- type EntityDesc
- type EntityID
- type EntityIDGenerator
- type EntityManager
- func (s *EntityManager) Close(ch chan struct{}) error
- func (s *EntityManager) GetEntity(eid EntityID) (IEntity, bool)
- func (s *EntityManager) GetService(typ string) (IService, bool)
- func (st *EntityManager) HandlePacket(pkt *nets.Packet) error
- func (s *EntityManager) InitEntity(c Context, id EntityID, entity IEntity) error
- func (st *EntityManager) LocalCall(pkt *nets.Packet, in any, respChan chan any) error
- func (s *EntityManager) NewEntity(c Context, id EntityID, typ string) (IEntity, error)
- func (s *EntityManager) RegisterEntity(c Context, id EntityID, entity IEntity) error
- func (s *EntityManager) RegisterEntityDesc(sd *EntityDesc, ss IEntity, intercepter ...ServerInterceptor)
- func (s *EntityManager) RegisterService(sd *EntityDesc, ss IService, intercepter ...ServerInterceptor)
- func (s *EntityManager) ReplaceEntityID(old, new EntityID) error
- type Handler
- type ID
- type IEntity
- type IService
- type InstID
- type MethodDesc
- type NotifyInfo
- type Proxy
- type ProxyID
- type RegisterProxy
- type ServerInfo
- type ServerInterceptor
- type Service
- type WatchRequest
Constants ¶
View Source
const ( TotalBitLen = 64 // (proxy+inst+id) ProxyIDBitNum = 20 InstIDBitNum = 8 IDBitNum = 36 ProxyIDMask = 1<<ProxyIDBitNum - 1 InstIDMask = 1<<InstIDBitNum - 1 IDBitMask = 1<<IDBitNum - 1 )
View Source
const (
GAME_SERVICE_TICK_INTERVAL = 5 * time.Millisecond
)
Variables ¶
View Source
var BbqSysEntityDesc = EntityDesc{ TypeName: "BbqSysEntity", HandlerType: (*BbqSysEntity)(nil), Methods: map[string]MethodDesc{ "SysWatch": { MethodName: "SysWatch", Handler: _BbqSysEntity_SysWatch_Remote_Handler, LocalHandler: _BbqSysEntity_SysWatch_Local_Handler, }, "SysUnwatch": { MethodName: "SysUnwatch", Handler: _BbqSysEntity_SysUnwatch_Remote_Handler, LocalHandler: _BbqSysEntity_SysUnwatch_Local_Handler, }, "SysNotify": { MethodName: "SysNotify", Handler: _BbqSysEntity_SysNotify_Remote_Handler, LocalHandler: _BbqSysEntity_SysNotify_Local_Handler, }, }, Metadata: "bbqsys.proto", }
View Source
var File_bbqsys_proto protoreflect.FileDescriptor
Functions ¶
func DispatchPkt ¶
func NotMyMethod ¶
func RegisterBbqSysEntity ¶
func RegisterBbqSysEntity(etyMgr *EntityManager, impl BbqSysEntity)
func RegisterCallback ¶
func SetEntityDesc ¶
func SetEntityDesc(e IEntity, desc *EntityDesc)
func SetServiceDesc ¶
func SetServiceDesc(s IService, desc *EntityDesc)
Types ¶
type BbqSys ¶
type BbqSys struct {
EntityID EntityID
}
func NewBbqSysClient ¶
func (*BbqSys) SysUnwatch ¶
func (t *BbqSys) SysUnwatch(c Context, req *WatchRequest) error
type BbqSysEntity ¶
type BbqSysEntity interface { IEntity // SysWatch SysWatch(c Context, req *WatchRequest) error // SysUnwatch SysUnwatch(c Context, req *WatchRequest) error // SysNotify SysNotify(c Context, req *WatchRequest) error }
BbqSysEntity
type Context ¶
type Context interface { /************************************/ /***** GOLANG.ORG/X/NET/CONTEXT *****/ /************************************/ context.Context /************************************/ /******** ENTITY MANAGEMENT********/ /************************************/ Copy() (Context, releaseCtx) Entity() IEntity EntityID() EntityID Packet() *nets.Packet SrcEntity() EntityID /************************************/ /******** METADATA MANAGEMENT********/ /************************************/ SetError(err error) // Set is used to store a new key/value pair exclusively for this context. // It also lazy initializes c.Keys if it was not used previously. Set(key string, value any) // Get returns the value for the given key, ie: (value, true). // If the value does not exist it returns (nil, false) Get(key string) (value any, exists bool) // MustGet returns the value for the given key if it exists, otherwise it panics. MustGet(key string) any // GetString returns the value associated with the key as a string. GetString(key string) (s string) // GetBool returns the value associated with the key as a boolean. GetBool(key string) (b bool) // GetInt returns the value associated with the key as an integer. GetInt(key string) (i int) // GetInt64 returns the value associated with the key as an integer. GetInt64(key string) (i64 int64) // GetUint returns the value associated with the key as an unsigned integer. GetUint(key string) (ui uint) // GetUint64 returns the value associated with the key as an unsigned integer. GetUint64(key string) (ui64 uint64) // GetFloat64 returns the value associated with the key as a float64. GetFloat64(key string) (f64 float64) // GetTime returns the value associated with the key as time. GetTime(key string) (t time.Time) // GetDuration returns the value associated with the key as a duration. GetDuration(key string) (d time.Duration) // GetStringSlice returns the value associated with the key as a slice of strings. GetStringSlice(key string) (ss []string) // GetStringMap returns the value associated with the key as a map of interfaces. GetStringMap(key string) (sm map[string]any) // GetStringMapString returns the value associated with the key as a map of strings. GetStringMapString(key string) (sms map[string]string) // GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings. GetStringMapStringSlice(key string) (smss map[string][]string) // contains filtered or unexported methods }
func NewContext ¶
NewPacket allocates a new packet
type Empty ¶
type Empty struct {
// contains filtered or unexported fields
}
func (*Empty) Descriptor
deprecated
func (*Empty) ProtoMessage ¶
func (*Empty) ProtoMessage()
func (*Empty) ProtoReflect ¶
func (x *Empty) ProtoReflect() protoreflect.Message
type Entity ¶
type Entity struct {
// contains filtered or unexported fields
}
func (*Entity) AddCallback ¶
func (e *Entity) AddCallback(d time.Duration, callback timer.CallbackFunc)
AddOnceTimer 直接用,不需要重写,除非有特殊需求
func (*Entity) AddTimer ¶
func (e *Entity) AddTimer(d time.Duration, callback timer.TimerCallbackFunc)
AddRepeatTimer 直接用,不需要重写,除非有特殊需求
func (*Entity) EntityDesc ¶
func (e *Entity) EntityDesc() *EntityDesc
func (*Entity) OnMigrateIn ¶
func (e *Entity) OnMigrateIn()
func (*Entity) OnMigrateOut ¶
func (e *Entity) OnMigrateOut()
func (*Entity) SetTickIntervel ¶
func (*Entity) SysUnwatch ¶
func (e *Entity) SysUnwatch(c Context, req *WatchRequest) error
SysUnwatch
type EntityDesc ¶
type EntityDesc struct { EntityImpl any TypeName string // The pointer to the Entity interface. Used to check whether the user // provided implementation satisfies the interface requiremente. HandlerType any Methods map[string]MethodDesc Metadata any EntityMgr *EntityManager // contains filtered or unexported fields }
EntityDesc represents an RPC Entity's specification.
type EntityID ¶
type EntityID uint64
EntityID proxyid + instid + id => (22bit + 10bit + 32bit)
func NewEntityID ¶
type EntityIDGenerator ¶
type EntityIDGenerator interface {
NewEntityID() EntityID
}
type EntityManager ¶
type EntityManager struct { Proxy Services map[string]IService // service name -> service info Entities map[EntityID]IEntity // entity id -> entity impl ProxyRegister RegisterProxy EntityIDGenerator EntityIDGenerator // contains filtered or unexported fields }
EntityManager manage entity lifecycle
func GetEntityMgr ¶
func GetEntityMgr(c Context) *EntityManager
func NewEntityManager ¶
func NewEntityManager() *EntityManager
func (*EntityManager) Close ¶
func (s *EntityManager) Close(ch chan struct{}) error
func (*EntityManager) GetEntity ¶
func (s *EntityManager) GetEntity(eid EntityID) (IEntity, bool)
需要优化, gate的id再拆分,不要直接用这个来判断是不是自己的entity
func (*EntityManager) GetService ¶
func (s *EntityManager) GetService(typ string) (IService, bool)
func (*EntityManager) HandlePacket ¶
func (st *EntityManager) HandlePacket(pkt *nets.Packet) error
func (*EntityManager) InitEntity ¶
func (s *EntityManager) InitEntity(c Context, id EntityID, entity IEntity) error
func (*EntityManager) RegisterEntity ¶
func (s *EntityManager) RegisterEntity(c Context, id EntityID, entity IEntity) error
func (*EntityManager) RegisterEntityDesc ¶
func (s *EntityManager) RegisterEntityDesc(sd *EntityDesc, ss IEntity, intercepter ...ServerInterceptor)
func (*EntityManager) RegisterService ¶
func (s *EntityManager) RegisterService(sd *EntityDesc, ss IService, intercepter ...ServerInterceptor)
func (*EntityManager) ReplaceEntityID ¶
func (s *EntityManager) ReplaceEntityID(old, new EntityID) error
type IEntity ¶
type IEntity interface { // EntityID EntityID() EntityID Context() Context // Entity Lifetime OnInit() // Called when initializing entity struct, override to initialize entity custom fields OnDestroy() // Called when entity is destroying (just before destroy) // OnMessage 收到请求,返回false则不处理,默认true OnMessage(c Context, pkt *nets.Packet) bool // Migration OnMigrateOut() // Called just before entity is migrating out OnMigrateIn() // Called just after entity is migrating in // AddCallback 直接用,不需要重写,除非有特殊需求 AddCallback(d time.Duration, callback timer.CallbackFunc) // AddTimer 直接用,不需要重写,除非有特殊需求 AddTimer(d time.Duration, callback timer.TimerCallbackFunc) // OnTick entity执行过一次事件之后执行一次OnTick, 实时性很高要求的可以通过tick实现 // 如果没有事件发生,则定时调用,默认5ms,可以重写OnInit()调用SetTickIntervel()自定义间隔时间 OnTick() // SetTickIntervel 自定义OnTick()的间隔时间,只能在OnInit()中调用 SetTickIntervel(t time.Duration) // 关注entity, 如果entity退出或者状态变更会通过OnNotify接收到状态变更通知 Watch(id EntityID) Unwatch(id EntityID) OnNotify(NotifyInfo) // Redirect 重定向请求到指定的dst Entity Redirect(c Context, pkt *nets.Packet, dst EntityID) error // 主动结束, 主动调用结束entity的生命周期 Stop() // contains filtered or unexported methods }
On开头的表示可重写
type IService ¶
type IService interface { IEntity ServiceDesc() *EntityDesc // contains filtered or unexported methods }
type MethodDesc ¶
type MethodDesc struct { MethodName string Handler methodHandler LocalHandler methodLocalHandler }
MethodDesc represents an RPC Entity's method specification.
type NotifyInfo ¶
type NotifyInfo struct {
EntityID EntityID
}
type Proxy ¶
type RegisterProxy ¶
type ServerInfo ¶
type ServerInterceptor ¶
type Service ¶
type Service struct {
Entity
}
func (*Service) ServiceDesc ¶
func (s *Service) ServiceDesc() *EntityDesc
type WatchRequest ¶
type WatchRequest struct { EntityID uint64 `protobuf:"varint,1,opt,name=EntityID,proto3" json:"EntityID,omitempty" bson:"EntityID"` // contains filtered or unexported fields }
func (*WatchRequest) Descriptor
deprecated
func (*WatchRequest) Descriptor() ([]byte, []int)
Deprecated: Use WatchRequest.ProtoReflect.Descriptor instead.
func (*WatchRequest) GetEntityID ¶
func (x *WatchRequest) GetEntityID() uint64
func (*WatchRequest) ProtoMessage ¶
func (*WatchRequest) ProtoMessage()
func (*WatchRequest) ProtoReflect ¶
func (x *WatchRequest) ProtoReflect() protoreflect.Message
func (*WatchRequest) Reset ¶
func (x *WatchRequest) Reset()
func (*WatchRequest) String ¶
func (x *WatchRequest) String() string
Click to show internal directories.
Click to hide internal directories.