terrain

package
Version: v0.0.0-...-9e256ac Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Start of sand layer (right above water)
	SandLevel = 255 / 2

	// Start of grass layer (right above sand)
	GrassLevel = SandLevel + 1*resolution
)
View Source
const (
	// Seed default seed.
	Seed = int64(56)
	// OffsetX the default x offset from the origin in world space.
	OffsetX = -128 * Scale
	// OffsetY the default y offset from the origin in world space.
	OffsetY = -128 * Scale
)
View Source
const Scale = 25

Scale pixel width/height in meters. Converts from world space to terrain space.

View Source
const (
	Size = 2048
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer writes 4 bits of a byte and uses run length encoding. Each byte is 4 bits of data followed by 4 bits of count - 1.

func (*Buffer) Buffer

func (buffer *Buffer) Buffer() []byte

Buffer returns the remaining bytes

func (*Buffer) Grow

func (buffer *Buffer) Grow(n int)

Grow makes space for about n elements

func (*Buffer) Read

func (buffer *Buffer) Read(buf []byte) (int, error)

Write implements io.Reader.

func (*Buffer) Reset

func (buffer *Buffer) Reset(buf []byte)

func (*Buffer) Write

func (buffer *Buffer) Write(buf []byte) (int, error)

Write implements io.Writer.

type ColorVec

type ColorVec [3]float32

func Gray

func Gray(v byte) ColorVec

func RGB

func RGB(r, g, b byte) ColorVec

func (ColorVec) Color

func (vec ColorVec) Color() color.RGBA

func (ColorVec) Lerp

func (vec ColorVec) Lerp(other ColorVec, factor float32) ColorVec

func (ColorVec) Mul

func (vec ColorVec) Mul(v float32) ColorVec

func (ColorVec) String

func (vec ColorVec) String() string

type Data

type Data struct {
	world.AABB
	Data   []byte `json:"data"`   // Data is a possibly compressed terrain heightmap.
	Stride int    `json:"stride"` // Stride is width of Data.
	Length int    `json:"length"` // Length is uncompressed length of Data for faster reading.
}

Data describes part of a heightmap. It may be in a compressed format.

func NewData

func NewData() *Data

func (*Data) Pool

func (data *Data) Pool()

type Source

type Source interface {
	Generate(x, y, width, height int) []byte
}

Source generates heightmap data.

type Terrain

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

Terrain is a compressed implementation of terrain.Terrain. It represents each terrain pixel with 4 bits of precision.

func New

func New(source Source) *Terrain

New creates a new Terrain from a source.

func (*Terrain) AltitudeAt

func (t *Terrain) AltitudeAt(pos world.Vec2f) float32

Returns altitude (in meters) above sea level

func (*Terrain) At

func (t *Terrain) At(aabb world.AABB) *Data

At returns compressed terrain data at a given bounding box.

func (*Terrain) AtPos

func (t *Terrain) AtPos(pos world.Vec2f) byte

AtPos returns the height at a world position using bi-linear interpolation.

func (*Terrain) Clamp

func (t *Terrain) Clamp(aabb world.AABB) world.AABB

Clamp clamps a bounding box to what At will send. It's useful for caching terrain data.

func (*Terrain) Collides

func (t *Terrain) Collides(entity *world.Entity, seconds float32) bool

Collides returns if an entity collides with the terrain given a time step in seconds.

func (*Terrain) Debug

func (t *Terrain) Debug()

func (*Terrain) Decode

func (t *Terrain) Decode(data *Data) (raw []byte, err error)

Decode decompresses terrain data compressed with this terrain.

func (*Terrain) LandAt

func (t *Terrain) LandAt(pos world.Vec2f) bool

Returns whether the position lies in land (sand or higher)

func (*Terrain) Render

func (t *Terrain) Render(size int) image.Image

func (*Terrain) Repair

func (t *Terrain) Repair()

Repair reverts some of the terrain closer to its original generated state.

func (*Terrain) Sculpt

func (t *Terrain) Sculpt(pos world.Vec2f, amount float32)

Sculpt changes the terrain height at pos by an amount.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL