utils

package
v0.0.0-...-677ea5f Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Rad2Deg float32 = 57.29578
	Deg2Rad float32 = 0.01745329
	HalfPi  float32 = 1.5707963267948966
)

Variables

This section is empty.

Functions

func AddSafePool

func AddSafePool(t interface{}, f func() interface{})

func AddUnsafePool

func AddUnsafePool(t interface{}, f func() interface{})

func Ceil

func Ceil(d float32, bit int32) float32

func CeilInt32

func CeilInt32(ceil, v int32) (r, o int32)

func ClampFloat

func ClampFloat(min, max, v float32) float32

func ClampInt32

func ClampInt32(min, max, v int32) int32

func CopyBytes

func CopyBytes(src []byte) []byte

func ErrorChanClosed

func ErrorChanClosed() error

func ErrorSubmitGoroutine

func ErrorSubmitGoroutine() error

func ErrorTimeout

func ErrorTimeout() error

func Floor

func Floor(d float32, bit int32) float32

func FloorInt32

func FloorInt32(floor, v int32) (r, o int32)

func GetMask

func GetMask(vals ...uint64) uint64

func GetSnowflakeId

func GetSnowflakeId() int64

func GetSnowflakeIdStr

func GetSnowflakeIdStr() string

func Int64ToStr

func Int64ToStr(id int64) string

func Int64sToStrSlice

func Int64sToStrSlice(ids ...int64) []string

func Lock

func Lock(key string)

func MaskAddVal

func MaskAddVal(val, mask uint64) uint64

func MaskDelVal

func MaskDelVal(val, mask uint64) uint64

func MaxInt32

func MaxInt32(a, b int32) int32

func MinInt32

func MinInt32(a, b int32) int32

func NewConcurrentData

func NewConcurrentData(m map[string]interface{}) *concurrentData

func NewData

func NewData(m map[string]interface{}) *data

func NewObject

func NewObject(data map[string]interface{}) *object

func NewPool

func NewPool(f func() interface{}) *sync.Pool

func NewRingBuffer

func NewRingBuffer(cap int) *ringBuffer

func NewUnsafePool

func NewUnsafePool(f func() interface{}) *nosync.Pool

func NewWeightSelector

func NewWeightSelector() *weightSelector

func NewWorkerManager

func NewWorkerManager(workerCap int, complete Action) *workerManager

func RLock

func RLock(key string)

func RUnlock

func RUnlock(key string)

func RandStr

func RandStr(n int) string

func RecycleBytes

func RecycleBytes(data []byte)

func RecyclePoolObj

func RecyclePoolObj(t interface{}, obj interface{})

func Round

func Round(d float32, bit int32) float32

func SetSnowflakeNodeId

func SetSnowflakeNodeId(nodeId int64) (err error)

func SetTrace

func SetTrace(tracer string) (err error)

func SpawnBytes

func SpawnBytes() []byte

func SpawnBytesWithLen

func SpawnBytesWithLen(l int) []byte

func SpawnPoolObj

func SpawnPoolObj(t interface{}) interface{}

func StartTickWorker

func StartTickWorker(complete Action, duration time.Duration, tick ActionInt64) *worker

@Description: 启动一个带心跳的处理器, @param executor 处理消息的方法,循环调用自身Push会被阻塞 @param complete 处理器关闭回调 @param duration 心跳间隔 @param tick 心跳处理函数,参数心跳间隔 @return *worker 处理器

func StartWorker

func StartWorker(complete Action) *worker

@Description: 启动一个处理器 @param complete 处理器关闭回调 @return *worker 处理器

func StrToInt64

func StrToInt64(id string) int64

func StrToUint16

func StrToUint16(id string) uint16

func StrToUint64

func StrToUint64(id string) uint64

func TestMask

func TestMask(val, mask uint64) bool

func TestMaskVals

func TestMaskVals(val uint64, vals ...uint64) bool

func TraceDebug

func TraceDebug(tid int64, msg string, fields ...zap.Field)

func TraceError

func TraceError(tid int64, msg string, error error, fields ...zap.Field)

func TraceInfo

func TraceInfo(tid int64, msg string, fields ...zap.Field)

func TraceSign

func TraceSign(parent int64, sign string, fields ...zap.Field) int64

func TraceWarn

func TraceWarn(tid int64, msg string, fields ...zap.Field)

func Uint16ToStr

func Uint16ToStr(id uint16) string

func Uint64ToStr

func Uint64ToStr(id uint64) string

func Unlock

func Unlock(key string)

func Vec2Angle

func Vec2Angle(v1 Vec2, v2 Vec2) float32

func Vec2Distance

func Vec2Distance(v1 Vec2, v2 Vec2) float32

func Vec2Magnitude

func Vec2Magnitude(v Vec2) float32

func Vec2TestCircular

func Vec2TestCircular(point, origin Vec2, radius float32) bool

func Vec2TestRay

func Vec2TestRay(point, origin, normal Vec2, radius, length float32) bool

func Vec2TestRect

func Vec2TestRect(point, origin, normal Vec2, width, length float32) bool

func Vec2TestSector

func Vec2TestSector(point, origin, normal Vec2, radius, angle float32) bool

func Vec3Angle

func Vec3Angle(v1 Vec3, v2 Vec3) float32

func Vec3Distance

func Vec3Distance(v1 Vec3, v2 Vec3) float32

func Vec3Magnitude

func Vec3Magnitude(v Vec3) float32

func Vec3TestCentrum

func Vec3TestCentrum(point, origin, normal Vec3, radius, angle float32) bool

圆锥

func Vec3TestCylinder

func Vec3TestCylinder(point, origin, normal Vec3, radius, length float32) bool

圆柱

func Vec3TestSphere

func Vec3TestSphere(point, origin Vec3, radius float32) bool

球体

func Wait

func Wait(action func(ch WaitCh))

func WaitOsExit

func WaitOsExit(beforeExit func())

func WaitRes

func WaitRes(action func(chan<- interface{})) (interface{}, error)

func WaitResAsync

func WaitResAsync(onComplete ActionObjErr) chan<- interface{}

func WaitTrue

func WaitTrue(action func()) chan<- bool

Types

type Action

type Action func()

@Description: 无参无返回函数别名,用于回调完成

func (Action) Invoke

func (c Action) Invoke()

@Description: 完成回调,如果为空跳过 @receiver c Action

type ActionBytes

type ActionBytes func(data []byte)

type ActionError

type ActionError func(err error)

type ActionInt64

type ActionInt64 func(v int64)

type ActionObj

type ActionObj func(obj interface{})

type ActionObjErr

type ActionObjErr func(obj interface{}, err error)

type ActionStr

type ActionStr func(str string)

type BytesBuffer

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

func NewBytesBuffer

func NewBytesBuffer(data []byte) *BytesBuffer

func (*BytesBuffer) Available

func (b *BytesBuffer) Available() uint32

func (*BytesBuffer) Bytes

func (b *BytesBuffer) Bytes() []byte

func (*BytesBuffer) Clear

func (b *BytesBuffer) Clear()

func (*BytesBuffer) Copy

func (b *BytesBuffer) Copy() []byte

func (*BytesBuffer) Length

func (b *BytesBuffer) Length() uint32

func (*BytesBuffer) Mark

func (b *BytesBuffer) Mark()

func (*BytesBuffer) Pos

func (b *BytesBuffer) Pos() uint32

func (*BytesBuffer) RAll

func (b *BytesBuffer) RAll() (v []byte)

读取剩余所有字节

func (*BytesBuffer) RBool

func (b *BytesBuffer) RBool() (v bool, err error)

func (*BytesBuffer) RBytes

func (b *BytesBuffer) RBytes(l uint16) (v []byte, err error)

func (*BytesBuffer) RBytesWithLen

func (b *BytesBuffer) RBytesWithLen() (v []byte, err error)

func (*BytesBuffer) RFloat32

func (b *BytesBuffer) RFloat32() (v float32, err error)

func (*BytesBuffer) RFloat64

func (b *BytesBuffer) RFloat64() (v float64, err error)

func (*BytesBuffer) RInt32

func (b *BytesBuffer) RInt32() (v int32, err error)

func (*BytesBuffer) RInt64

func (b *BytesBuffer) RInt64() (v int64, err error)

func (*BytesBuffer) RInt8

func (b *BytesBuffer) RInt8() (v int8, err error)

func (*BytesBuffer) RStrMapStr

func (b *BytesBuffer) RStrMapStr() (m map[string]string, err error)

func (*BytesBuffer) RString

func (b *BytesBuffer) RString() (v string, err error)

func (*BytesBuffer) RStringNoLen

func (b *BytesBuffer) RStringNoLen() (v string)

func (*BytesBuffer) RUint16

func (b *BytesBuffer) RUint16() (v uint16, err error)

func (*BytesBuffer) RUint32

func (b *BytesBuffer) RUint32() (v uint32, err error)

func (*BytesBuffer) RUint64

func (b *BytesBuffer) RUint64() (v uint64, err error)

func (*BytesBuffer) RUint8

func (b *BytesBuffer) RUint8() (v uint8, err error)

func (*BytesBuffer) RVec2

func (b *BytesBuffer) RVec2() (v Vec2, err error)

func (*BytesBuffer) RVec3

func (b *BytesBuffer) RVec3() (v Vec3, err error)

func (*BytesBuffer) RVec4

func (b *BytesBuffer) RVec4() (v Vec4, err error)

func (*BytesBuffer) RVecInt2

func (b *BytesBuffer) RVecInt2() (v VecInt2, err error)

func (*BytesBuffer) RVecInt3

func (b *BytesBuffer) RVecInt3() (v VecInt3, err error)

func (*BytesBuffer) RVecInt4

func (b *BytesBuffer) RVecInt4() (v VecInt4, err error)

func (*BytesBuffer) ResetMark

func (b *BytesBuffer) ResetMark()

func (*BytesBuffer) Rint16

func (b *BytesBuffer) Rint16() (v int16, err error)

func (*BytesBuffer) SetData

func (b *BytesBuffer) SetData(bytes []byte)

func (*BytesBuffer) SetPos

func (b *BytesBuffer) SetPos(v uint32) error

func (*BytesBuffer) ToHex

func (b *BytesBuffer) ToHex() string

func (*BytesBuffer) WBool

func (b *BytesBuffer) WBool(v bool)

func (*BytesBuffer) WBytes

func (b *BytesBuffer) WBytes(v []byte)

func (*BytesBuffer) WBytesWithLen

func (b *BytesBuffer) WBytesWithLen(v []byte)

func (*BytesBuffer) WFloat32

func (b *BytesBuffer) WFloat32(v float32)

func (*BytesBuffer) WFloat64

func (b *BytesBuffer) WFloat64(v float64)

func (*BytesBuffer) WInt16

func (b *BytesBuffer) WInt16(v int16)

func (*BytesBuffer) WInt32

func (b *BytesBuffer) WInt32(v int32)

func (*BytesBuffer) WInt64

func (b *BytesBuffer) WInt64(v int64)

func (*BytesBuffer) WInt8

func (b *BytesBuffer) WInt8(v int8)

func (*BytesBuffer) WStrMapStr

func (b *BytesBuffer) WStrMapStr(m map[string]string)

func (*BytesBuffer) WString

func (b *BytesBuffer) WString(v string)

func (*BytesBuffer) WStringNoLen

func (b *BytesBuffer) WStringNoLen(v string)

func (*BytesBuffer) WUint16

func (b *BytesBuffer) WUint16(v uint16)

func (*BytesBuffer) WUint32

func (b *BytesBuffer) WUint32(v uint32)

func (*BytesBuffer) WUint64

func (b *BytesBuffer) WUint64(v uint64)

func (*BytesBuffer) WUint8

func (b *BytesBuffer) WUint8(v uint8)

func (*BytesBuffer) WVec2

func (b *BytesBuffer) WVec2(v Vec4)

func (*BytesBuffer) WVec3

func (b *BytesBuffer) WVec3(v Vec4)

func (*BytesBuffer) WVec4

func (b *BytesBuffer) WVec4(v Vec4)

func (*BytesBuffer) WVecInt2

func (b *BytesBuffer) WVecInt2(v VecInt2)

func (*BytesBuffer) WVecInt3

func (b *BytesBuffer) WVecInt3(v VecInt3)

func (*BytesBuffer) WVecInt4

func (b *BytesBuffer) WVecInt4(v VecInt4)

type EnableAction

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

func NewEnableAction

func NewEnableAction() *EnableAction

func (*EnableAction) Action

func (e *EnableAction) Action(action func()) bool

func (*EnableAction) Close

func (e *EnableAction) Close(action func()) bool

func (*EnableAction) Reset

func (e *EnableAction) Reset()

type FunStr

type FunStr func(str string) bool

type Func

type Func func(v bool)

func (Func) Invoke

func (f Func) Invoke(v bool)

type IBuffer

type IBuffer interface {
	Push(data interface{})
	Action(action ActionObj)
}

type IData

type IData interface {
	Data() map[string]interface{}
	Set(key string, val interface{})
	Get(key string) (interface{}, bool)
	Pop(key string) (interface{}, bool)
	Remove(key string)
	Has(key string) bool
	Must(key string, defVal interface{}) interface{}
	Bool(key string) (bool, bool)
	MustBool(key string, defVal bool) bool
	Int16(key string) (int16, bool)
	MustInt16(key string, defVal int16) int16
	Int(key string) (int, bool)
	MustInt(key string, defVal int) int
	Int32(key string) (int32, bool)
	MustInt32(key string, defVal int32) int32
	Int64(key string) (int64, bool)
	MustInt64(key string, defVal int64) int64
	Uint8(key string) (uint8, bool)
	MustUint8(key string, defVal uint8) uint8
	Uint16(key string) (uint16, bool)
	MustUint16(key string, defVal uint16) uint16
	Uint(key string) (uint, bool)
	MustUint(key string, defVal uint) uint
	Uint32(key string) (uint32, bool)
	MustUint32(key string, defVal uint32) uint32
	Uint64(key string) (uint64, bool)
	MustUint64(key string, defVal uint64) uint64
	Float32(key string) (float32, bool)
	MustFloat32(key string, defVal float32) float32
	Float64(key string) (float64, bool)
	MustFloat64(key string, defVal float64) float64
	String(key string) (string, bool)
	MustString(key string, defVal string) string
	Strings(key string) ([]string, bool)
	MustStrings(key string, defVal []string) []string
	Reset()
}

type IObject

type IObject interface {
	Set(v interface{}, paths ...interface{}) error
	Get(paths ...interface{}) (interface{}, error)
	Must(val interface{}, paths ...interface{}) interface{}
	Bool(paths ...interface{}) (bool, error)
	MustBool(val bool, paths ...interface{}) bool
	Int16(paths ...interface{}) (int16, error)
	MustInt16(val int16, paths ...interface{}) int16
	Int(paths ...interface{}) (int, error)
	MustInt(val int, paths ...interface{}) int
	Int32(paths ...interface{}) (int32, error)
	MustInt32(val int32, paths ...interface{}) int32
	Int64(paths ...interface{}) (int64, error)
	MustInt64(val int64, paths ...interface{}) int64
	Uint8(paths ...interface{}) (uint8, error)
	MustUint8(val uint8, paths ...interface{}) uint8
	Uint16(paths ...interface{}) (uint16, error)
	MustUint16(val uint16, paths ...interface{}) uint16
	Uint(paths ...interface{}) (uint, error)
	MustUint(val uint, paths ...interface{}) uint
	Uint32(paths ...interface{}) (uint32, error)
	MustUint32(val uint32, paths ...interface{}) uint32
	Uint64(paths ...interface{}) (uint64, error)
	MustUint64(val uint64, paths ...interface{}) uint64
	Float32(paths ...interface{}) (float32, error)
	MustFloat32(val float32, paths ...interface{}) float32
	Float64(paths ...interface{}) (float64, error)
	MustFloat64(val float64, paths ...interface{}) float64
	String(paths ...interface{}) (string, error)
	MustString(val string, paths ...interface{}) string
	Strings(paths ...interface{}) ([]string, error)
	MustStrings(val []string, paths ...interface{}) []string
	Data() map[string]interface{}
}

type IPool

type IPool interface {
	Get() interface{}
	Put(x interface{})
}

type IWeightSelector

type IWeightSelector interface {
	Add(item interface{}, weight int)
	Remove(object interface{})
	RemoveAll()
	Reset()
	All(action ActionObj)
	Next() interface{}
}

type IWorker

type IWorker interface {
	Dispose()
	PushJob(action Action)
}

type IWorkerManager

type IWorkerManager interface {
	AddWorker(id int64, complete Action)
	RemoveWorker(id int64)
	PushJob(id int64, job Action)
}

type Locker

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

func NewLocker

func NewLocker() *Locker

func (*Locker) Get

func (l *Locker) Get(action func())

func (*Locker) Set

func (l *Locker) Set(action func())

type Tuple1

type Tuple1 struct {
	Item1 interface{}
}

func (Tuple1) Equal

func (t Tuple1) Equal(tuple Tuple1) bool

type Tuple2

type Tuple2 struct {
	Item1 interface{}
	Item2 interface{}
}

func (Tuple2) Equal

func (t Tuple2) Equal(tuple Tuple2) bool

type Tuple3

type Tuple3 struct {
	Item1 interface{}
	Item2 interface{}
	Item3 interface{}
}

func (Tuple3) Equal

func (t Tuple3) Equal(tuple Tuple3) bool

type Tuple4

type Tuple4 struct {
	Item1 interface{}
	Item2 interface{}
	Item3 interface{}
	Item4 interface{}
}

func (Tuple4) Equal

func (t Tuple4) Equal(tuple Tuple4) bool

type Tuple5

type Tuple5 struct {
	Item1 interface{}
	Item2 interface{}
	Item3 interface{}
	Item4 interface{}
	Item5 interface{}
}

func (Tuple5) Equal

func (t Tuple5) Equal(tuple Tuple5) bool

type Tuple6

type Tuple6 struct {
	Item1 interface{}
	Item2 interface{}
	Item3 interface{}
	Item4 interface{}
	Item5 interface{}
	Item6 interface{}
}

func (Tuple6) Equal

func (t Tuple6) Equal(tuple Tuple6) bool

type Vec2

type Vec2 struct {
	X float32
	Y float32
}

func Vec2Add

func Vec2Add(v1 Vec2, v2 Vec2) Vec2

func Vec2Dot

func Vec2Dot(vec Vec2, v float32) Vec2

func Vec2Normalize

func Vec2Normalize(v Vec2) Vec2

func Vec2RandNormalize

func Vec2RandNormalize() Vec2

随机生成一个方向法线

func Vec2Sub

func Vec2Sub(v1 Vec2, v2 Vec2) Vec2

type Vec3

type Vec3 struct {
	X float32
	Y float32
	Z float32
}

func Vec3Add

func Vec3Add(v1 Vec3, v2 Vec3) Vec3

func Vec3Dot

func Vec3Dot(vec Vec3, v float32) Vec3

func Vec3Normalize

func Vec3Normalize(v Vec3) Vec3

func Vec3RandNormalize

func Vec3RandNormalize() Vec3

随机生成一个方向法线

func Vec3Sub

func Vec3Sub(v1 Vec3, v2 Vec3) Vec3

type Vec4

type Vec4 struct {
	X float32
	Y float32
	Z float32
	W float32
}

type VecInt2

type VecInt2 struct {
	X int32
	Y int32
}

type VecInt3

type VecInt3 struct {
	X int32
	Y int32
	Z int32
}

type VecInt4

type VecInt4 struct {
	X int32
	Y int32
	Z int32
	W int32
}

type WaitCh

type WaitCh chan<- struct{}

func WaitAsync

func WaitAsync(onComplete func()) WaitCh

func (WaitCh) Done

func (ch WaitCh) Done()

Jump to

Keyboard shortcuts

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