entity

package
v0.0.0-...-0012533 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

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

func RetMsg

func RetMsg(user IClientSess, msg msgdef.IMsg, err error)

回复消息 user 回复对象 retmsgid 回复消息号 err 错误信息

func ReturnLLoginNtf

func ReturnLLoginNtf(user IClientSess, err error)

让客户端返回登录消息

Types

type CallDelayF

type CallDelayF func()

回调函数

type DelayCallHost

type DelayCallHost struct {
	// contains filtered or unexported fields
}

用于回调函数的结构

func (*DelayCallHost) CallDelay

func (this *DelayCallHost) CallDelay(f CallDelayF)

func (*DelayCallHost) CallDelayWait

func (this *DelayCallHost) CallDelayWait(f CallDelayF)

加上等待

func (*DelayCallHost) Exec

func (this *DelayCallHost) Exec()

调用函数

type Entities

type Entities struct {
	// contains filtered or unexported fields
}

对象管理器

func NewEntities

func NewEntities(isMutilThread bool, real IEntities, thgo *threads.ThreadGo) *Entities

func (*Entities) CreateEntity

func (this *Entities) CreateEntity(etype string, eid, dbid uint64, fly bool, param ...interface{}) (result IEntity, err error)

创建子对象

func (*Entities) Destroy

func (this *Entities) Destroy()

销毁 会等所有子协程结束

func (*Entities) DestroyEntity

func (this *Entities) DestroyEntity(eid uint64) error

销毁子对象

func (*Entities) GetEntity

func (this *Entities) GetEntity(eid uint64) IEntity

获取子对象

func (*Entities) GetEntityByDBID

func (this *Entities) GetEntityByDBID(dbid uint64, etype string) IEntity

获取子对象使用DBID

func (*Entities) GetID

func (this *Entities) GetID() uint64

本空间的ID 默认为0,表示自己是service层的管理器,如果是space,对应的space会重载这个接口

func (*Entities) GetThreadGo

func (this *Entities) GetThreadGo() *threads.ThreadGo

操作子协程的管理器

func (*Entities) Init

func (this *Entities) Init() error

初始化

func (*Entities) Loop

func (this *Entities) Loop()

循环调用

func (*Entities) Range

func (this *Entities) Range(f func(k, v interface{}) bool)

遍历所有成员

func (*Entities) RangeByGroup

func (this *Entities) RangeByGroup(gp string, f func(k, v any) bool)

按分组遍历组内所有成员

func (*Entities) RangeByType

func (this *Entities) RangeByType(etype string, f func(k, v any) bool)

按类型遍历组内所有成员

func (*Entities) String

func (this *Entities) String() string

字符串化信息

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) AddGroup

func (e *Entity) AddGroup(g string)

GetType 添加分组

func (*Entity) DelGroup

func (e *Entity) DelGroup(g string)

GetType 添加分组

func (*Entity) DelayPost

func (this *Entity) DelayPost(stye global.ServerTypeEnum, msg msgdef.IMsg)

DelayPost 延迟发送消息, 在帧尾发送

func (*Entity) Destroy

func (e *Entity) Destroy()

销毁

func (*Entity) EnterDestroy

func (e *Entity) EnterDestroy()

进入对象销毁程序

func (*Entity) GetClientSess

func (this *Entity) GetClientSess() sess.INetSess

获取连接

func (*Entity) GetDBID

func (e *Entity) GetDBID() uint64

GetDBID 获取实体的DBID

func (*Entity) GetEntities

func (e *Entity) GetEntities() IEntities

GetEntities 获取包含自己的Entities指针

func (*Entity) GetEntityState

func (e *Entity) GetEntityState() EntityStateEnum

GetEntityState 获取当前状态

func (*Entity) GetGroup

func (e *Entity) GetGroup(g string) bool

GetType 获取分组

func (*Entity) GetGroups

func (e *Entity) GetGroups() *sync.Map

GetType 获取分组列表

func (*Entity) GetID

func (e *Entity) GetID() uint64

GetID 获取实体ID

func (*Entity) GetRealPtr

func (e *Entity) GetRealPtr() IEntityReal

GetRealPtr 获取真实的后代对象的指针

func (*Entity) GetSpaceID

func (e *Entity) GetSpaceID() uint64

GetSpaceID 获取空间ID

func (*Entity) GetSrvByStype

func (this *Entity) GetSrvByStype(styp uint32) (*EntitySrvInfo, error)

获取服务器信息

func (*Entity) GetSrvInfoAll

func (e *Entity) GetSrvInfoAll() []*EntitySrvInfo

获取服务器路由信息

func (*Entity) GetType

func (e *Entity) GetType() string

GetType 获取实体类型

func (*Entity) GoRun

func (e *Entity) GoRun(ctx context.Context)

自运行协程的函数

func (*Entity) Init

func (e *Entity) Init() error

初始化

func (*Entity) IsDestroyed

func (e *Entity) IsDestroyed() bool

是否已销毁

func (*Entity) IsExistSID

func (this *Entity) IsExistSID(srvid uint64) bool

本对象有没有连接指点的服务器

