props

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: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PackProp_Role uint8 = 1
	PackProp_AOI  uint8 = 2
)

Variables

View Source
var (
	ErrDef_FileNotFound  = common.NewError("read entity def file error")
	ErrDef_JsonUnmarshal = common.NewError("read entity def json unmarshal error")
	ErrDef_Fill          = common.NewError("read entity def fill error")
	//属性不存在
	ErrProp_NotExist = errors.New("prop index not exist")
)

Functions

func PackProps

func PackProps(e *PropDirtyMgr, packType uint8) (result []*protomsg.SyncProp)

PackProps 打包属性

func PackPropsToProtobuf

func PackPropsToProtobuf(props []IProp) (result []*protomsg.SyncProp)

PackPropsToProtobuf 把属列表打包成proto

Types

type Def

type Def struct {
	Name         string               //主类型名字
	FieldsByID   map[uint32]*FieldDef //key是Index的字段map
	FieldsByName map[string]*FieldDef //key是Name的字段map
}

Def 独立的实体定义

func LoadDef

func LoadDef(filePath string) (*Def, error)

加载entity的jsonc配置

type EDPSorterType

type EDPSorterType int8

分流器类型

const (
	//同步分流器
	EDPSorterTypeSync EDPSorterType = 1
	//保存分流器
	EDPSorterTypeSave EDPSorterType = 2
)

type FieldDef

type FieldDef struct {
	Name     string              //字段名字
	Index    uint32              //字段的唯一ID
	Desc     string              //字段说明
	TypeName string              //类型名字
	SubTypes map[string]struct{} //哪些子类型有这个字段

	WatchSrvs []uint32 //关心的服务器类型
	IsClient  bool     //是否其他客户端需要
	IsMRole   bool     //是否自己客户端需要
	SaveSrv   uint32   //做数据落地的服务器类型
	IsSync    bool     //当这个字段值发生变化时,是否需要同步给别的服务器

	RefType reflect.Type //实例类型
}

单个字段

type IDef

type IDef interface {
	SetPropDirtyMgr(pmgr *PropDirtyMgr)
}

自动生成的属性包装代码实现的接口

type IProp

type IProp interface {
	// 获取字段Index
	GetIndex() uint32
	// 获取字段名字
	GetName() string
	GetField() *FieldDef
	// 设置属性值(标脏)
	SetValue(v interface{})
	// 设置属性值(不标脏)
	LoadValue(v interface{})
	// 获取属性值
	GetValue() interface{}
	// 是否同步脏数据
	IsSyncDirty() bool
	// 是否保存脏数据
	IsSaveDirty() bool
	// 是否标脏了
	IsDirty(dType EDPSorterType) bool

	// 设置标脏
	SetDirty()
	// 设置指定分流器标脏
	SetDirty2(dType EDPSorterType)
	// 从同步消息里读数据
	ReadSyncProp(msg *protomsg.SyncProp)
	// contains filtered or unexported methods
}

单个属性更新器

type IProps

type IProps interface {
	SetProp(index uint32, value interface{})
	PropDirty(index uint32)
	IsDirty(index uint32, dType EDPSorterType) bool
	PropDirty2(index uint32, dType EDPSorterType)
	GetProp(index uint32) interface{}
	//尝试获取属性,如果没有拿到就返回错误
	TryGetProp(index uint32) (interface{}, error)
	GetPropRawByName(name string) IProp
	GetPropRaw(index uint32) IProp
}

IProps Entity属性相关的操作

type IPropsDirtySorter

type IPropsDirtySorter interface {
	// 标记脏数据
	FlagDirty(p IProp)
	//分流器类型
	GetSorterType() EDPSorterType
	// 列表获取回调
	HandlerAllList(consumeListFunc func(list []IProp) bool)
	// 成员遍历回调
	HandlerForEach(consumeFunc func(p IProp))
	//获取脏数据
	ListCount() int
	//弹出所有脏数据
	PopDirtyList() (result []IProp)
}

分流器接口

type PropDirtyMgr

type PropDirtyMgr struct {
	PropList   map[uint32]IProp //所有字段按ID查
	PropByName map[string]IProp //所有字段按名字查
	// contains filtered or unexported fields
}

属性管理器 可以管理属性的脏字段

func NewPropDirtyMgr

func NewPropDirtyMgr() (result *PropDirtyMgr)

func (*PropDirtyMgr) AddSorter

func (e *PropDirtyMgr) AddSorter(sorterType EDPSorterType)

添加分流器

func (*PropDirtyMgr) DelSorter

func (e *PropDirtyMgr) DelSorter(sorterType EDPSorterType)

删除分流器

func (*PropDirtyMgr) ForEachProp

func (this *PropDirtyMgr) ForEachProp(callBack func(p IProp))

func (*PropDirtyMgr) GetDirtyPropSorter

func (e *PropDirtyMgr) GetDirtyPropSorter(sorterType EDPSorterType) IPropsDirtySorter

////////////////////////////// 属性脏分流器操作

func (*PropDirtyMgr) GetProp

func (this *PropDirtyMgr) GetProp(index uint32) interface{}

func (*PropDirtyMgr) GetPropRaw

func (this *PropDirtyMgr) GetPropRaw(index uint32) IProp

func (*PropDirtyMgr) GetPropRawByName

func (this *PropDirtyMgr) GetPropRawByName(name string) IProp

func (*PropDirtyMgr) HandlerSorterResult

func (e *PropDirtyMgr) HandlerSorterResult(sorterType EDPSorterType, consumeFunc func([]IProp) bool) bool

按类型获取脏数据列表回调

func (*PropDirtyMgr) HandlerSorterResultForeach

func (e *PropDirtyMgr) HandlerSorterResultForeach(sorterType EDPSorterType, consumeFunc func(p IProp)) bool

按类型遍历脏数据

func (*PropDirtyMgr) InitProp

func (this *PropDirtyMgr) InitProp(def *Def)

func (*PropDirtyMgr) IsDirty

func (this *PropDirtyMgr) IsDirty(index uint32, dType EDPSorterType) bool

func (*PropDirtyMgr) PropDirty

func (this *PropDirtyMgr) PropDirty(index uint32)

func (*PropDirtyMgr) PropDirty2

func (this *PropDirtyMgr) PropDirty2(index uint32, dType EDPSorterType)

func (*PropDirtyMgr) SetProp

func (this *PropDirtyMgr) SetProp(index uint32, value interface{})

func (*PropDirtyMgr) SetSorter

func (e *PropDirtyMgr) SetSorter(stype EDPSorterType, sorter IPropsDirtySorter)

设置或替换分流器

func (*PropDirtyMgr) SetSrvType

func (this *PropDirtyMgr) SetSrvType(srvType uint32)

设置属性为指定服务器类型

func (*PropDirtyMgr) SetSubType

func (this *PropDirtyMgr) SetSubType(subType string)

设置属性为指定子类型

func (*PropDirtyMgr) TryGetProp

func (this *PropDirtyMgr) TryGetProp(index uint32) (interface{}, error)

尝试获取属性,如果没有拿到就返回错误

type PropInfo

type PropInfo[T any] struct {
	// contains filtered or unexported fields
}

单个属性更新器

func NewProp

func NewProp[T any](pmgr *PropDirtyMgr, index uint32) (result *PropInfo[T])

新建属性到管理器中

func (*PropInfo[T]) GetField

func (this *PropInfo[T]) GetField() *FieldDef

获取属性的字段信息

func (*PropInfo[T]) GetIndex

func (this *PropInfo[T]) GetIndex() uint32

获取字段Index

func (*PropInfo[T]) GetName

func (this *PropInfo[T]) GetName() string

获取字段名字

func (*PropInfo[T]) GetValue

func (this *PropInfo[T]) GetValue() interface{}

获取字段值

func (*PropInfo[T]) GetValueT

func (this *PropInfo[T]) GetValueT() T

