Documentation ¶
Index ¶
- Constants
- Variables
- func RetMsg(user IClientSess, msg msgdef.IMsg, err error)
- func ReturnLLoginNtf(user IClientSess, err error)
- type CallDelayF
- type DelayCallHost
- type Entities
- func (this *Entities) CreateEntity(etype string, eid, dbid uint64, fly bool, param ...interface{}) (result IEntity, err error)
- func (this *Entities) Destroy()
- func (this *Entities) DestroyEntity(eid uint64) error
- func (this *Entities) GetEntity(eid uint64) IEntity
- func (this *Entities) GetEntityByDBID(dbid uint64, etype string) IEntity
- func (this *Entities) GetID() uint64
- func (this *Entities) GetThreadGo() *threads.ThreadGo
- func (this *Entities) Init() error
- func (this *Entities) Loop()
- func (this *Entities) Range(f func(k, v interface{}) bool)
- func (this *Entities) RangeByGroup(gp string, f func(k, v any) bool)
- func (this *Entities) RangeByType(etype string, f func(k, v any) bool)
- func (this *Entities) String() string
- type EntitiesMsgProc
- func (es *EntitiesMsgProc) MsgPorc_DestroyEntityRetSrv(msg *protomsg.DestroyEntityRetSrv)
- func (es *EntitiesMsgProc) MsgProc_CreateEntityReqSrv(msg *protomsg.CreateEntityReqSrv)
- func (es *EntitiesMsgProc) MsgProc_CreateEntityRetSrv(msg *protomsg.CreateEntityRetSrv)
- func (es *EntitiesMsgProc) MsgProc_DestroyEntityReqSrv(msg *protomsg.DestroyEntityReqSrv)
- type Entity
- func (e *Entity) AddGroup(g string)
- func (e *Entity) DelGroup(g string)
- func (this *Entity) DelayPost(stye global.ServerTypeEnum, msg msgdef.IMsg)
- func (e *Entity) Destroy()
- func (e *Entity) EnterDestroy()
- func (this *Entity) GetClientSess() sess.INetSess
- func (e *Entity) GetDBID() uint64
- func (e *Entity) GetEntities() IEntities
- func (e *Entity) GetEntityState() EntityStateEnum
- func (e *Entity) GetGroup(g string) bool
- func (e *Entity) GetGroups() *sync.Map
- func (e *Entity) GetID() uint64
- func (e *Entity) GetRealPtr() IEntityReal
- func (e *Entity) GetSpaceID() uint64
- func (this *Entity) GetSrvByStype(styp uint32) (*EntitySrvInfo, error)
- func (e *Entity) GetSrvInfoAll() []*EntitySrvInfo
- func (e *Entity) GetType() string
- func (e *Entity) GoRun(ctx context.Context)
- func (e *Entity) Init() error
- func (e *Entity) IsDestroyed() bool
- func (this *Entity) IsExistSID(srvid uint64) bool
- func (e *Entity) Loop()
- func (e *Entity) Looped()
- func (e *Entity) Looping()
- func (e *Entity) OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, ...)
- func (e *Entity) OnPanic(err error)
- func (this *Entity) PackEntityMsgRet(msg msgdef.IMsg) (result *protomsg.EntityMsgRet)
- func (this *Entity) Post(stye global.ServerTypeEnum, msg msgdef.IMsg) error
- func (this *Entity) PostBuf(data []byte) error
- func (e *Entity) ReLoop()
- func (this *Entity) ReadSyncProps(li []*protomsg.SyncProp)
- func (this *Entity) RefreshSrvIDS()
- func (this *Entity) SetClientSess(v sess.INetSess)
- func (e *Entity) SetEntityState(st EntityStateEnum)
- func (e *Entity) SetSrvInfo(v []*EntitySrvInfo)
- func (e *Entity) String() string
- func (this *Entity) SyncProps()
- type EntitySrvInfo
- type EntityStateEnum
- type Entity_Proc
- type IClientSess
- type IDelayCall
- type IEntities
- type IEntity
- type IEntityReal
- type RedisUtilEntity
- func (util *RedisUtilEntity) GetSrvInfos() (result []*EntitySrvInfo, err error)
- func (util *RedisUtilEntity) RegEntity(etyp string, dbid uint64) error
- func (util *RedisUtilEntity) RegSrvID(stye global.ServerTypeEnum, srvid, spid uint64) error
- func (util *RedisUtilEntity) UnRegSrvID(srvType uint32, srvID uint64, spaceID uint64) (result error)
- func (util *RedisUtilEntity) UnregEntity() error
- type SimpleEntity
- func (this *SimpleEntity) AddGroup(g string)
- func (this *SimpleEntity) DelGroup(g string)
- func (e *SimpleEntity) Destroy()
- func (e *SimpleEntity) EnterDestroy()
- func (this *SimpleEntity) GetDBID() uint64
- func (this *SimpleEntity) GetEntities() IEntities
- func (this *SimpleEntity) GetEntityState() EntityStateEnum
- func (this *SimpleEntity) GetGroup(g string) bool
- func (this *SimpleEntity) GetGroups() *sync.Map
- func (this *SimpleEntity) GetID() uint64
- func (this *SimpleEntity) GetRealPtr() IEntity
- func (this *SimpleEntity) GetSpaceID() uint64
- func (this *SimpleEntity) GetType() string
- func (e *SimpleEntity) GoRun(ctx context.Context)
- func (e *SimpleEntity) Init() error
- func (e *SimpleEntity) IsDestroyed() bool
- func (e *SimpleEntity) Loop()
- func (e *SimpleEntity) Looped()
- func (e *SimpleEntity) Looping()
- func (e *SimpleEntity) OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, ...)
- func (e *SimpleEntity) OnPanic(err error)
- func (e *SimpleEntity) ReLoop()
- func (this *SimpleEntity) SetEntityState(st EntityStateEnum)
- func (e *SimpleEntity) String() string
- type TypeMgr
Constants ¶
View Source
const (
//Ntt类型 Player
Entity_Type_Player = "Player"
)
Variables ¶
View Source
var ( //eid 已存在 ErrNtt_EID_Exist = common.NewError("entity eid:%d exist.") // eid 不存在 ErrNtt_EID_Not_Exist = common.NewError("entity eid:%d not exist.") //对象不在指定服务器上 ErrNtt_Stype_Not_Exist = common.NewError("entity eid:%d stype:%d not exist.") //这个对像是Fly ErrNtt_Fly = common.NewError("entity eid:%d is fly.") )
Functions ¶
Types ¶
type DelayCallHost ¶
type DelayCallHost struct {
// contains filtered or unexported fields
}
用于回调函数的结构
func (*DelayCallHost) CallDelay ¶
func (this *DelayCallHost) CallDelay(f CallDelayF)
type Entities ¶
type Entities struct {
// contains filtered or unexported fields
}
对象管理器
func NewEntities ¶
func (*Entities) CreateEntity ¶
func (this *Entities) CreateEntity(etype string, eid, dbid uint64, fly bool, param ...interface{}) (result IEntity, err error)
创建子对象
func (*Entities) GetEntityByDBID ¶
获取子对象使用DBID
func (*Entities) RangeByGroup ¶
按分组遍历组内所有成员
func (*Entities) RangeByType ¶
按类型遍历组内所有成员
type EntitiesMsgProc ¶
type EntitiesMsgProc struct {
IEntities
}
func (*EntitiesMsgProc) MsgPorc_DestroyEntityRetSrv ¶
func (es *EntitiesMsgProc) MsgPorc_DestroyEntityRetSrv(msg *protomsg.DestroyEntityRetSrv)
func (*EntitiesMsgProc) MsgProc_CreateEntityReqSrv ¶
func (es *EntitiesMsgProc) MsgProc_CreateEntityReqSrv(msg *protomsg.CreateEntityReqSrv)
func (*EntitiesMsgProc) MsgProc_CreateEntityRetSrv ¶
func (es *EntitiesMsgProc) MsgProc_CreateEntityRetSrv(msg *protomsg.CreateEntityRetSrv)
func (*EntitiesMsgProc) MsgProc_DestroyEntityReqSrv ¶
func (es *EntitiesMsgProc) MsgProc_DestroyEntityReqSrv(msg *protomsg.DestroyEntityReqSrv)
type Entity ¶
type Entity struct { //消息路由 *msghandler.MsgHandler //属性同步器(有可能为空) *PropsSyncContainer //对象身上所有需要垮协程的数量读写的时候,用到的锁 Mux sync.RWMutex // contains filtered or unexported fields }
基础对象,服务器用与通信的最小单元
func (*Entity) DelayPost ¶
func (this *Entity) DelayPost(stye global.ServerTypeEnum, msg msgdef.IMsg)
DelayPost 延迟发送消息, 在帧尾发送
func (*Entity) GetEntityState ¶
func (e *Entity) GetEntityState() EntityStateEnum
GetEntityState 获取当前状态
func (*Entity) GetSrvByStype ¶
func (this *Entity) GetSrvByStype(styp uint32) (*EntitySrvInfo, error)
获取服务器信息
func (*Entity) OnCreated ¶
func (e *Entity) OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, param ...interface{})
在创建对象的时候调用 eid:实例的唯一ID etype:实例对象类型 dbid:实例持久化的唯一ID,如果没有持久化可以使用eid一样,也可以为0 realPtr:最外面的实例对象引用 spacePtr:最外面的实例所在空间的引用 fly:是否需要在redis中注册路由信息
func (*Entity) PackEntityMsgRet ¶
func (this *Entity) PackEntityMsgRet(msg msgdef.IMsg) (result *protomsg.EntityMsgRet)
打包成发给客户端的消息
func (*Entity) ReadSyncProps ¶
从同步消息中获取数据
func (*Entity) SetEntityState ¶
func (e *Entity) SetEntityState(st EntityStateEnum)
type EntitySrvInfo ¶
type EntitySrvInfo struct { SrvID uint64 SpaceID uint64 Stype global.ServerTypeEnum }
type EntityStateEnum ¶
type EntityStateEnum = uint32
const ( //初始化 Entity_State_Init EntityStateEnum = iota //Tick状态 Entity_State_Loop //开始Destroy Entity_State_Destroy //Destroy结束后的状态 Entity_State_InValid //暂停状态 Entity_State_Suspend //恢复状态 Entity_State_Prepare )
type Entity_Proc ¶
type Entity_Proc struct {
// contains filtered or unexported fields
}
对象消息
func (*Entity_Proc) MsgProc_SyncEntityProps ¶
func (this *Entity_Proc) MsgProc_SyncEntityProps(msg *protomsg.SyncEntityProps)
type IClientSess ¶
type IClientSess interface { // 发消息给客户端的二进制消息 PostBuf(data []byte) error //发消息出去 Post(stye global.ServerTypeEnum, msg msgdef.IMsg) error // DelayPost 延迟发送消息, 在帧尾发送 DelayPost(stye global.ServerTypeEnum, msg msgdef.IMsg) // 打包成发给客户端的消息 PackEntityMsgRet(msg msgdef.IMsg) (result *protomsg.EntityMsgRet) }
type IDelayCall ¶
type IDelayCall interface { //在帧尾回调这个函数,当前立即返回 CallDelay(f CallDelayF) //在帧尾回调这个函数,当前协程会卡住 CallDelayWait(f CallDelayF) //调用存储的函数 Exec() }
支持回调的接口
type IEntities ¶
type IEntities interface { //这个需要子类实现 IMsgHandler //这个需要子类实现 IDelayCall //初始化 Init() error //循环调用 Loop() //销毁 Destroy() //获取子对象 GetEntity(eid uint64) IEntity // 获取子对象使用DBID GetEntityByDBID(dbid uint64, etype string) IEntity //创建子对象 CreateEntity(etype string, eid, dbid uint64, fly bool, param ...interface{}) (result IEntity, err error) //销毁子对象 DestroyEntity(eid uint64) error //遍历所有成员 Range(f func(k, v interface{}) bool) //按分组遍历组内所有成员 RangeByGroup(gp string, f func(k, v any) bool) //按类型遍历组内所有成员 RangeByType(etype string, f func(k, v any) bool) //字符串化信息 String() string //本空间的ID GetID() uint64 //操作子协程的管理器 GetThreadGo() *threads.ThreadGo }
type IEntity ¶
type IEntity interface { IMsgHandler //进入对象销毁程序(不能重载) EnterDestroy() //是否已销毁 IsDestroyed() bool /* 在创建对象的时候调用 eid:实例的唯一ID etype:实例对象类型 dbid:实例持久化的唯一ID,如果没有持久化可以使用eid一样 realPtr:最外面的实例对象引用 spacePtr:最外面的实例所在空间的引用 fly:是否需要在redis中注册路由信息 */ OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, param ...interface{}) //初始化 Init() error //循环调用 Loop() //循环调用中间 Looping() //循环调用结尾 Looped() //销毁 Destroy() //恢复到Loop状态 ReLoop() //发生异常的时候 OnPanic(err error) //自运行协程的函数(不能重写) GoRun(ctx context.Context) //字符串化信息 String() string GetID() uint64 GetDBID() uint64 GetType() string GetSpaceID() uint64 // GetSpaceSrvType() uint32 AddGroup(g string) DelGroup(g string) GetEntities() IEntities GetEntityState() EntityStateEnum GetGroup(g string) bool GetGroups() *sync.Map // contains filtered or unexported methods }
对象的基础接口,用于表示真实对象引用 子类可重载
type IEntityReal ¶
type IEntityReal interface { IEntity IProps //获取连接 GetClientSess() sess.INetSess // 设置链接 SetClientSess(v sess.INetSess) //获取服务器信息 GetSrvByStype(styp uint32) (*EntitySrvInfo, error) // 刷新对象路由信息 RefreshSrvIDS() // 本对象有没有连接指点的服务器 IsExistSID(srvid uint64) bool // 同步属性给别的服务器和客户端 SyncProps() // 从同步消息中获取数据 ReadSyncProps(li []*protomsg.SyncProp) }
后代Entity接口
type RedisUtilEntity ¶
type RedisUtilEntity struct {
// contains filtered or unexported fields
}
对象的redis操作集合
func NewRedisUtilEntity ¶
func NewRedisUtilEntity(eid uint64) (result *RedisUtilEntity)
对象的redis操作集合
func (*RedisUtilEntity) GetSrvInfos ¶
func (util *RedisUtilEntity) GetSrvInfos() (result []*EntitySrvInfo, err error)
获取对象在所有服务器上的路由信息
func (*RedisUtilEntity) RegEntity ¶
func (util *RedisUtilEntity) RegEntity(etyp string, dbid uint64) error
注册这个对象信息 一般是有链接的服务器会使用这个
func (*RedisUtilEntity) RegSrvID ¶
func (util *RedisUtilEntity) RegSrvID(stye global.ServerTypeEnum, srvid, spid uint64) error
注册服务器
func (*RedisUtilEntity) UnRegSrvID ¶
func (util *RedisUtilEntity) UnRegSrvID(srvType uint32, srvID uint64, spaceID uint64) (result error)
UnRegSrvID 删除注册信息
func (*RedisUtilEntity) UnregEntity ¶
func (util *RedisUtilEntity) UnregEntity() error
注销对象信息 一般是有链接的服务器会使用这个
type SimpleEntity ¶
type SimpleEntity struct { //消息路由 *MsgHandler //对象身上所有需要垮协程的数量读写的时候,用到的锁 Mux sync.RWMutex // contains filtered or unexported fields }
无属性的entity对象
func (*SimpleEntity) GetEntities ¶
func (this *SimpleEntity) GetEntities() IEntities
GetEntities 获取包含自己的Entities指针
func (*SimpleEntity) GetEntityState ¶
func (this *SimpleEntity) GetEntityState() EntityStateEnum
GetEntityState 获取当前状态
func (*SimpleEntity) GetRealPtr ¶
func (this *SimpleEntity) GetRealPtr() IEntity
GetRealPtr 获取真实的后代对象的指针
func (*SimpleEntity) OnCreated ¶
func (e *SimpleEntity) OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, param ...interface{})
在创建对象的时候调用 eid:实例的唯一ID etype:实例对象类型 dbid:实例持久化的唯一ID,如果没有持久化可以使用eid一样,也可以为0 realPtr:最外面的实例对象引用 spacePtr:最外面的实例所在空间的引用 fly:是否需要在redis中注册路由信息
func (*SimpleEntity) SetEntityState ¶
func (this *SimpleEntity) SetEntityState(st EntityStateEnum)
func (*SimpleEntity) String ¶
func (e *SimpleEntity) String() string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.