Voxy v0.0.1
Chunk3D< SX, SY, SZ, V > Struct Template Reference

Voxel 3D container. (array). More...

#include <chunk.hpp>

Public Types

typedef V Voxel
 Chunk voxel ID type.

Public Member Functions

 Chunk3D () noexcept=default
 Creates a new uninitialized chunk.
 Chunk3D (Voxel voxel) noexcept
 Creates a new initialized chunk.
VoxelgetVoxels () noexcept
 Returns chunk voxel array.
const VoxelgetVoxels () const noexcept
 Returns constant chunk voxel array.
Voxel get (uint8_t x, uint8_t y, uint8_t z) const noexcept
 Returns chunk voxel at specified 3D position.
void set (uint8_t x, uint8_t y, uint8_t z, Voxel voxel) noexcept
 Sets chunk voxel at specified 3D position.
Voxel get (uint32_t index) const noexcept
 Returns chunk voxel at specified array index.
void set (uint32_t index, Voxel voxel) noexcept
 Sets chunk voxel at specified array index.
bool tryGet (uint8_t x, uint8_t y, uint8_t z, Voxel &voxel) const noexcept
 Returns chunk voxel at specified 3D position if inside chunk bounds.
bool trySet (uint8_t x, uint8_t y, uint8_t z, Voxel voxel) noexcept
 Sets chunk voxel at specified 3D position if inside chunk bounds.
bool tryGet (uint32_t index, Voxel &voxel) const noexcept
 Returns chunk voxel at specified array index if inside array bounds.
bool trySet (uint32_t index, Voxel voxel) noexcept
 Sets chunk voxel at specified array index if inside array bounds.
Voxel unsafeGet (uint8_t x, uint8_t y, uint8_t z) const noexcept
 Returns chunk voxel at specified 3D position.
void unsafeSet (uint8_t x, uint8_t y, uint8_t z, Voxel voxel) noexcept
 Sets chunk voxel at specified 3D position.
Voxel unsafeGet (uint32_t index) const noexcept
 Returns chunk voxel at specified array index.
void unsafeSet (uint32_t index, Voxel voxel) noexcept
 Sets chunk voxel at specified array index.
void clear () noexcept
 Fills chunk with zeros.
void fill (Voxel voxel) noexcept
 Fills chunk with specified voxel ID.
void copy (const Voxel *voxels) noexcept
 Copies voxels from specified array to this chunk.
void copy (const Voxel *otherVoxels, uint8_t otherLength, uint16_t otherLayerSize, uint8_t countX, uint8_t countY, uint8_t countZ, uint8_t otherOffsetX=0, uint8_t otherOffsetY=0, uint8_t otherOffsetZ=0, uint8_t thisOffsetX=0, uint8_t thisOffsetY=0, uint8_t thisOffsetZ=0) noexcept
 Copies voxels from specified array part to this chunk.

Static Public Member Functions

static constexpr uint32_t posToIndex (uint8_t x, uint8_t y, uint8_t z) noexcept
 Calculates chunk voxel index from the 3D position.
static constexpr void indexToPos (uint32_t index, uint8_t &x, uint8_t &y, uint8_t &z) noexcept
 Calculates chunk voxel 3D position from the index.

Static Public Attributes

static constexpr uint8_t lengthX = SX
 Chunk length in voxels along X-axis.
static constexpr uint8_t lengthY = SY
 Chunk length in voxels along Y-axis.
static constexpr uint8_t lengthZ = SZ
 Chunk length in voxels along Z-axis.
static constexpr uint16_t layerSize = SX * SY
 Chunk layer size in voxels. (sizeX * sizeY).
static constexpr uint32_t size = SX * SY * SZ
 Chunk array size in voxels, or chunk volume. (sizeX * sizeY * sizeZ).

Protected Attributes

Voxel voxels [size]

Detailed Description

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
struct voxy::Chunk3D< SX, SY, SZ, V >

Voxel 3D container. (array).

Template Parameters
SXchunk size in voxels along X-axis
SYchunk size in voxels along Y-axis
SZchunk size in voxels along Z-axis
Vchunk voxel ID type

Constructor & Destructor Documentation

