fov

package
v0.0.0-...-117f852 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: GPL-3.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Algorithm

type Algorithm uint8

Algorithm represents a field-of-view algorithm

const (
	AlgorithmNone Algorithm = iota
	AlgorithmBBQ
)

Our default algorithms

type Cell

type Cell struct {
	Lighting       Light
	Visible        bool // Whether this cell is within the FoV.
	BlocksLight    bool
	BlocksMovement bool
}

Cell is the state for a given position in an FoVMap.

type Light

type Light struct {
	Lumens int16
}

Light represents light state.

type Map

type Map interface {
	Width() int
	Height() int
	CostAt(x, y int) uint32
	Resize(width, height int)
	Clear(fovCell Cell)
	Reset()
	Recompute(cX, cY int, radius int, light Light)
	Compute(cX, cY int, radius int, light Light)
	SetCell(x, y int, fovCell Cell) error
	BlocksMovement(x, y int) bool
	SetBlocksMovement(x, y int, blocks bool) error
	BlocksLight(x, y int) bool
	SetBlocksLight(x, y int, blocks bool) error
	Visible(x, y int) bool
	SetVisible(x, y int, visible bool) error
	Lighting(x, y int) Light
	SetLighting(x, y int, light Light) error
	CheckBounds(x, y int) error
	ToString(showVisible, showBlocksLight, showBlocksMovement, showLight bool) string
}

Map is our interface for field of view Maps.

func NewMap

func NewMap(width, height int, algo Algorithm) Map

NewMap returns a new Map at the given dimensions using the provided Algorithm.

type MapBBQ

type MapBBQ struct {
	MapBase
}

MapBBQ represents a 2D structure for calculating a field of view.

func NewMapBBQ

func NewMapBBQ(width, height int) (fovMap *MapBBQ)

NewMapBBQ returns an field of view Map sized to the given width and height using the BBQ algorithm.

func (*MapBBQ) Compute

func (fovMap *MapBBQ) Compute(cX, cY int, radius int, light Light)

Compute calculates the FOV for our BBQ.

func (*MapBBQ) Recompute

func (fovMap *MapBBQ) Recompute(cX, cY int, radius int, light Light)

Recompute calls Reset() then Compute()

type MapBase

type MapBase struct {
	// contains filtered or unexported fields
}

MapBase is the base implementation of our Map interface. It is used as an embedded structure within most Map implementations.

func (*MapBase) BlocksLight

func (fovMap *MapBase) BlocksLight(x, y int) bool

BlocksLight checks if the cell at x and y blocks light. Returns true if x or y is out of bounds.

func (*MapBase) BlocksMovement

func (fovMap *MapBase) BlocksMovement(x, y int) bool

BlocksMovement checks if the cell at x and y blocks movement. Returns true if x or y is out of bounds.

func (*MapBase) CheckBounds

func (fovMap *MapBase) CheckBounds(x, y int) error

CheckBounds returns an error if the provided x and y is out of bounds.

func (*MapBase) Clear

func (fovMap *MapBase) Clear(fovCell Cell)

Clear clears the map using the provided Cell for clearing.

func (*MapBase) CostAt

func (fovMap *MapBase) CostAt(x, y int) (cost uint32)

Height returns the movement cost of a tile in a map. This allows fov.Maps to be used for pathing.

func (*MapBase) Height

func (fovMap *MapBase) Height() int

Height returns the height of the map.

func (*MapBase) Lighting

func (fovMap *MapBase) Lighting(x, y int) Light

Lighting returns the lighting value for a given cell. Returns 0 if x or y is out of bounds.

func (*MapBase) Reset

func (fovMap *MapBase) Reset()

Reset resets the visibility state of all cells.

func (*MapBase) Resize

func (fovMap *MapBase) Resize(width, height int)

Resize resizes the given MapBase to the provided size.

func (*MapBase) SetBlocksLight

func (fovMap *MapBase) SetBlocksLight(x, y int, blocks bool) error

SetBlocksLight sets the blocksLight property of the cell at x and y to blocks.

func (*MapBase) SetBlocksMovement

func (fovMap *MapBase) SetBlocksMovement(x, y int, blocks bool) error

SetBlocksMovement sets the blocksMovement property of the cell at x and y to blocks.

func (*MapBase) SetCell

func (fovMap *MapBase) SetCell(x, y int, fovCell Cell) error

SetCell sets the cell at the given x and y to fovCell.

func (*MapBase) SetLighting

func (fovMap *MapBase) SetLighting(x, y int, light Light) error

SetLighting sets a given cell's lighting value to the one provided.

func (*MapBase) SetVisible

func (fovMap *MapBase) SetVisible(x, y int, visible bool) error

SetVisible sets whether a given cell is considered as within the FoV.

func (*MapBase) ToString

func (fovMap *MapBase) ToString(showVisible, showBlocksLight, showBlocksMovement, showLight bool) string

ToString returns a stringified view of the map.

func (*MapBase) Visible

func (fovMap *MapBase) Visible(x, y int) bool

Visible returns whether a given cell is considered as within the FoV. Returns false if x or y is out of bounds.

func (*MapBase) Width

func (fovMap *MapBase) Width() int

Width returns the width of the map.

Jump to

Keyboard shortcuts

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