lhcore

package
v0.0.0-...-6b3b694 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStageNotFound = errors.New("stage not found")
	ErrItemNotFound  = errors.New("item not found")
)

Functions

func Module

func Module() fx.Option

Types

type DropElement

type DropElement struct {
	IDSet

	// Times describes the amount of occurances of reports such drop
	// may possibly drop.
	Times DropElementValue
	// Quantity describes the amount of occurances that such item has dropped
	Quantity DropElementValue

	// Subscriptions, map[ClientID]*Sub
	Subscriptions sync.Map
}

DropElement contains all metrics for a drop element identified by an IDSet, as well all subscriptions to such DropElement.

func (*DropElement) AddSub

func (e *DropElement) AddSub(sub *Sub)

func (*DropElement) CutOut

func (e *DropElement) CutOut(times, quantity, generation uint64)

func (*DropElement) Incr

func (e *DropElement) Incr(times, quantity, generation uint64)

func (*DropElement) RemoveSub

func (e *DropElement) RemoveSub(sub *Sub)

type DropElementValue

type DropElementValue struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

DropElementValue

func (*DropElementValue) CutOut

func (d *DropElementValue) CutOut(value, generation uint64)

func (*DropElementValue) Incr

func (d *DropElementValue) Incr(delta, generation uint64) uint64

func (*DropElementValue) Sum

func (d *DropElementValue) Sum() uint64

type DropSet

type DropSet struct {

	// CombineElements is used to get a singular element (if exists)
	// by indexing its ServerID, StageID, and ItemID.
	// Such indexing uint64 is calculated using IDSet#ID().
	CombineElements map[uint64]*DropElement

	// StageElements is used to get a list of elements for a particular (ServerID, StageID) pair (if exists)
	// It is actually map[EntityID]map[EntityID]*DropElement, in which
	// the first EntityID consists of a (ServerID, StageID) pair, and
	// the second EntityID consists of a (ServerID, ItemID) pair.
	StageElements map[uint32]map[uint32]*DropElement

	// ItemElements is used to get a list of elements for a particular (ServerID, ItemID) pair (if exists)
	// It is actually map[EntityID]map[EntityID]*DropElement, in which
	// the first EntityID consists of a (ServerID, ItemID) pair, and
	// the second EntityID consists of a (ServerID, StageID) pair.
	ItemElements map[uint32]map[uint32]*DropElement
	// contains filtered or unexported fields
}

DropSet consists a completed collection of all `DropElement`s existing on such instance. It stores a singular `DropElement` into three different maps, to improve index efficiencies under different workloads. See docuemntation on those particular maps for their intended usage.

func NewDropSet

func NewDropSet() *DropSet

func (*DropSet) GetOrCreateElement

func (d *DropSet) GetOrCreateElement(idset IDSet) *DropElement

func (*DropSet) IncrTimes

func (d *DropSet) IncrTimes(stageId uint32, server uint8, generation uint64)

func (*DropSet) RemoveSub

func (d *DropSet) RemoveSub(sub *Sub)

func (*DropSet) ReplaceSubToItemElements

func (d *DropSet) ReplaceSubToItemElements(itemID uint32, server uint8, sub *Sub) error

func (*DropSet) ReplaceSubToStageElements

func (d *DropSet) ReplaceSubToStageElements(stageID uint32, server uint8, sub *Sub) error

type Element

type Element struct {
	IDSet

	LiteValue
}

Element consists of a minimal subscribable values stored in LiteValue that is identified by lhcore.IDSet. A zero LiteValue is ready to be used.

type IDPair

type IDPair struct {
	ServerID uint8
	EntityID uint32
}

func (IDPair) Hash

func (p IDPair) Hash() uint32

type IDSet

type IDSet struct {
	ServerID uint8
	StageID  uint32
	ItemID   uint32
}

func (IDSet) GoString

func (s IDSet) GoString() string

func (IDSet) Hash

func (s IDSet) Hash() uint64

func (IDSet) ItemPair

func (s IDSet) ItemPair() IDPair

func (IDSet) StagePair

func (s IDSet) StagePair() IDPair

type LiteValue

type LiteValue struct {
	Quantity uint64
	Times    uint64
}

LiteValue consists of a minimal representation of values to subscribe with. A zero LiteValue is ready to be used.

type Sub

type Sub struct {
	ClientID string
	// contains filtered or unexported fields
}

func NewSub

func NewSub(clientId string) *Sub

func (*Sub) Flush

func (s *Sub) Flush() []Element

func (*Sub) Get

func (s *Sub) Get(id IDSet) *LiteValue

func (*Sub) Set

func (s *Sub) Set(id IDSet, value *LiteValue)

func (*Sub) Swap

func (s *Sub) Swap() *sync.Map

Jump to

Keyboard shortcuts

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