获取属性值

func (*PropInfo[T]) IsDirty

func (this *PropInfo[T]) IsDirty(dType EDPSorterType) bool

是否标脏了

func (*PropInfo[T]) IsSaveDirty

func (this *PropInfo[T]) IsSaveDirty() bool

是否保存脏数据

func (*PropInfo[T]) IsSyncDirty

func (this *PropInfo[T]) IsSyncDirty() bool

是否同步脏数据

func (*PropInfo[T]) LoadValue

func (this *PropInfo[T]) LoadValue(v interface{})

设置属性值(不标脏)

func (*PropInfo[T]) LoadValueT

func (this *PropInfo[T]) LoadValueT(v T)

设置属性值(不标脏)

func (*PropInfo[T]) ReadSyncProp

func (this *PropInfo[T]) ReadSyncProp(msg *protomsg.SyncProp)

从同步消息里读数据

func (*PropInfo[T]) SetDirty

func (this *PropInfo[T]) SetDirty()

设置标脏

func (*PropInfo[T]) SetDirty2

func (this *PropInfo[T]) SetDirty2(dType EDPSorterType)

设置指定分流器标脏

func (*PropInfo[T]) SetValue

func (this *PropInfo[T]) SetValue(v interface{})

设置属性值(标脏)

func (*PropInfo[T]) SetValueT

func (this *PropInfo[T]) SetValueT(v T)

设置属性值(标脏)

type PropsDirtySorter

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

func NewPropsDirtySorter

func NewPropsDirtySorter(sorter EDPSorterType) *PropsDirtySorter

func (*PropsDirtySorter) FlagDirty

func (this *PropsDirtySorter) FlagDirty(p IProp)

标记脏数据

func (*PropsDirtySorter) GetSorterType

func (this *PropsDirtySorter) GetSorterType() EDPSorterType

func (*PropsDirtySorter) HandlerAllList

func (this *PropsDirtySorter) HandlerAllList(consumeListFunc func(list []IProp) bool)

列表获取回调

func (*PropsDirtySorter) HandlerForEach

func (this *PropsDirtySorter) HandlerForEach(consumeFunc func(p IProp))

成员遍历回调

func (*PropsDirtySorter) ListCount

func (this *PropsDirtySorter) ListCount() int

func (*PropsDirtySorter) PopDirtyList

func (this *PropsDirtySorter) PopDirtyList() (result []IProp)

弹出脏数据 这里需要注意,返回的切片与分流器里的是同一份数组,需要确保拿到这个切片后, 只做遍历,不做保留处理;

type PropsSyncContainer

type PropsSyncContainer struct {
	*PropDirtyMgr

	//需要同步给其他服务器的数据
	DirtySrvProps map[uint32][]IProp

	DirtyAOIMsg   []*protomsg.SyncProp
	DirtyMRoleMsg []*protomsg.SyncProp
}

PropsSyncContainer 需要进行属性同步的部分

func NewPropsSyncContainer

func NewPropsSyncContainer() *PropsSyncContainer

func (*PropsSyncContainer) ForEachSrvDirty

func (this *PropsSyncContainer) ForEachSrvDirty(f func(uint32, []IProp))

遍历服务器脏数据,会清空脏数据

func (*PropsSyncContainer) GetDirtyAOIMsg

func (c *PropsSyncContainer) GetDirtyAOIMsg() []*protomsg.SyncProp

获取AOI需要的差量属性更新

func (*PropsSyncContainer) GetDirtyMRoleMsg

func (c *PropsSyncContainer) GetDirtyMRoleMsg() []*protomsg.SyncProp

获取自身需要的差量属性更新

func (*PropsSyncContainer) PackPropsSyncProps

func (c *PropsSyncContainer) PackPropsSyncProps()

打包同步数据:给自己的,给AOI的,给其他服务器的

func (*PropsSyncContainer) ProsSyncInit

func (c *PropsSyncContainer) ProsSyncInit()

Init 初始化

Jump to

Keyboard shortcuts

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