Documentation ¶
Index ¶
- Constants
- type Block
- type BlockType
- type Chunk
- func (c *Chunk) BlockAt(x, y, z int) *Block
- func (c *Chunk) Clone() *Chunk
- func (c *Chunk) Destroy()
- func (c *Chunk) GetTheRenderable(textureIndexes fizzle.TextureArrayIndexes) *fizzle.Renderable
- func (c *Chunk) IsBlockMovementBlocking(x, y, z int) bool
- func (c *Chunk) IsBlockVisible(x, y, z int) bool
- func (c *Chunk) SetBlock(x, y, z int, ty BlockType)
- func (c *Chunk) UpdateColliders()
- type Manager
Constants ¶
const ( // ChunkSize controls the cubic dimensions of Chunk structures ChunkSize = 16 // ChunkSizeF is the size of the Chunk in float ChunkSizeF = float32(16.0) // ChunkSize2 is chunkSize squared ChunkSize2 = ChunkSize * ChunkSize // ChunkSize3 is chunkSize cubed ChunkSize3 = ChunkSize2 * ChunkSize )
const ( BlockTypeEmpty = BlockType(0) BlockTypeGrass = BlockType(1) BlockTypeStones = BlockType(2) BlockTypeDirt = BlockType(3) )
TODO: these are temporary fixes until the chunk manager has a map of block types to descriptors.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct { // Type determines the type of block that the Block struct represents // NOTE: a Type of 0 has special significance in that it's assumed // to be an empty space. Type BlockType }
Block is the basic building block of the landscape terrain.
type BlockType ¶
type BlockType uint32
BlockType is a type alias for the variable that will determine what type a landscape Block is in the Chunk.
type Chunk ¶
type Chunk struct { // X is the location of Chunk along the X axis in multiples of ChunkSize. // (e.g. a value of Chunk.X==2 for ChunkSize==16 means a world position of 32) X int // Y is the location of Chunk along the Y axis in multiples of ChunkSize. // (e.g. a value of Chunk.Y==2 for ChunkSize==16 means a world position of 32) Y int // Z is the location of Chunk along the Z axis in multiples of ChunkSize. // (e.g. a value of Chunk.Z==2 for ChunkSize==16 means a world position of 32) Z int // Blocks is a flat array [y*x*z] Block values. You can think // of it in +Z first ordering, meaning it fills a depth of Z, then moves in +X // and fills another depth of Z. // // Viz: // Y // ^ Z // |/__> X // // Further examples for RegionDepth of 16: // (0,0,0) = [0] // (0,0,5) = [5] // (1,0,0) = [16] // (1,0,5) = [21] // (0,1,0) = [256] (16*16) Blocks [ChunkSize3]Block // Renderable is the drawable OpenGL object for the chunk. In a server-side // only server, this pointer will be nil. Renderable *fizzle.Renderable // AABBCollider is an axis aligned bounding box collider for the chunk for // use in simple collision checks with the space of the entire chunk, // regarldless of the contents (i.e. will still collide on 'empty' blocks // and contains the entierty of the chunk). // Note: coordinates used in the collider are in world space. AABBCollider *glider.AABBox // colliders is a slice of calculate physics colliders for the chunk geometry. // This is generated on calls to UpdateColliders() which should be called // when the Blocks array has value changes. Colliders []physics.Collider // BoxColliders is a slice of AABBoxes that mirrors the physics colliders. // This can be used for faster raycasts since the voxels aren't rotating. BoxColliders []*glider.AABBox // Owner is the owning landscape Manager class. This will be nil if the Chunk // has not been registered yet with a manager. Owner *Manager }
Chunk is the data structure that groups together Blocks.
func (*Chunk) BlockAt ¶
BlockAt returns the Block object at a given offset within the Chunk. NOTE: not to be confused with coordinate -- this is the offset in the Cubes array.
func (*Chunk) Clone ¶
Clone creates a new Chunk object with the core data but does not duplicate the Renderable or physics colliders
func (*Chunk) Destroy ¶
func (c *Chunk) Destroy()
Destroy tells the chunk to release any special data.
func (*Chunk) GetTheRenderable ¶
func (c *Chunk) GetTheRenderable(textureIndexes fizzle.TextureArrayIndexes) *fizzle.Renderable
GetTheRenderable returns the already crafted Renderable object or makes one, caches it and returns a pointer to it.
func (*Chunk) IsBlockMovementBlocking ¶
IsBlockMovementBlocking checks to see if a block location blocks movement from entities. Having this separate from IsVisible makes the mechanic being checked more explicit.
func (*Chunk) IsBlockVisible ¶
IsBlockVisible tests whether or not the block is visible. x,y,z are specified in local coordinates. NOTE: blocks on the outside of the chunk are always considered visible.
func (*Chunk) SetBlock ¶
SetBlock sets the attribute of a block at a given coordiante. X,Y,Z should be within range of [0..ChunkSize-1].
func (*Chunk) UpdateColliders ¶
func (c *Chunk) UpdateColliders()
UpdateColliders should be called whenever the Blocks of the Chunk change which could result in the pathing being different.
type Manager ¶
type Manager struct { // Chunks is the internal splice of all of the chunks registered in the Manager. // Access to this will depend on the Size parameter. Chunks []*Chunk // Size is the number of chunks in each direction to manage. Size int // X is the location of Manager along the X axis in multiples of ChunkSize. // (e.g. a value of Manager.X==2 for ChunkSize==16 means a world position of 32) X int // Y is the location of Manager along the Y axis in multiples of ChunkSize. // (e.g. a value of Manager.Y==2 for ChunkSize==16 means a world position of 32) Y int // Z is the location of Manager along the Z axis in multiples of ChunkSize. // (e.g. a value of Manager.Z==2 for ChunkSize==16 means a world position of 32) Z int }
Manager is the landscape manager type structure that manages access to landscape data.
func NewManager ¶
NewManager returns a new voxel manager object that manages a cube region of chunks.
func (*Manager) GetBlockAt ¶
GetBlockAt returns the block at a given coorindate and, as an added bonus to faithful callers, it will also return the chunk. A two for one! NOTE: restrictions apply! If world xyz doesn't exist in the manger, (nil, nil) is returned.
func (*Manager) GetHeightAt ¶
GetHeightAt returns the local height of the land at the local coordinate X,Z passed in.
func (*Manager) RegisterChunk ¶
RegisterChunk fits the new chunk into the chunks slice of the Manager
func (*Manager) RegisterChunks ¶
RegisterChunks registers all of the chunks in the slice passed in.
func (*Manager) SetBlockAt ¶
SetBlockAt sets the block type and color for a given locaiton in the world. It will create a new chunk if necessary. It returns the chunk for the block that was set. NOTE: Does not update colliders. This was left to the calling client so that multiple updates at a time don't needlessly recreate colliders.