Documentation ¶
Index ¶
- type Position2DChangeEventHandle
- type Position2DDestinationEventHandle
- type Position2DStopMoveEventHandle
- type TwoDimensional
- func (slf *TwoDimensional[EID, PosType]) MoveTo(entity TwoDimensionalEntity[EID, PosType], x, y PosType)
- func (slf *TwoDimensional[EID, PosType]) OnPosition2DChangeEvent(entity TwoDimensionalEntity[EID, PosType], oldX, oldY PosType)
- func (slf *TwoDimensional[EID, PosType]) OnPosition2DDestinationEvent(entity TwoDimensionalEntity[EID, PosType])
- func (slf *TwoDimensional[EID, PosType]) OnPosition2DStopMoveEvent(entity TwoDimensionalEntity[EID, PosType])
- func (slf *TwoDimensional[EID, PosType]) RegPosition2DChangeEvent(handle Position2DChangeEventHandle[EID, PosType])
- func (slf *TwoDimensional[EID, PosType]) RegPosition2DDestinationEvent(handle Position2DDestinationEventHandle[EID, PosType])
- func (slf *TwoDimensional[EID, PosType]) RegPosition2DStopMoveEvent(handle Position2DStopMoveEventHandle[EID, PosType])
- func (slf *TwoDimensional[EID, PosType]) Release()
- func (slf *TwoDimensional[EID, PosType]) StopMove(id EID)
- type TwoDimensionalEntity
- type TwoDimensionalOption
- func WithTwoDimensionalIdleWaitTime[EID generic.Basic, PosType generic.SignedNumber](duration time.Duration) TwoDimensionalOption[EID, PosType]
- func WithTwoDimensionalInterval[EID generic.Basic, PosType generic.SignedNumber](duration time.Duration) TwoDimensionalOption[EID, PosType]
- func WithTwoDimensionalTimeUnit[EID generic.Basic, PosType generic.SignedNumber](duration time.Duration) TwoDimensionalOption[EID, PosType]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Position2DChangeEventHandle ¶
type Position2DChangeEventHandle[EID generic.Basic, PosType generic.SignedNumber] func(moving *TwoDimensional[EID, PosType], entity TwoDimensionalEntity[EID, PosType], oldX, oldY PosType)
type Position2DDestinationEventHandle ¶
type Position2DDestinationEventHandle[EID generic.Basic, PosType generic.SignedNumber] func(moving *TwoDimensional[EID, PosType], entity TwoDimensionalEntity[EID, PosType])
type Position2DStopMoveEventHandle ¶
type Position2DStopMoveEventHandle[EID generic.Basic, PosType generic.SignedNumber] func(moving *TwoDimensional[EID, PosType], entity TwoDimensionalEntity[EID, PosType])
type TwoDimensional ¶
type TwoDimensional[EID generic.Basic, PosType generic.SignedNumber] struct { // contains filtered or unexported fields }
TwoDimensional 用于2D对象移动的数据结构
- 通过对象调用 MoveTo 方法后将开始执行该对象的移动
- 移动将在根据设置的每次移动间隔时间(WithTwoDimensionalInterval)进行移动,当无对象移动需要移动时将会进入短暂的休眠
- 当对象移动速度永久为0时,将会导致永久无法完成的移动
func NewTwoDimensional ¶
func NewTwoDimensional[EID generic.Basic, PosType generic.SignedNumber](options ...TwoDimensionalOption[EID, PosType]) *TwoDimensional[EID, PosType]
NewTwoDimensional 创建一个用于2D对象移动的实例(TwoDimensional)
Example ¶
package main import ( "fmt" moving2 "github.com/kercylan98/minotaur/utils/moving" ) func main() { m := moving2.NewTwoDimensional[int64, float64]() defer func() { m.Release() }() fmt.Println(m != nil) }
Output: true
func (*TwoDimensional[EID, PosType]) MoveTo ¶
func (slf *TwoDimensional[EID, PosType]) MoveTo(entity TwoDimensionalEntity[EID, PosType], x, y PosType)
MoveTo 设置对象移动到特定位置
Example ¶
m := moving2.NewTwoDimensional(moving2.WithTwoDimensionalTimeUnit[int64, float64](time.Second)) defer func() { m.Release() }() var wait sync.WaitGroup m.RegPosition2DDestinationEvent(func(moving *moving2.TwoDimensional[int64, float64], entity moving2.TwoDimensionalEntity[int64, float64]) { fmt.Println("done") wait.Done() }) wait.Add(1) entity := NewEntity(1, 100) m.MoveTo(entity, 50, 30) wait.Wait()
Output: done
func (*TwoDimensional[EID, PosType]) OnPosition2DChangeEvent ¶
func (slf *TwoDimensional[EID, PosType]) OnPosition2DChangeEvent(entity TwoDimensionalEntity[EID, PosType], oldX, oldY PosType)
func (*TwoDimensional[EID, PosType]) OnPosition2DDestinationEvent ¶
func (slf *TwoDimensional[EID, PosType]) OnPosition2DDestinationEvent(entity TwoDimensionalEntity[EID, PosType])
func (*TwoDimensional[EID, PosType]) OnPosition2DStopMoveEvent ¶
func (slf *TwoDimensional[EID, PosType]) OnPosition2DStopMoveEvent(entity TwoDimensionalEntity[EID, PosType])
func (*TwoDimensional[EID, PosType]) RegPosition2DChangeEvent ¶
func (slf *TwoDimensional[EID, PosType]) RegPosition2DChangeEvent(handle Position2DChangeEventHandle[EID, PosType])
RegPosition2DChangeEvent 在对象位置改变时将执行注册的事件处理函数
func (*TwoDimensional[EID, PosType]) RegPosition2DDestinationEvent ¶
func (slf *TwoDimensional[EID, PosType]) RegPosition2DDestinationEvent(handle Position2DDestinationEventHandle[EID, PosType])
RegPosition2DDestinationEvent 在对象到达终点时将执行被注册的事件处理函数
func (*TwoDimensional[EID, PosType]) RegPosition2DStopMoveEvent ¶
func (slf *TwoDimensional[EID, PosType]) RegPosition2DStopMoveEvent(handle Position2DStopMoveEventHandle[EID, PosType])
RegPosition2DStopMoveEvent 在对象停止移动时将执行被注册的事件处理函数
func (*TwoDimensional[EID, PosType]) Release ¶
func (slf *TwoDimensional[EID, PosType]) Release()
Release 释放对象移动对象所占用的资源
func (*TwoDimensional[EID, PosType]) StopMove ¶
func (slf *TwoDimensional[EID, PosType]) StopMove(id EID)
StopMove 停止特定对象的移动
Example ¶
m := moving2.NewTwoDimensional(moving2.WithTwoDimensionalTimeUnit[int64, float64](time.Second)) defer func() { m.Release() }() var wait sync.WaitGroup m.RegPosition2DChangeEvent(func(moving *moving2.TwoDimensional[int64, float64], entity moving2.TwoDimensionalEntity[int64, float64], oldX, oldY float64) { fmt.Println("move") }) m.RegPosition2DStopMoveEvent(func(moving *moving2.TwoDimensional[int64, float64], entity moving2.TwoDimensionalEntity[int64, float64]) { fmt.Println("stop") wait.Done() }) m.RegPosition2DDestinationEvent(func(moving *moving2.TwoDimensional[int64, float64], entity moving2.TwoDimensionalEntity[int64, float64]) { fmt.Println("done") wait.Done() }) wait.Add(1) entity := NewEntity(1, 100) m.MoveTo(entity, 50, 300) m.StopMove(1) wait.Wait()
Output: stop
type TwoDimensionalEntity ¶
type TwoDimensionalEntity[EID generic.Basic, PosType generic.SignedNumber] interface { // GetTwoDimensionalEntityID 获取 Moving 对象 ID GetTwoDimensionalEntityID() EID // GetSpeed 获取移动速度 GetSpeed() float64 // GetPosition 获取位置 GetPosition() geometry.Point[PosType] // SetPosition 设置位置 SetPosition(geometry.Point[PosType]) }
TwoDimensionalEntity 2D移动对象接口定义
type TwoDimensionalOption ¶
type TwoDimensionalOption[EID generic.Basic, PosType generic.SignedNumber] func(moving *TwoDimensional[EID, PosType])
func WithTwoDimensionalIdleWaitTime ¶
func WithTwoDimensionalIdleWaitTime[EID generic.Basic, PosType generic.SignedNumber](duration time.Duration) TwoDimensionalOption[EID, PosType]
WithTwoDimensionalIdleWaitTime 通过特定的空闲等待时间创建
- 默认情况下在没有新的移动计划时将限制 100毫秒 + 移动间隔事件(默认100毫秒)
func WithTwoDimensionalInterval ¶
func WithTwoDimensionalInterval[EID generic.Basic, PosType generic.SignedNumber](duration time.Duration) TwoDimensionalOption[EID, PosType]
WithTwoDimensionalInterval 通过特定的移动间隔时间创建
func WithTwoDimensionalTimeUnit ¶
func WithTwoDimensionalTimeUnit[EID generic.Basic, PosType generic.SignedNumber](duration time.Duration) TwoDimensionalOption[EID, PosType]
WithTwoDimensionalTimeUnit 通过特定时间单位创建
- 默认单位为1毫秒,最小单位也为1毫秒
Click to show internal directories.
Click to hide internal directories.