| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package astar6
- // FindContext 搜索上下文(每次搜索独立的状态)
- // 优化内存布局:将小字段放在一起,减少padding
- type FindContext struct {
- // 用户传递的原始参数
- sx, sy int32 // 起点坐标
- ex, ey int32 // 终点坐标
- playerID int64 // 当前搜索的玩家ID
- leagueID int64 // 当前搜索的联盟ID
- marchType int32 // 当前搜索类型,定义路径搜索的行为:默认行为(所有障碍点不可走)|友军障碍可走|忽略终点动态障碍|忽略所有动态障碍
- start *Node // 当前搜索的起点(用于视觉惩罚计算)
- end *Node // 当前搜索的终点(用于视觉惩罚计算)
- minY int32 // 起点和终点的最小y值
- openHeap nodeHeap // 优先队列
- openSet map[*Node]*heapItem // 快速查询节点对应的heapItem(索引堆优化)
- closeSet map[*Node]struct{} // 关闭列表
- parentMap map[*Node]*Node // 父节点映射
- gMap map[*Node]int32 // g值映射
- }
- func DefaultFindContext(sx, sy, ex, ey int32) *FindContext {
- ctx := acquireContext()
- ctx.sx = sx
- ctx.sy = sy
- ctx.ex = ex
- ctx.ey = ey
- ctx.minY = min(sy, ey)
- return ctx
- }
- func NewFindContext(sx, sy, ex, ey int32, playerID, leagueID int64, marchType int32) *FindContext {
- ctx := DefaultFindContext(sx, sy, ex, ey)
- ctx.playerID = playerID
- ctx.leagueID = leagueID
- ctx.marchType = marchType
- return ctx
- }
- func (p *FindContext) PlayerID() int64 {
- return p.playerID
- }
- func (p *FindContext) LeagueID() int64 {
- return p.leagueID
- }
- func (p *FindContext) MarchType() int32 {
- return p.marchType
- }
- func (p *FindContext) IsEndPoint(x, y int32) bool {
- return x == p.ex && y == p.ey
- }
|