Cauldron2D.Grid.Fov (Cauldron2D v0.1.3)

Copy Markdown View Source

Recursive shadowcasting: which tiles an observer can see from where it stands.

Cauldron2D.Grid.Fov.compute(&transparent?/1, {12, 9}, 8)
#=> MapSet.new([{12, 9}, {12, 8}, ...])

The map is walked as eight octants, each a wedge scanned row by row away from the observer; an opaque tile splits the wedge and what is behind it is not visited, so the cost follows what is visible rather than the area of the circle.

Two rules a caller can rely on:

  • Walls bounding a lit area are lit: an opaque tile is added to the set before it stops the scan.
  • Visibility is mutual: if b is in the set computed from a, a is in the set computed from b at the same radius.

transparent? is a function from a tile to whether sight passes through it; a tile outside the map should answer false. origin itself is always in the set.

Summary

Functions

The set of tiles visible from origin within radius, measured as Euclidean distance.

Types

point()

@type point() :: {integer(), integer()}

transparent()

@type transparent() :: (point() -> boolean())

Functions

compute(transparent?, origin, radius)

@spec compute(transparent(), point(), pos_integer()) :: MapSet.t(point())

The set of tiles visible from origin within radius, measured as Euclidean distance.