Documentation
¶
Overview ¶
Package flowfield implements Flow Field pathfinding for efficient group movement. Instead of computing per-agent paths, it builds a vector field from the goal outward (one Dijkstra pass), then every agent looks up its direction in O(1).
Single target:
ff := flowfield.New(grid, goalX, goalY)
for _, a := range agents {
dx, dy := ff.GetDirection(a.X, a.Y)
a.X += dx; a.Y += dy
}
Multiple targets (each tile routes to the nearest goal):
ff := flowfield.NewMulti(grid, [][2]int{{3,5}, {9,7}})
ff.Reset(7, 3) // switch to single goal
ff.ResetMulti([][2]int{{1,1}, {9,9}}) // switch to multi goal
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field holds the precomputed integration and vector fields.
func NewMulti ¶
NewMulti builds a flow field toward multiple goals. Each tile routes to the nearest goal automatically.
func (*Field) FindPath ¶
FindPath backtracks from (x, y) by following the direction chain to the nearest goal. Useful for debugging and visualization.
func (*Field) GetCost ¶
GetCost returns the integration cost (distance to nearest goal). Returns -1 for unreachable tiles.
func (*Field) GetDirection ¶
GetDirection returns the movement direction for tile (x, y). Returns (0,0) if the tile is blocked or unreachable.
func (*Field) ResetMulti ¶
ResetMulti recalculates the field for multiple goals. Reuses memory.
type Option ¶
type Option func(*Field)
Option configures the flow field.
func WithDiagonal ¶
func WithDiagonal(d finder.DiagonalMovement) Option
WithDiagonal sets the diagonal movement rule. Defaults to DiagonalNever (cardinal-only).