◆ Chunk3D() [1/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
Chunk3D ( )
defaultnoexcept

Creates a new uninitialized chunk.

Warning
Chunk may contain garbage voxels.

◆ Chunk3D() [2/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
Chunk3D ( Voxel voxel)
inlinenoexcept

Creates a new initialized chunk.

Parameters
voxeltarget voxel to fill chunk with

Member Function Documentation

◆ posToIndex()

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
constexpr uint32_t posToIndex ( uint8_t x,
uint8_t y,
uint8_t z )
inlinestaticconstexprnoexcept

Calculates chunk voxel index from the 3D position.

Parameters
xvoxel position along X-axis
yvoxel position along Y-axis
zvoxel position along Z-axis

◆ indexToPos()

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
constexpr void indexToPos ( uint32_t index,
uint8_t & x,
uint8_t & y,
uint8_t & z )
inlinestaticconstexprnoexcept

Calculates chunk voxel 3D position from the index.

Parameters
indexvoxel index inside the chunk
[out]xvoxel position along X-axis
[out]yvoxel position along Y-axis
[out]zvoxel position along Z-axis

◆ get() [1/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
Voxel get ( uint8_t x,
uint8_t y,
uint8_t z ) const
inlinenoexcept

Returns chunk voxel at specified 3D position.

Note
Use with care, it doesn't checks for out of chunk bounds!
Parameters
xvoxel position along X-axis
yvoxel position along Y-axis
zvoxel position along Z-axis

◆ set() [1/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
void set ( uint8_t x,
uint8_t y,
uint8_t z,
Voxel voxel )
inlinenoexcept

Sets chunk voxel at specified 3D position.

Note
Use with care, it doesn't checks for out of chunk bounds!
Parameters
xvoxel position along X-axis
yvoxel position along Y-axis
zvoxel position along Z-axis
voxeltarget voxel ID

◆ get() [2/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
Voxel get ( uint32_t index) const
inlinenoexcept

Returns chunk voxel at specified array index.

Note
Use with care, it doesn't checks for out of array bounds!
Parameters
indextarget voxel index inside array

◆ set() [2/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
void set ( uint32_t index,
Voxel voxel )
inlinenoexcept

Sets chunk voxel at specified array index.

Note
Use with care, it doesn't checks for out of array bounds!
Parameters
indextarget voxel index inside array
voxeltarget voxel ID

◆ tryGet() [1/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
bool tryGet ( uint8_t x,
uint8_t y,
uint8_t z,
Voxel & voxel ) const
inlinenoexcept

Returns chunk voxel at specified 3D position if inside chunk bounds.

Parameters
xvoxel position along X-axis
yvoxel position along Y-axis
zvoxel position along Z-axis
[out]voxeltarget voxel ID
Returns
True if voxel 3D position is inside the chunk bounds, otherwise false.

◆ trySet() [1/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
bool trySet ( uint8_t x,
uint8_t y,
uint8_t z,
Voxel voxel )
inlinenoexcept

Sets chunk voxel at specified 3D position if inside chunk bounds.

Parameters
xvoxel position along X-axis
yvoxel position along Y-axis
zvoxel position along Z-axis
voxeltarget voxel ID
Returns
True if voxel 3D position is inside the chunk bounds, otherwise false.

◆ tryGet() [2/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
bool tryGet ( uint32_t index,
Voxel & voxel ) const
inlinenoexcept

Returns chunk voxel at specified array index if inside array bounds.

Parameters
indextarget voxel index inside array
[out]voxeltarget voxel ID
Returns
True if voxel index is inside array bounds, otherwise false.

◆ trySet() [2/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
bool trySet ( uint32_t index,
Voxel voxel )
inlinenoexcept

Sets chunk voxel at specified array index if inside array bounds.

Parameters
indextarget voxel index inside array
voxeltarget voxel ID
Returns
True if voxel index is inside array bounds, otherwise false.

◆ unsafeGet() [1/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
Voxel unsafeGet ( uint8_t x,
uint8_t y,
uint8_t z ) const
inlinenoexcept

Returns chunk voxel at specified 3D position.

Warning
Skips out of bounds check in Debug and Release builds!
Parameters
xvoxel position along X-axis
yvoxel position along Y-axis
zvoxel position along Z-axis

◆ unsafeSet() [1/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
void unsafeSet ( uint8_t x,
uint8_t y,
uint8_t z,
Voxel voxel )
inlinenoexcept

Sets chunk voxel at specified 3D position.

Warning
Skips out of bounds check in Debug and Release builds!
Parameters
xvoxel position along X-axis
yvoxel position along Y-axis
zvoxel position along Z-axis
voxeltarget voxel ID

◆ unsafeGet() [2/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
Voxel unsafeGet ( uint32_t index) const
inlinenoexcept

Returns chunk voxel at specified array index.

Warning
Skips out of bounds check in Debug and Release builds!
Parameters
indextarget voxel index inside array

◆ unsafeSet() [2/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
void unsafeSet ( uint32_t index,
Voxel voxel )
inlinenoexcept

Sets chunk voxel at specified array index.

Warning
Skips out of bounds check in Debug and Release builds!
Parameters
indextarget voxel index inside array
voxeltarget voxel ID

◆ fill()

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
void fill ( Voxel voxel)
inlinenoexcept

Fills chunk with specified voxel ID.

Parameters
voxeltarget voxel ID

◆ copy() [1/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
void copy ( const Voxel * voxels)
inlinenoexcept

Copies voxels from specified array to this chunk.

Note
Voxel array should have bigger or the same size as chunk!
Parameters
[in]voxelstarget voxel array

◆ copy() [2/2]

template<uint8_t SX, uint8_t SY, uint8_t SZ, typename V>
void copy ( const Voxel * otherVoxels,
uint8_t otherLength,
uint16_t otherLayerSize,
uint8_t countX,
uint8_t countY,
uint8_t countZ,
uint8_t otherOffsetX = 0,
uint8_t otherOffsetY = 0,
uint8_t otherOffsetZ = 0,
uint8_t thisOffsetX = 0,
uint8_t thisOffsetY = 0,
uint8_t thisOffsetZ = 0 )
inlinenoexcept

Copies voxels from specified array part to this chunk.

Note
Voxel array should have bigger or the same size as specified part!
Parameters
[in]otherVoxelstarget other voxel array
countXvoxel array part size along X-axis
countYvoxel array part size along Y-axis
countZvoxel array part size along Z-axis
otherLengthother voxel array length along X-axis
otherLayerSizeother voxel array layer size along X * Y
otherOffsetXother voxel array part offset along X-axis
otherOffsetYother voxel array part offset along Y-axis
otherOffsetZother voxel array part offset along Z-axis
thisOffsetXthis voxel array part offset along X-axis
thisOffsetYthis voxel array part offset along Y-axis
thisOffsetZthis voxel array part offset along Z-axis