func (*Entity) Loop

func (e *Entity) Loop()

循环调用

func (*Entity) Looped

func (e *Entity) Looped()

循环调用后

func (*Entity) Looping

func (e *Entity) Looping()

循环调用中

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) OnPanic

func (e *Entity) OnPanic(err error)

发生异常的时候

func (*Entity) PackEntityMsgRet

func (this *Entity) PackEntityMsgRet(msg msgdef.IMsg) (result *protomsg.EntityMsgRet)

打包成发给客户端的消息

func (*Entity) Post

func (this *Entity) Post(stye global.ServerTypeEnum, msg msgdef.IMsg) error

func (*Entity) PostBuf

func (this *Entity) PostBuf(data []byte) error

发消息给客户端的二进制消息

func (*Entity) ReLoop

func (e *Entity) ReLoop()

恢复到Loop状态

func (*Entity) ReadSyncProps

func (this *Entity) ReadSyncProps(li []*protomsg.SyncProp)

从同步消息中获取数据

func (*Entity) RefreshSrvIDS

func (this *Entity) RefreshSrvIDS()

刷新对象路由信息

func (*Entity) SetClientSess

func (this *Entity) SetClientSess(v sess.INetSess)

设置链接

func (*Entity) SetEntityState

func (e *Entity) SetEntityState(st EntityStateEnum)

func (*Entity) SetSrvInfo

func (e *Entity) SetSrvInfo(v []*EntitySrvInfo)

设置服务器路由信息

func (*Entity) String

func (e *Entity) String() string

func (*Entity) SyncProps

func (this *Entity) SyncProps()

同步属性给别的服务器和客户端

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) AddGroup

func (this *SimpleEntity) AddGroup(g string)

GetType 添加分组

func (*SimpleEntity) DelGroup

func (this *SimpleEntity) DelGroup(g string)

GetType 添加分组

func (*SimpleEntity) Destroy

func (e *SimpleEntity) Destroy()

销毁

func (*SimpleEntity) EnterDestroy

func (e *SimpleEntity) EnterDestroy()

进入对象销毁程序

func (*SimpleEntity) GetDBID

func (this *SimpleEntity) GetDBID() uint64

GetDBID 获取实体的DBID

func (*SimpleEntity) GetEntities

func (this *SimpleEntity) GetEntities() IEntities

GetEntities 获取包含自己的Entities指针

func (*SimpleEntity) GetEntityState

func (this *SimpleEntity) GetEntityState() EntityStateEnum

GetEntityState 获取当前状态

func (*SimpleEntity) GetGroup

func (this *SimpleEntity) GetGroup(g string) bool

GetType 获取分组

func (*SimpleEntity) GetGroups

func (this *SimpleEntity) GetGroups() *sync.Map

GetType 获取分组列表

func (*SimpleEntity) GetID

func (this *SimpleEntity) GetID() uint64

GetID 获取实体ID

func (*SimpleEntity) GetRealPtr

func (this *SimpleEntity) GetRealPtr() IEntity

GetRealPtr 获取真实的后代对象的指针

func (*SimpleEntity) GetSpaceID

func (this *SimpleEntity) GetSpaceID() uint64

GetSpaceID 获取空间ID

func (*SimpleEntity) GetType

func (this *SimpleEntity) GetType() string

GetType 获取实体类型

func (*SimpleEntity) GoRun

func (e *SimpleEntity) GoRun(ctx context.Context)

自运行协程的函数

func (*SimpleEntity) Init

func (e *SimpleEntity) Init() error

初始化

func (*SimpleEntity) IsDestroyed

func (e *SimpleEntity) IsDestroyed() bool

是否已销毁

func (*SimpleEntity) Loop

func (e *SimpleEntity) Loop()

循环调用

func (*SimpleEntity) Looped

func (e *SimpleEntity) Looped()

循环调用后

func (*SimpleEntity) Looping

func (e *SimpleEntity) Looping()

循环调用中

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) OnPanic

func (e *SimpleEntity) OnPanic(err error)

发生异常的时候

func (*SimpleEntity) ReLoop

func (e *SimpleEntity) ReLoop()

恢复到Loop状态

func (*SimpleEntity) SetEntityState

func (this *SimpleEntity) SetEntityState(st EntityStateEnum)

func (*SimpleEntity) String

func (e *SimpleEntity) String() string

type TypeMgr

type TypeMgr struct {
	// contains filtered or unexported fields
}

func GetTypeMgr

func GetTypeMgr() *TypeMgr

获取对象类型管理器

func (*TypeMgr) GetDefByName

func (mgr *TypeMgr) GetDefByName(name string) *Def

获取对象配置

func (*TypeMgr) LoadDefs

func (mgr *TypeMgr) LoadDefs(dirpath string) (err error)

加载entity的配置表 协程不安全 建议在server初始化的时候,调用

func (*TypeMgr) NewEntity

func (mgr *TypeMgr) NewEntity(name string) (result IEntity)

New对象出来

func (*TypeMgr) RegEntityType

func (mgr *TypeMgr) RegEntityType(name string, v IEntity)

注册对象类型

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL