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]) View(rect Rect, fn func(Point, Tile[T])) *View[T]
- 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 Point
- func (p Point) Add(p2 Point) Point
- 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 (c Tile[T]) Add(v T)
- func (c Tile[T]) ChangeDirection(d uint32, id uint32, data interface{})
- func (c Tile[T]) Count() (count int)
- func (c Tile[T]) Del(v T)
- func (c Tile[T]) Despawn(v T, id uint32, data interface{})
- func (c Tile[T]) Mask(tile, mask Value) Value
- func (c Tile[T]) Merge(merge func(Value) Value) Value
- func (c Tile[T]) MoveTo(cd Tile[T], v T, id uint32, data interface{})
- func (c Tile[T]) Range(fn func(T) error) error
- func (c Tile[T]) SimpleDespawn(v T)
- func (c Tile[T]) SimpleMoveTo(cd Tile[T], v T)
- func (c Tile[T]) SimpleSpawn(v T)
- func (c Tile[T]) Spawn(v T, id uint32, data interface{})
- func (c Tile[T]) TriggerEvent(id uint32, data interface{})
- func (c Tile[T]) Value() Value
- func (c Tile[T]) Write(tile Value)
- type Update
- type Value
- type View
- func (v *View[T]) At(x, y int16) (Tile[T], bool)
- func (v *View[T]) Close() error
- func (v *View[T]) Each(fn func(Point, Tile[T]))
- func (v *View[T]) MergeAt(x, y int16, tile, mask Value)
- func (v *View[T]) MoveAt(nw Point, fnNew, fnOld func(Point, Tile[T]))
- func (v *View[T]) MoveBy(x, y int16, fnNew, fnOld func(Point, Tile[T]))
- func (v *View[T]) Resize(box Rect, fnNew, fnOld func(Point, Tile[T]))
- func (v *View[T]) WriteAt(x, y int16, tile Value)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
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 ¶
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 ¶
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 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) 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]) ChangeDirection ¶
func (Tile[T]) Mask ¶
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]) SimpleDespawn ¶
func (c Tile[T]) SimpleDespawn(v T)
func (Tile[T]) SimpleMoveTo ¶
Add adds object to the set
func (Tile[T]) SimpleSpawn ¶
func (c Tile[T]) SimpleSpawn(v T)
func (Tile[T]) TriggerEvent ¶
type Update ¶
type Update[T comparable] struct { Point // The tile location Old Value // Old tile value New Value // New tile value Add T // An object was added to the tile Del T // An object was removed from the tile Dir uint32 Moved T Spawned T Despawned T Emmiter uint32 Data interface{} }
Update represents a tile update notification.
type Value ¶
type Value = uint32
Value represents a packed tile information, it must fit on 4 bytes.
type View ¶
type View[T comparable] struct { Grid *Grid[T] // The associated map Inbox chan Update[T] // The update inbox for the view // contains filtered or unexported fields }
View represents a view which can monitor a collection of tiles.
func (*View[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.