Documentation
¶
Index ¶
- type Direction
- type Grid
- func (m *Grid[T]) Around(from Point, distance uint32, costOf costFn, fn func(Point, Tile[T]))
- func (m *Grid[T]) At(x, y int16) (Tile[T], bool)
- func (m *Grid[T]) Each(fn func(Point, Tile[T]))
- func (m *Grid[T]) MaskAt(x, y int16, tile, mask Value)
- func (m *Grid[T]) MergeAt(x, y int16, merge func(Value) Value)
- func (m *Grid[T]) Neighbors(x, y int16, fn func(Point, Tile[T]))
- func (m *Grid[T]) Path(from, to Point, costOf costFn) ([]Point, int, bool)
- func (m *Grid[T]) Within(nw, se Point, fn func(Point, Tile[T]))
- func (m *Grid[T]) WriteAt(x, y int16, tile Value)
- func (m *Grid[T]) WriteFile(filename string) error
- func (m *Grid[T]) WriteTo(dst io.Writer) (n int64, err error)
- type Observer
- type Point
- func (p Point) Add(p2 Point) Point
- func (p Point) Angle(other Point) Direction
- func (p Point) DistanceTo(other Point) uint32
- func (p Point) Divide(p2 Point) Point
- func (p Point) DivideScalar(s int16) Point
- func (p Point) Equal(other Point) bool
- func (p Point) Integer() uint32
- func (p Point) Move(direction Direction) Point
- func (p Point) MoveBy(direction Direction, n int16) Point
- func (p Point) Multiply(p2 Point) Point
- func (p Point) MultiplyScalar(s int16) Point
- func (p Point) String() string
- func (p Point) Subtract(p2 Point) Point
- func (p Point) Within(nw, se Point) bool
- func (p Point) WithinRect(box Rect) bool
- func (p Point) WithinSize(size Point) bool
- type Rect
- type Tile
- func (t Tile[T]) Add(v T)
- func (t Tile[T]) Count() (count int)
- func (t Tile[T]) Del(v T)
- func (t Tile[T]) IsObserved() bool
- func (t Tile[T]) Mask(tile, mask Value) Value
- func (t Tile[T]) Merge(merge func(Value) Value) Value
- func (t Tile[T]) Move(v T, dst Point) bool
- func (t Tile[T]) Observers(fn func(view Observer[T]))
- func (t Tile[T]) Point() Point
- func (t Tile[T]) Range(fn func(T) error) error
- func (t Tile[T]) Value() Value
- func (t Tile[T]) Write(tile Value)
- type Update
- type Value
- type ValueAt
- type View
- func (v *View[S, T]) At(x, y int16) (Tile[T], bool)
- func (v *View[S, T]) Close() error
- func (v *View[S, T]) Each(fn func(Point, Tile[T]))
- func (v *View[S, T]) MergeAt(x, y int16, tile, mask Value)
- func (v *View[S, T]) MoveAt(nw Point, fn func(Point, Tile[T]))
- func (v *View[S, T]) MoveBy(x, y int16, fn func(Point, Tile[T]))
- func (v *View[S, T]) MoveTo(angle Direction, distance int16, fn func(Point, Tile[T]))
- func (v *View[S, T]) Resize(view Rect, fn func(Point, Tile[T]))
- func (v *View[S, T]) Viewport() Rect
- func (v *View[S, T]) WriteAt(x, y int16, tile Value)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Direction ¶ added in v1.2.0
type Direction byte
Diretion represents a direction
Various directions
type Grid ¶
type Grid[T comparable] struct { Size Point // The map size // contains filtered or unexported fields }
Grid represents a 2D tile map. Internally, a map is composed of 3x3 pages.
func NewGrid ¶
NewGrid returns a new map of the specified size. The width and height must be both multiples of 3.
func NewGridOf ¶ added in v1.3.0
func NewGridOf[T comparable](width, height int16) *Grid[T]
NewGridOf returns a new map of the specified size. The width and height must be both multiples of 3.
func ReadFile ¶ added in v1.2.2
func ReadFile[T comparable](filename string) (grid *Grid[T], err error)
Restore restores the grid from the specified file. The grid must be written using the corresponding WriteFile() method.
func ReadFrom ¶
func ReadFrom[T comparable](src io.Reader) (grid *Grid[T], err error)
ReadFrom reads the grid from the reader.
func (*Grid[T]) MaskAt ¶ added in v1.3.0
MaskAt atomically updates the bits of tile at a specific coordinate. The bits are specified by the mask. The bits that need to be updated should be flipped on in the mask.
func (*Grid[T]) MergeAt ¶
Merge atomically merges the tile by applying a merging function at a specific coordinate.
func (*Grid[T]) Within ¶
Within selects the tiles within a specifid bounding box which is specified by north-west and south-east coordinates.
type Observer ¶ added in v1.5.0
type Observer[T comparable] interface { Viewport() Rect Resize(Rect, func(Point, Tile[T])) // contains filtered or unexported methods }
Observer represents a tile update Observer.
type Point ¶
Point represents a 2D coordinate.
func (Point) DistanceTo ¶
DistanceTo calculates manhattan distance to the other point
func (Point) DivideScalar ¶
DivideScalar divides the given point by the scalar.
func (Point) MultiplyScalar ¶
MultiplyScalar multiplies the given point by the scalar.
func (Point) WithinRect ¶
WithinRect checks if the point is within the specified bounding box.
func (Point) WithinSize ¶
WithinSize checks if the point is within the specified bounding box which starts at 0,0 until the width/height provided.
type Rect ¶
type Rect struct {
Min Point // Top left point of the rectangle
Max Point // Bottom right point of the rectangle
}
Rect represents a rectangle
func (Rect) Difference ¶ added in v1.4.0
Difference calculates up to four non-overlapping regions in a that are not covered by b. If there are fewer than four distinct regions, the remaining Rects will be zero-value.
func (Rect) Intersects ¶
Intersects returns whether a rectangle intersects with another rectangle or not.
type Tile ¶
type Tile[T comparable] struct { // contains filtered or unexported fields }
Tile represents an iterator over all state objects at a particular location.
func (Tile[T]) IsObserved ¶ added in v1.6.3
IsObserved returns whether the tile is observed or not
func (Tile[T]) Mask ¶ added in v1.3.0
Mask updates the bits of tile. The bits are specified by the mask. The bits that need to be updated should be flipped on in the mask.
func (Tile[T]) Merge ¶ added in v1.3.0
Merge atomically merges the tile by applying a merging function.
func (Tile[T]) Move ¶ added in v1.6.0
Move moves an object from the current tile to the destination tile.
type Update ¶
type Update[T comparable] struct { Old ValueAt // Old tile + value New ValueAt // New tile + value Add T // An object was added to the tile Del T // An object was removed from the tile }
Update represents a tile update notification.
type Value ¶ added in v1.3.0
type Value = uint32
Value represents a packed tile information, it must fit on 4 bytes.
type View ¶
type View[S any, T comparable] struct { Grid *Grid[T] // The associated map Inbox chan Update[T] // The update inbox for the view State S // The state of the view // contains filtered or unexported fields }
View represents a view which can monitor a collection of tiles. Type parameters S and T are the state and tile types respectively.
func NewView ¶ added in v1.5.0
func NewView[S any, T comparable](m *Grid[T], state S) *View[S, T]
NewView creates a new view for a map with a given state. State can be anything that is passed to the view and can be used to store additional information.
func (*View[S, T]) MergeAt ¶
MergeAt updates the bits of tile at a specific coordinate. The bits are specified by the mask. The bits that need to be updated should be flipped on in the mask.
func (*View[S, T]) MoveTo ¶ added in v1.4.0
MoveTo moves the viewport towards a particular direction.