Documentation
¶
Index ¶
- Constants
- Variables
- func PackEntityMsgRet(nttmd IBase, msg msgdef.IMsg) (result *protomsg.EntityMsgRet)
- func RetMsg(user IPost, msg msgdef.IMsg, err error)
- func ReturnLLoginNtf(user IPost, err error)
- type CallDelayF
- type DelayCallHost
- type Entities
- func (this *Entities) AddChan(eid uint64, v ITime)
- 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) DestroyEntityByStype(eid uint64, stype global.ServerTypeEnum, callbackf global.RouteCallBackF) error
- func (this *Entities) GetEntity(eid uint64) IEntity
- func (this *Entities) GetEntityByDBID(dbid uint64, etype string) IEntity
- func (this *Entities) GetEntityID() 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) ReChan(eid uint64, v ITime)
- func (this *Entities) String() string
- type EntitiesMsgProc
- func (this *EntitiesMsgProc) MsgPorc_DestroyEntityRetSrv(msg *protomsg.DestroyEntityRetSrv)
- func (this *EntitiesMsgProc) MsgProc_CreateEntityReqSrv(msg *protomsg.CreateEntityReqSrv)
- func (this *EntitiesMsgProc) MsgProc_CreateEntityRetSrv(msg *protomsg.CreateEntityRetSrv)
- func (this *EntitiesMsgProc) MsgProc_DestroyEntityReqSrv(msg *protomsg.DestroyEntityReqSrv)
- func (this *EntitiesMsgProc) Srv_CreateEntityReqSrv(req *protomsg.RouteMsgSrvReq, msg *protomsg.CreateEntityReqSrv) error
- func (this *EntitiesMsgProc) Srv_DestroyEntityReqSrv(req *protomsg.RouteMsgSrvReq, msg *protomsg.DestroyEntityReqSrv) error
- type Entity
- func (this *Entity) Destroy()
- func (this *Entity) Init() (err error)
- func (this *Entity) Loop()
- func (this *Entity) Looped()
- func (this *Entity) Looping()
- func (this *Entity) OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, ...) error
- func (this *Entity) OnPanic(err error)
- func (e *Entity) ReLoop()
- func (this *Entity) SyncDirtyProps()
- func (this *Entity) SyncSrvPropsAll(stype global.ServerTypeEnum)
- type EntityBase
- func (e *EntityBase) AddGroup(g string)
- func (e *EntityBase) DelGroup(g string)
- func (e *EntityBase) GetDBID() uint64
- func (e *EntityBase) GetEntities() IEntities
- func (e *EntityBase) GetEntityID() uint64
- func (e *EntityBase) GetEntityState() EntityStateEnum
- func (e *EntityBase) GetGroup(g string) bool
- func (e *EntityBase) GetGroups() *sync.Map
- func (e *EntityBase) GetSpaceID() uint64
- func (e *EntityBase) GetType() string
- func (this *EntityBase) OnCreated(etype string, eid, dbid uint64, spacePtr IEntities, param ...interface{})
- func (e *EntityBase) SetEntityState(st EntityStateEnum)
- func (this *EntityBase) String() string
- type EntityRun
- type EntitySess
- func (this *EntitySess) CloseClientSess()
- func (this *EntitySess) CreateEntityByStype(stye global.ServerTypeEnum, spid, sid uint64, callbackf global.RouteCallBackF) error
- func (this *EntitySess) DelayPost(stye global.ServerTypeEnum, msg msgdef.IMsg)
- func (this *EntitySess) DestroyEntityByStype(stye global.ServerTypeEnum, callbackf global.RouteCallBackF) error
- func (this *EntitySess) GetClientSess() sess.INetSess
- func (this *EntitySess) GetSrvByStype(styp uint32) (*EntitySrvInfo, error)
- func (e *EntitySess) GetSrvInfoAll() []*EntitySrvInfo
- func (this *EntitySess) IsExistSID(srvid uint64) bool
- func (this *EntitySess) OnCreated(fly bool, real IEntity, etype string, eid, dbid uint64, spacePtr IEntities, ...)
- func (this *EntitySess) Post(stye global.ServerTypeEnum, msg msgdef.IMsg) error
- func (this *EntitySess) PostBuf(data []byte) error
- func (this *EntitySess) RefreshSrvIDS()
- func (this *EntitySess) RegEntity() (err error)
- func (this *EntitySess) SetClientSess(v sess.INetSess)
- func (e *EntitySess) SetSrvInfo(v []*EntitySrvInfo)
- func (this *EntitySess) UnRegEntity()
- type EntitySrvInfo
- type EntityStateEnum
- type EntityTime
- type Entity_Proc
- type IBase
- type IClientSess
- type IDelayCall
- type IEntities
- type IEntity
- type IEntityReal
- type ILoop
- type IPost
- type IRun
- type ITime
- type RedisUtilEntity
- func (this *RedisUtilEntity) Expire()
- func (util *RedisUtilEntity) GetSrvInfoByStype(styp global.ServerTypeEnum) (srvid, spid uint64, err error)
- func (util *RedisUtilEntity) GetSrvInfos() (result []*EntitySrvInfo, err error)
- func (util *RedisUtilEntity) RegEntity(etyp string, dbid uint64) (err error)
- func (util *RedisUtilEntity) RegSrvID(stype global.ServerTypeEnum, srvid, spid uint64) error
- func (util *RedisUtilEntity) UnRegSrvID(srvType global.ServerTypeEnum, srvID uint64, spaceID uint64) (result error)
- func (util *RedisUtilEntity) UnregEntity() error
- type SimpleEntity
- func (this *SimpleEntity) Destroy()
- func (this *SimpleEntity) Init() error
- func (this *SimpleEntity) Loop()
- func (this *SimpleEntity) Looped()
- func (this *SimpleEntity) Looping()
- func (this *SimpleEntity) OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, ...) error
- func (this *SimpleEntity) ReLoop()
- type TypeMgr
Constants ¶
const (
//Ntt类型 Player
Entity_Type_Player = "Player"
)
Variables ¶
var ( //eid 已存在 ErrNtt_EID_Exist = common.NewError(-1, "entity eid:%d exist.") // eid 不存在 ErrNtt_EID_Not_Exist = common.NewError(-1, "entity eid:%d not exist.") //对象不在指定服务器上 ErrNtt_Stype_Not_Exist = common.NewError(-1, "entity eid:%d stype:%d not exist.") // 对象已存在 ErrNtt_Stype_Exist = common.NewError(-1, "entity eid:%d stype:%d exist.") //这个对像是Fly ErrNtt_Fly = common.NewError(-1, "entity eid:%d is fly.") // 对象不是IEntityProp ErrNtt_Struct_Not_Props = common.NewError(-1, "Entity type %T not is IEntityProp") )
Functions ¶
func PackEntityMsgRet ¶
func PackEntityMsgRet(nttmd IBase, msg msgdef.IMsg) (result *protomsg.EntityMsgRet)
打包成发给客户端的消息
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)
创建子对象 etype:实例对象类型 eid:实例的唯一ID dbid:实例持久化的唯一ID,如果没有持久化可以使用eid一样 fly:是否为自由对象,不是自由对象时,需要redis里注册路由
func (*Entities) DestroyEntityByStype ¶
func (this *Entities) DestroyEntityByStype(eid uint64, stype global.ServerTypeEnum, callbackf global.RouteCallBackF) error
删除指定服务器上的子对象; 删除后,会调用callbackf
func (*Entities) GetEntityByDBID ¶
获取子对象使用DBID
func (*Entities) GetEntityID ¶
本空间的ID 默认为0,表示自己是service层的管理器,如果是space,对应的space会重载这个接口
func (*Entities) RangeByGroup ¶
按分组遍历组内所有成员
func (*Entities) RangeByType ¶
按类型遍历组内所有成员
type EntitiesMsgProc ¶
type EntitiesMsgProc struct {
// contains filtered or unexported fields
}
func (*EntitiesMsgProc) MsgPorc_DestroyEntityRetSrv ¶
func (this *EntitiesMsgProc) MsgPorc_DestroyEntityRetSrv(msg *protomsg.DestroyEntityRetSrv)
func (*EntitiesMsgProc) MsgProc_CreateEntityReqSrv ¶
func (this *EntitiesMsgProc) MsgProc_CreateEntityReqSrv(msg *protomsg.CreateEntityReqSrv)
func (*EntitiesMsgProc) MsgProc_CreateEntityRetSrv ¶
func (this *EntitiesMsgProc) MsgProc_CreateEntityRetSrv(msg *protomsg.CreateEntityRetSrv)
func (*EntitiesMsgProc) MsgProc_DestroyEntityReqSrv ¶
func (this *EntitiesMsgProc) MsgProc_DestroyEntityReqSrv(msg *protomsg.DestroyEntityReqSrv)
func (*EntitiesMsgProc) Srv_CreateEntityReqSrv ¶
func (this *EntitiesMsgProc) Srv_CreateEntityReqSrv(req *protomsg.RouteMsgSrvReq, msg *protomsg.CreateEntityReqSrv) error
func (*EntitiesMsgProc) Srv_DestroyEntityReqSrv ¶
func (this *EntitiesMsgProc) Srv_DestroyEntityReqSrv(req *protomsg.RouteMsgSrvReq, msg *protomsg.DestroyEntityReqSrv) error
type Entity ¶
type Entity struct { /* 组合 */ // 基础通信路由有关 EntitySess // ITime实现 EntityTime // 支持独立协程启动 EntityRun //属性同步器(有可能为空) *PropsSyncContainer // contains filtered or unexported fields }
支持路由通信、属性同步、时间同步 完整Entity对象
func (*Entity) OnCreated ¶
func (this *Entity) OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, param ...interface{}) error
在创建对象的时候调用 eid:实例的唯一ID etype:实例对象类型 dbid:实例持久化的唯一ID,如果没有持久化可以使用eid一样,也可以为0 realPtr:最外面的实例对象引用 spacePtr:最外面的实例所在空间的引用 fly:是否为自由对象,不是自由对象时,需要redis里注册路由
func (*Entity) SyncSrvPropsAll ¶
func (this *Entity) SyncSrvPropsAll(stype global.ServerTypeEnum)
同步本服务器管理属性给对象目标服务器
type EntityBase ¶
type EntityBase struct {
// contains filtered or unexported fields
}
EntityBase 实体基础结构,实现IEntityBase接口 字段说明:
- entityType: 实体类型标识
- entityID: 系统内唯一实体标识
- dbid: 数据库持久化ID
- spaceID: 所属空间标识
- groups: 并发安全的分组集合(使用sync.Map实现)
- state: 原子操作维护的实体状态
- spacePtr: 指向所属实体集合的接口引用
func (*EntityBase) AddGroup ¶
func (e *EntityBase) AddGroup(g string)
AddGroup 添加实体到指定分组 参数:
- g: 分组名称
func (*EntityBase) DelGroup ¶
func (e *EntityBase) DelGroup(g string)
DelGroup 从指定分组移除实体 参数:
- g: 分组名称
func (*EntityBase) GetEntities ¶
func (e *EntityBase) GetEntities() IEntities
GetEntities 获取实体所属集合接口 返回:
- IEntities: 指向包含该实体的集合对象
func (*EntityBase) GetEntityState ¶
func (e *EntityBase) GetEntityState() EntityStateEnum
GetEntityState 获取当前实体状态 返回:
- EntityStateEnum: 使用原子操作读取的状态值
func (*EntityBase) GetGroup ¶
func (e *EntityBase) GetGroup(g string) bool
GetGroup 检查是否属于指定分组 参数:
- g: 分组名称
返回:
- bool: true表示属于该分组
func (*EntityBase) GetGroups ¶
func (e *EntityBase) GetGroups() *sync.Map
GetGroups 获取实体所属全部分组 返回:
- *sync.Map: 并发安全的分组集合指针(使用Load/Store方法操作)
func (*EntityBase) OnCreated ¶
func (this *EntityBase) OnCreated(etype string, eid, dbid uint64, spacePtr IEntities, param ...interface{})
func (*EntityBase) SetEntityState ¶
func (e *EntityBase) SetEntityState(st EntityStateEnum)
SetEntityState 设置实体状态 参数:
- st: 要设置的状态枚举值
func (*EntityBase) String ¶
func (this *EntityBase) String() string
String 生成实体描述字符串 返回格式:[Type:{类型} EntityID:{实体ID} DBID:{存储ID} SpaceID:{空间ID}]
type EntityRun ¶
type EntityRun struct {
// contains filtered or unexported fields
}
func (*EntityRun) GetIsFailLoad ¶
是否加载失败,如果失败,后面的逻辑就不继续下去了
type EntitySess ¶
type EntitySess struct { EntityBase *msghandler.MsgHandler //对象身上所有需要垮协程的数量读写的时候,用到的锁 Mux sync.RWMutex // 直连模式, ServerTypeClient类型不经过转发 IsDirectMode atomic.Bool // contains filtered or unexported fields }
带链接的Entity的组件
func (*EntitySess) CreateEntityByStype ¶
func (this *EntitySess) CreateEntityByStype(stye global.ServerTypeEnum, spid, sid uint64, callbackf global.RouteCallBackF) error
去指定服务器上创建副本
func (*EntitySess) DelayPost ¶
func (this *EntitySess) DelayPost(stye global.ServerTypeEnum, msg msgdef.IMsg)
DelayPost 延迟发送消息, 在帧尾发送
func (*EntitySess) DestroyEntityByStype ¶
func (this *EntitySess) DestroyEntityByStype(stye global.ServerTypeEnum, callbackf global.RouteCallBackF) error
删除目标服务器上的本对象副本
func (*EntitySess) GetSrvByStype ¶
func (this *EntitySess) GetSrvByStype(styp uint32) (*EntitySrvInfo, error)
获取服务器信息
func (*EntitySess) IsExistSID ¶
func (this *EntitySess) IsExistSID(srvid uint64) bool
本对象有没有连接指点的服务器
func (*EntitySess) OnCreated ¶
func (this *EntitySess) OnCreated(fly bool, real IEntity, etype string, eid, dbid uint64, spacePtr IEntities, param ...interface{})
OnCreated 实体创建时调用
func (*EntitySess) Post ¶
func (this *EntitySess) Post(stye global.ServerTypeEnum, msg msgdef.IMsg) error
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 EntityTime ¶
type EntityTime struct {
// contains filtered or unexported fields
}
func (*EntityTime) OnCreated ¶
func (this *EntityTime) OnCreated(now time.Time)
func (*EntityTime) SetTickerNow ¶
func (this *EntityTime) SetTickerNow(n time.Time)
设置TICK的时间 只有系统协程可以对子协程做
type Entity_Proc ¶
type Entity_Proc struct {
// contains filtered or unexported fields
}
对象消息
func (*Entity_Proc) MsgProc_EntityRegNtf ¶
func (this *Entity_Proc) MsgProc_EntityRegNtf(msg *protomsg.EntityRegNtf)
func (*Entity_Proc) MsgProc_SyncEntityProps ¶
func (this *Entity_Proc) MsgProc_SyncEntityProps(msg *protomsg.SyncEntityProps)
type IBase ¶
type IBase interface { //字符串化信息 String() string /* GetDBID 获取当前实体关联的数据库唯一标识符 返回值: 数据库ID(uint64类型) */ GetDBID() uint64 /* GetEntityID 获取当前实体的唯一标识符 返回值: 实体ID(uint64类型) */ GetEntityID() uint64 /* GetType 获取实体类型标识符 返回值: 实体类型描述字符串 */ GetType() string /* GetSpaceID 获取实体所属空间的标识符 返回值: 空间ID(uint64类型) */ GetSpaceID() uint64 /* AddGroup 将实体添加到指定组 参数g: 要添加的组名称(string类型) */ AddGroup(g string) /* DelGroup 将实体从指定组移除 参数g: 要移除的组名称(string类型) */ DelGroup(g string) /* GetGroups 获取实体所属的所有组集合 返回值: 线程安全的组集合指针(sync.Map类型),存储格式为[组名:struct{}] */ GetGroups() *sync.Map /* GetGroup 检查实体是否属于指定组 参数g: 要检查的组名称(string类型) 返回值: 存在返回true,否则false */ GetGroup(g string) bool /* GetEntityState 获取当前实体状态 返回值: 实体状态枚举值(EntityStateEnum类型) */ GetEntityState() EntityStateEnum /* SetEntityState 设置实体状态 参数st: 要设置的状态枚举值(EntityStateEnum类型) */ SetEntityState(st EntityStateEnum) /* GetEntities 获取关联的实体集合接口 返回值: 实体集合接口(IEntities类型),用于批量操作关联实体 */ GetEntities() IEntities }
IBase 定义实体基础接口,包含实体核心属性和行为管理 方法列表:
- String: 获取实体字符串化信息
- 属性访问:DBID/实体ID/类型/空间ID
- 分组管理:添加/删除/查询分组
- 状态管理:获取/设置实体状态
- 空间关系:获取所属实体集合
type IClientSess ¶
type IClientSess interface { IBase msghandler.IMsgHandler //获取连接 GetClientSess() sess.INetSess // 设置链接 SetClientSess(v sess.INetSess) // 关闭连接 CloseClientSess() // 发消息给客户端的二进制消息 PostBuf(data []byte) error //发消息出去 Post(stye global.ServerTypeEnum, msg msgdef.IMsg) error // DelayPost 延迟发送消息, 在帧尾发送 DelayPost(stye global.ServerTypeEnum, msg msgdef.IMsg) //获取服务器信息 GetSrvByStype(styp uint32) (*EntitySrvInfo, error) // 刷新对象路由信息 RefreshSrvIDS() // 本对象有没有连接指点的服务器 IsExistSID(srvid uint64) bool // 删除目标服务器上的本对象副本 DestroyEntityByStype(stye global.ServerTypeEnum, callbackf global.RouteCallBackF) error }
带链接的Entity的组件
type IDelayCall ¶
type IDelayCall interface { //在帧尾回调这个函数,当前立即返回 CallDelay(f CallDelayF) //在帧尾回调这个函数,当前协程会卡住 CallDelayWait(f CallDelayF) //调用存储的函数 Exec() }
支持回调的接口
type IEntities ¶
type IEntities interface { //这个需要子类实现 IMsgHandler //这个需要子类实现 IDelayCall //Loop时的时间 GetNowTime() time.Time //初始化 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 // 删除指定服务器上的子对象; 删除后,会调用callbackf DestroyEntityByStype(eid uint64, stype global.ServerTypeEnum, callbackf global.RouteCallBackF) 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) // 添加子对象loop信号量 AddChan(uint64, ITime) // 移除子对象loop信号量 ReChan(uint64, ITime) //字符串化信息 String() string //本空间的ID GetEntityID() uint64 //操作子协程的管理器 GetThreadGo() *threads.ThreadGo }
type IEntity ¶
被管理的Entity对象需要实现的最小接口
1.实现IEntityBase接口 2.实现IMsgHandler接口 3.实现ITime接口 4.需要实现自运行和对象生命周期的方法 5.实现IRun接口
type ILoop ¶
type ILoop interface { /* 在创建对象的时候调用 eid:实例的唯一ID etype:实例对象类型 dbid:实例持久化的唯一ID,如果没有持久化可以使用eid一样 realPtr:最外面的实例对象引用 spacePtr:最外面的实例所在空间的引用 fly:是否为自由对象,不是自由对象时,需要redis里注册路由 */ OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, param ...interface{}) error //初始化 Init() error //循环调用 Loop() //循环调用中间 Looping() //循环调用结尾 Looped() //销毁 Destroy() //恢复到Loop状态 ReLoop() //发生异常的时候 OnPanic(err error) // contains filtered or unexported methods }
type IPost ¶
type IPost interface { props.IProps IClientSess // 同步脏属性给别的服务器和客户端 SyncDirtyProps() // 同步本服务器管理属性给对象目标服务器 SyncSrvPropsAll(stype global.ServerTypeEnum) }
Entity对象通讯有关的接口
type RedisUtilEntity ¶
type RedisUtilEntity struct {
// contains filtered or unexported fields
}
对象的redis操作集合
func NewRedisUtilEntity ¶
func NewRedisUtilEntity(eid uint64) (result *RedisUtilEntity)
对象的redis操作集合
func (*RedisUtilEntity) GetSrvInfoByStype ¶
func (util *RedisUtilEntity) GetSrvInfoByStype(styp global.ServerTypeEnum) (srvid, spid uint64, err error)
获取指定服务类型信息
func (*RedisUtilEntity) GetSrvInfos ¶
func (util *RedisUtilEntity) GetSrvInfos() (result []*EntitySrvInfo, err error)
获取对象在所有服务器上的路由信息
func (*RedisUtilEntity) RegEntity ¶
func (util *RedisUtilEntity) RegEntity(etyp string, dbid uint64) (err error)
注册这个对象信息 一般是有链接的服务器会使用这个
func (*RedisUtilEntity) RegSrvID ¶
func (util *RedisUtilEntity) RegSrvID(stype global.ServerTypeEnum, srvid, spid uint64) error
注册服务器
func (*RedisUtilEntity) UnRegSrvID ¶
func (util *RedisUtilEntity) UnRegSrvID(srvType global.ServerTypeEnum, srvID uint64, spaceID uint64) (result error)
UnRegSrvID 删除注册信息
func (*RedisUtilEntity) UnregEntity ¶
func (util *RedisUtilEntity) UnregEntity() error
注销对象信息 一般是有链接的服务器会使用这个
type SimpleEntity ¶
type SimpleEntity struct { /* 组合 */ // 属性 EntityBase // ITime实现 EntityTime // 支持独立协程启动 EntityRun //消息路由 *MsgHandler }
无属性的entity对象
func (*SimpleEntity) OnCreated ¶
func (this *SimpleEntity) OnCreated(etype string, eid, dbid uint64, realPtr IEntity, spacePtr IEntities, fly bool, param ...interface{}) error
在创建对象的时候调用 eid:实例的唯一ID etype:实例对象类型 dbid:实例持久化的唯一ID,如果没有持久化可以使用eid一样,也可以为0 realPtr:最外面的实例对象引用 spacePtr:最外面的实例所在空间的引用 fly:是否需要在redis中注册路由信息