aoi

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 5 Imported by: 0

README

Aoi

Go doc

aoi 提供了一种有效的方法来处理 AOI(Area of Interest)问题。

AOI 问题是在大规模多人在线游戏中常见的问题,它涉及到确定哪些对象对玩家来说是“感兴趣的”, 也就是说,哪些对象在玩家的视野范围内。

这个包提供了一种数据结构和一些方法来有效地解决这个问题。

目录导航

列出了该 package 下所有的函数及类型定义,可通过目录导航进行快捷跳转 ❤️

展开 / 折叠目录导航

包级函数定义

函数名称 描述
NewTwoDimensional 暂无描述...

类型定义

类型 名称 描述
STRUCT TwoDimensional 暂无描述...
INTERFACE TwoDimensionalEntity 基于2D定义的AOI对象功能接口
STRUCT EntityJoinVisionEventHandle 暂无描述...

详情信息

func NewTwoDimensional[EID generic.Basic, PosType generic.SignedNumber, E TwoDimensionalEntity[EID, PosType]](width int, height int, areaWidth int, areaHeight int) *TwoDimensional[EID, PosType, E]

查看 / 收起单元测试

func TestNewTwoDimensional(t *testing.T) {
	aoiTW := aoi.NewTwoDimensional[int64, float64, *Ent](10000, 10000, 100, 100)
	start := time.Now()
	for i := 0; i < 50000; i++ {
		aoiTW.AddEntity(&Ent{guid: int64(i), pos: geometry.NewPoint[float64](float64(random.Int64(0, 10000)), float64(random.Int64(0, 10000))), vision: 200})
	}
	fmt.Println("添加耗时:", time.Since(start))
	start = time.Now()
	aoiTW.SetSize(10100, 10100)
	fmt.Println("重设大小耗时:", time.Since(start))
}


TwoDimensional STRUCT
type TwoDimensional[EID generic.Basic, PosType generic.SignedNumber, E TwoDimensionalEntity[EID, PosType]] struct {
	*event[EID, PosType, E]
	rw               sync.RWMutex
	width            float64
	height           float64
	areaWidth        float64
	areaHeight       float64
	areaWidthLimit   int
	areaHeightLimit  int
	areas            [][]map[EID]E
	focus            map[EID]map[EID]E
	repartitionQueue []func()
}

func (*TwoDimensional) AddEntity(entity E)

func (*TwoDimensional) DeleteEntity(entity E)

func (*TwoDimensional) Refresh(entity E)

func (*TwoDimensional) GetFocus(id EID) map[EID]E

func (*TwoDimensional) SetSize(width int, height int)

func (*TwoDimensional) SetAreaSize(width int, height int)

TwoDimensionalEntity INTERFACE

基于2D定义的AOI对象功能接口

  • AOI 对象提供了 AOI 系统中常用的属性,诸如位置坐标和视野范围等
type TwoDimensionalEntity[EID generic.Basic, PosType generic.SignedNumber] interface {
	GetTwoDimensionalEntityID() EID
	GetVision() float64
	GetPosition() geometry.Point[PosType]
}

EntityJoinVisionEventHandle STRUCT
type EntityJoinVisionEventHandle[EID generic.Basic, PosType generic.SignedNumber, E TwoDimensionalEntity[EID, PosType]] func(entity E)

Documentation

Overview

Package aoi 提供了一种有效的方法来处理 AOI(Area of Interest)问题。

AOI 问题是在大规模多人在线游戏中常见的问题,它涉及到确定哪些对象对玩家来说是“感兴趣的”, 也就是说,哪些对象在玩家的视野范围内。

这个包提供了一种数据结构和一些方法来有效地解决这个问题。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EntityJoinVisionEventHandle

type EntityJoinVisionEventHandle[EID generic.Basic, PosType generic.SignedNumber, E TwoDimensionalEntity[EID, PosType]] func(entity, target E)

type EntityLeaveVisionEventHandle

type EntityLeaveVisionEventHandle[EID generic.Basic, PosType generic.SignedNumber, E TwoDimensionalEntity[EID, PosType]] func(entity, target E)

type TwoDimensional

type TwoDimensional[EID generic.Basic, PosType generic.SignedNumber, E TwoDimensionalEntity[EID, PosType]] struct {
	// contains filtered or unexported fields
}

func NewTwoDimensional

func NewTwoDimensional[EID generic.Basic, PosType generic.SignedNumber, E TwoDimensionalEntity[EID, PosType]](width, height, areaWidth, areaHeight int) *TwoDimensional[EID, PosType, E]

func (*TwoDimensional[EID, PosType, E]) AddEntity

func (slf *TwoDimensional[EID, PosType, E]) AddEntity(entity E)

func (*TwoDimensional[EID, PosType, E]) DeleteEntity

func (slf *TwoDimensional[EID, PosType, E]) DeleteEntity(entity E)

func (*TwoDimensional[EID, PosType, E]) GetFocus

func (slf *TwoDimensional[EID, PosType, E]) GetFocus(id EID) map[EID]E

func (TwoDimensional) OnEntityJoinVisionEvent

func (slf TwoDimensional) OnEntityJoinVisionEvent(entity, target E)

OnEntityJoinVisionEvent 在新对象进入视野时将会立刻执行被注册的事件处理函数

func (TwoDimensional) OnEntityLeaveVisionEvent

func (slf TwoDimensional) OnEntityLeaveVisionEvent(entity, target E)

OnEntityLeaveVisionEvent 在新对象离开视野时将会立刻执行被注册的事件处理函数

func (*TwoDimensional[EID, PosType, E]) Refresh

func (slf *TwoDimensional[EID, PosType, E]) Refresh(entity E)

func (TwoDimensional) RegEntityJoinVisionEvent

func (slf TwoDimensional) RegEntityJoinVisionEvent(handle EntityJoinVisionEventHandle[EID, PosType, E])

RegEntityJoinVisionEvent 在新对象进入视野时将会立刻执行被注册的事件处理函数

func (TwoDimensional) RegEntityLeaveVisionEvent

func (slf TwoDimensional) RegEntityLeaveVisionEvent(handle EntityLeaveVisionEventHandle[EID, PosType, E])

RegEntityLeaveVisionEvent 在新对象离开视野时将会立刻执行被注册的事件处理函数

func (*TwoDimensional[EID, PosType, E]) SetAreaSize

func (slf *TwoDimensional[EID, PosType, E]) SetAreaSize(width, height int)

func (*TwoDimensional[EID, PosType, E]) SetSize

func (slf *TwoDimensional[EID, PosType, E]) SetSize(width, height int)

type TwoDimensionalEntity

type TwoDimensionalEntity[EID generic.Basic, PosType generic.SignedNumber] interface {
	// GetTwoDimensionalEntityID 获取 AOI 对象 ID
	GetTwoDimensionalEntityID() EID
	// GetVision 获取视距
	GetVision() float64
	// GetPosition 获取位置
	GetPosition() geometry.Point[PosType]
}

TwoDimensionalEntity 基于2D定义的AOI对象功能接口

  • AOI 对象提供了 AOI 系统中常用的属性,诸如位置坐标和视野范围等

Jump to

Keyboard shortcuts

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