Documentation
¶
Index ¶
- Constants
- func ChunkOf(x, y, chunkSize int) (int, int)
- func PortalKey(chunkID, pos, dir, chunkSize int) int
- type HPAFinder
- type HPAOption
- func WithAllowDiagonal(dontCrossCorners bool) HPAOption
- func WithChunkSize(cs int) HPAOption
- func WithConcreteFinder(fnd finder.Finder) HPAOption
- func WithDiagonal(d finder.DiagonalMovement) HPAOption
- func WithHeuristic(h finder.HeuristicFunc) HPAOption
- func WithStringPulling(enabled bool) HPAOption
- func WithWeight(w float64) HPAOption
- type HPAWorld
- type Portal
Constants ¶
const ( DirN = 0 // north (top edge) DirE = 1 // east (right edge) DirS = 2 // south (bottom edge) DirW = 3 // west (left edge) )
Cardinal direction constants used for portal orientation.
const MaxPortalsPerChunk = 256
MaxPortalsPerChunk = ChunkSize * 4 (N/E/S/W)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HPAFinder ¶
type HPAFinder struct {
// Heuristic is the heuristic function used for estimating path cost.
Heuristic finder.HeuristicFunc
// Weight is the heuristic weight (higher values bias toward faster
// but potentially suboptimal paths).
Weight float64
// DiagonalMovement controls whether diagonal moves are permitted
// and under what conditions.
DiagonalMovement finder.DiagonalMovement
// contains filtered or unexported fields
}
HPAFinder implements Hierarchical Pathfinding A*.
It implements finder.Finder, so it can be used wherever a Finder is expected. Call Build(grid) to pre-build the hierarchical portal graph before FindPath.
func NewHPAFinder ¶
NewHPAFinder creates an HPA* finder. Call Build(grid) to pre-build the hierarchical portal graph before calling FindPath.
type HPAOption ¶
type HPAOption func(*HPAFinder)
HPAOption configures an HPAFinder.
func WithAllowDiagonal ¶
WithAllowDiagonal enables diagonal movement.
func WithChunkSize ¶
WithChunkSize sets the chunk size for world partitioning.
func WithConcreteFinder ¶
WithConcreteFinder sets the finder used for segment pathfinding.
func WithDiagonal ¶
func WithDiagonal(d finder.DiagonalMovement) HPAOption
WithDiagonal sets the diagonal movement rule.
func WithHeuristic ¶
func WithHeuristic(h finder.HeuristicFunc) HPAOption
WithHeuristic sets the heuristic function.
func WithStringPulling ¶
WithStringPulling enables or disables path smoothing via LOS string pulling. Enabled by default.
type HPAWorld ¶
type HPAWorld struct {
// Portals is the flat array of all portals indexed by PortalKey.
// Unused slots remain nil.
Portals []*Portal
// NumPortals is the total number of allocated portals.
NumPortals int
// ChunkMapX is the number of chunks along the X axis.
ChunkMapX int
// ChunkMapY is the number of chunks along the Y axis.
ChunkMapY int
// PaddedWidth is the grid width rounded up to a multiple of ChunkSize.
PaddedWidth int
// PaddedHeight is the grid height rounded up to a multiple of ChunkSize.
PaddedHeight int
// ChunkSize is the edge length of a single chunk in cells.
ChunkSize int
}
HPAWorld holds the hierarchical portal graph for a Grid.
func BuildWorld ¶
BuildWorld constructs the HPA world: partition grid into chunks, detect edge portals (compressed — one per run of consecutive walkable cells), connect external portals (adjacent chunk), and connect internal portals (BFS within chunk).
func (*HPAWorld) IsSingleChunk ¶
IsSingleChunk reports whether two positions are in the same chunk.
type Portal ¶
type Portal struct {
CenterX int // world X of portal center
CenterY int // world Y of portal center
Length int // number of cells this portal spans
Offset int // offset along the chunk edge (0-based)
// External connections to neighboring chunks (portal keys)
ExternalCount int
ExternalPortals [5]int
// Internal connections to other portals in the same chunk
InternalCount int
InternalPortals [255]int // portal key of connected portal
InternalCosts [255]int // movement cost (octile * 10)
}
Portal represents a portal on a chunk border or a diagonal corner portal.