world

package
v0.0.0-...-9f1eebf Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChunkWidth  = 16
	ChunkHeight = 256
	ChunkDepth  = 16
)

The size of the chunk (width, height, and depth), in blocks.

View Source
const (
	// MaxRenderRadius is the maximum number of chunks ahead of the player which
	// we can feasibly render.
	MaxRenderRadius = 32
)

Variables

This section is empty.

Functions

func ToChunkSpace

func ToChunkSpace(wx, wy, wz int) (p, q, x, y, z int)

ToChunkSpace returns the coordinates of the chunk and the block within that chunk that contain the given world-space coordinate.

func ToWorldSpace

func ToWorldSpace(wx, wy, wz float32) (int, int, int)

ToWorldSpace returns the absolute coordinate of the block that contains the given world-space coordinate.

Types

type Block

type Block uint32

Block is an ID representing the type of a block within the world.

type BlockInfo

type BlockInfo struct {
	Name        string // Display name of the block
	Visible     bool   // True if the block actually renders something
	Collidable  bool   // True if the block has a collidable AABB
	Transparent bool   // True if we can see the block behind at any angle
	Texture     string // Path to the texture to use for all faces
	UV          FaceUV // UV coordinates to use for all faces
}

BlockInfo contains the properties of a block type.

func (*BlockInfo) AABB

func (info *BlockInfo) AABB(p, q, x, y, z int) math.AABB

AABB returns an axis aligned bounding box for the block, used for collision detection.

type BlocksInfo

type BlocksInfo struct {
	Blocks []*BlockInfo
}

BlocksInfo contains the properties of every block type.

type Chunk

type Chunk struct {
	Blocks blockData // The cached block data for the chunk
	// contains filtered or unexported fields
}

Chunk stores information associated with a chunk, including OpenGL rendering information, block data, vertex data, and lighting data.

type FaceUV

type FaceUV struct {
	X, Y float32
}

FaceUV represents the base UV coordinate for a block face in the block texture atlas.

func (FaceUV) Size

func (uv FaceUV) Size() (float32, float32)

Size returns the size of a block texture in the texture atlas, scaled such that a size of (1.0, 1.0) represents the entire texture atlas. The size is used to calculate the UV coordinates passed to OpenGL for the block texture.

type RenderInfo

type RenderInfo struct {
	Camera       *camera.Camera
	PlayerChunkP int
	PlayerChunkQ int
}

RenderInfo stores information required by the world for rendering.

type World

type World struct {
	RenderRadius int // Current render distance
	// contains filtered or unexported fields
}

World manages the loading, unloading, and rendering of chunks.

func New

func New(renderRadius int) *World

New creates a new world instance with no loaded chunks.

func (*World) Destroy

func (w *World) Destroy()

Destroy unloads all the currently loaded chunks.

func (*World) FindChunk

func (w *World) FindChunk(p, q int) *Chunk

FindChunk checks to see if the chunk at the given coordinates is already loaded, and if so returns a pointer to it. Otherwise, returns nil.

func (*World) GenChunksAround

func (w *World) GenChunksAround(p, q int)

GenChunksAround generates all chunks within the render radius around a central chunk (usually the chunk that the player is in).

func (*World) GetBlockInfo

func (w *World) GetBlockInfo(block Block) *BlockInfo

GetBlockInfo returns information about a particular block type.

func (*World) Render

func (w *World) Render(info RenderInfo)

Render draws all loaded chunks with vertex data to the screen.

func (*World) Update

func (w *World) Update()

Update is called every update tick, and checks to see if any loading tasks are finished.

Jump to

Keyboard shortcuts

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