VoxelEngine
 
Loading...
Searching...
No Matches
engine::Chunk Class Reference
Inheritance diagram for engine::Chunk:
engine::Renderable engine::ISerializable

Classes

struct  GeometryState
 
struct  MeshGenContext
 

Public Member Functions

 Chunk (World *world, ChunkID coords, std::unique_ptr< IChunkData > data)
 
 Chunk (Chunk &)=delete
 
 Chunk (Chunk &&)=delete
 
const ChunkIDid () const
 
glm::ivec3 position () const
 
virtual glm::ivec3 dims () const
 Get the dimensions of this chunk type.
 
Worldworld () const
 
template<typename T >
T * worldAs () const
 
void populateTerrainData ()
 Generates the chunk data per TerrainGenerator if not generated yet.
 
bool generated () const
 
bool generateMesh ()
 Generates the mesh data for the chunk.
 
const BlockgetBlock (glm::ivec3 pos, BlockState **state=nullptr)
 
void setBlock (const glm::ivec3 &pos, BlockID block)
 
void setBlock (const glm::ivec3 &pos, BlockID block, BlockState state)
 
void setBlock (const glm::ivec3 &pos, MultiBlock &&multiBlock)
 
IChunkDatadata ()
 
const IChunkDatadata () const
 
void render (Engine &engine, const Camera *camera, int pass) override
 Renders the chunk.
 
VariantBlock::Neighbours getNeighbouringBlocks (glm::ivec3 pos) const
 
virtual void afterGenerated ()
 
void serialize (std::ostream &out) const override
 
void deserialize (std::istream &in) override
 

Static Public Attributes

static glm::ivec3 Dims {16, 16, 16}
 

Protected Member Functions

GeometryState calculateGeometryState (const Block *block, const BlockState *state) const
 
void generateMeshForGeometry (const MeshGenContext &ctx)
 
void generateMeshForBlock (const Block *block, glm::ivec3 pos, const BlockState *state, const glm::ivec3 &chunkBlockCoords)
 
void generateMeshForBlock (const VariantBlock *block, glm::ivec3 pos, const BlockState *state, const glm::ivec3 &chunkBlockCoords)
 
void generateMeshForBlock (const MultiBlock *block, glm::ivec3 pos, const BlockState *state, const glm::ivec3 &chunkBlockCoords)
 

Protected Attributes

Worldm_world
 
ChunkID m_coords
 
std::unique_ptr< IChunkDatam_data
 
bool m_dirty = false
 

Friends

class World
 

Member Function Documentation

◆ afterGenerated()

virtual void engine::Chunk::afterGenerated ( )
inlinevirtual

Events

◆ data() [1/2]

IChunkData * engine::Chunk::data ( )
inline
Returns
ChunkData structure containing all the block/terrain data.

◆ data() [2/2]

const IChunkData * engine::Chunk::data ( ) const
inline
Returns
const ChunkData structure containing all the block/terrain data.

◆ deserialize()

void Chunk::deserialize ( std::istream &  in)
overridevirtual

Implements engine::ISerializable.

◆ dims()

virtual glm::ivec3 engine::Chunk::dims ( ) const
inlinevirtual

Get the dimensions of this chunk type.

Returns
The dimensions (x, y, z) of the chunk.
Note
Override this in derived classes to provide custom chunk dimensions.

◆ generateMesh()

bool Chunk::generateMesh ( )

Generates the mesh data for the chunk.

Returns
true if the mesh was generated, false if it was already generating.
Note
This function is thread-safe.

◆ id()

const ChunkID & engine::Chunk::id ( ) const
inline
Returns
ID or coordinates of the chunk in the world.

◆ position()

glm::ivec3 engine::Chunk::position ( ) const
inline
Returns
Position of the chunk in world space.

◆ render()

void Chunk::render ( Engine engine,
const Camera camera,
int  pass 
)
overridevirtual

Renders the chunk.

Parameters
passPass == 0 will render the whole chunk, pass == 1 will render opaque blocks, pass == 2 will render transparent blocks.

Implements engine::Renderable.

◆ serialize()

void Chunk::serialize ( std::ostream &  out) const
overridevirtual

Implements engine::ISerializable.


The documentation for this class was generated from the following files: