Voxy v0.0.1
Cluster3D< C, V > Struct Template Reference

Nearby chunks 3x3x3 group container. More...

#include <cluster.hpp>

Classes

struct  Position
 Cluster 3D position container. More...

Public Types

typedef C Chunk
typedef V Voxel

Public Member Functions

 Cluster3D (Chunk *chunks[size]=nullptr) noexcept
 Creates a new chunk 3x3x3 cluster.
ChunkgetChunks () noexcept
 Returns cluster chunk array.
const ChunkgetChunks () const noexcept
 Returns constant cluster chunk array.
bool isComplete () const noexcept
 Are all cluster chunks not null.
ChunkgetCentralChunk () const noexcept
 Returns cluster central chunk. (It can be null).
ChunkgetChunk (uint8_t x, uint8_t y, uint8_t z) const noexcept
 Returns cluster chunk at specified 3D position. (It can be null).
ChunkgetChunk (uint8_t index) const noexcept
 Returns cluster chunk at specified array index. (It can be null).
ChunktryGetChunk (uint8_t x, uint8_t y, uint8_t z) const noexcept
 Returns cluster chunk at specified 3D position. (It can be null).
ChunktryGetChunk (uint8_t index) const noexcept
 Returns cluster chunk at specified array index. (It can be null).
ChunkunsafeGetChunk (uint8_t x, uint8_t y, uint8_t z) const noexcept
 Returns cluster chunk at specified 3D position. (It can be null).
ChunkunsafeGetChunk (uint8_t index) const noexcept
 Returns cluster chunk at specified array index. (It can be null).
ChunkgetVoxelChunk (int16_t &x, int16_t &y, int16_t &z) const noexcept
 Returns cluster chunk at specified voxel 3D position relative to the central chunk.
ChunktryGetVoxelChunk (int16_t &x, int16_t &y, int16_t &z) const noexcept
 Returns cluster chunk at specified voxel 3D position relative to the central chunk.
ChunkunsafeGetVoxelChunk (int16_t &x, int16_t &y, int16_t &z) const noexcept
 Returns cluster chunk at specified voxel 3D position relative to the central chunk.
Voxel getVoxel (int16_t x, int16_t y, int16_t z, Voxel nullVoxel=voxel::null) const noexcept
 Returns voxel at specified 3D position relative to the central chunk.
void setVoxel (uint16_t x, uint16_t y, uint16_t z, Voxel voxel) noexcept
 Sets voxel at specified 3D position relative to the central chunk.
bool tryGetVoxel (int16_t x, int16_t y, int16_t z, Voxel &voxel) const noexcept
 Returns voxel at specified 3D position relative to the central chunk.
bool trySetVoxel (uint16_t x, uint16_t y, uint16_t z, Voxel voxel) noexcept
 Sets voxel at specified 3D position relative to the central chunk.
Voxel unsafeGetVoxel (int16_t x, int16_t y, int16_t z, Voxel nullVoxel=voxel::null) const noexcept
 Returns voxel at specified 3D position relative to the central chunk.

Static Public Member Functions

static constexpr uint8_t posToIndex (uint8_t x, uint8_t y, uint8_t z) noexcept
 Calculates cluster chunk index from the 3D position.
template<typename T>
static constexpr void indexToPos (uint8_t index, uint8_t &x, uint8_t &y, uint8_t &z) noexcept
 Calculates cluster chunk 3D position from the index.

Static Public Attributes

static constexpr uint8_t length = 3
static constexpr uint8_t layerSize = 9
static constexpr uint8_t size = 27
static constexpr Position positions [size]
 Cluster 3D positions 3x3x3.
static constexpr uint8_t centralIndex = posToIndex(1, 1, 1)
 Central cluster chunk index.

Protected Attributes

Chunkchunks [size]

Detailed Description

template<class C, typename V>
struct voxy::Cluster3D< C, V >

Nearby chunks 3x3x3 group container.

Template Parameters
Ccluster chunk type
Vchunk voxel ID type

Member Typedef Documentation

◆ Chunk

template<class C, typename V>
typedef C Chunk

Cluster chunk type.

◆ Voxel

template<class C, typename V>
typedef V Voxel

Chunk voxel ID type.

Constructor & Destructor Documentation

◆ Cluster3D()

template<class C, typename V>
Cluster3D ( Chunk * chunks[size] = nullptr)
inlinenoexcept

Creates a new chunk 3x3x3 cluster.

Parameters
chunkstarget cluster chunk array or null

Member Function Documentation

◆ posToIndex()

template<class C, typename V>
constexpr uint8_t posToIndex ( uint8_t x,
uint8_t y,
uint8_t z )
inlinestaticconstexprnoexcept

Calculates cluster chunk index from the 3D position.

Parameters
xchunk position along X-axis
ychunk position along Y-axis
zchunk position along Z-axis

◆ indexToPos()

template<class C, typename V>
template<typename T>
constexpr void indexToPos ( uint8_t index,
uint8_t & x,
uint8_t & y,
uint8_t & z )
inlinestaticconstexprnoexcept

Calculates cluster chunk 3D position from the index.

Parameters
indexchunk index inside the chunk
[out]xchunk position along X-axis
[out]ychunk position along Y-axis
[out]zchunk position along Z-axis

◆ getChunk() [1/2]

template<class C, typename V>
Chunk * getChunk ( uint8_t x,
uint8_t y,
uint8_t z ) const
inlinenoexcept

Returns cluster chunk at specified 3D position. (It can be null).

Note
Use with care, it doesn't checks for out of cluster bounds!
Parameters
xchunk position along X-axis
ychunk position along Y-axis
zchunk position along Z-axis

◆ getChunk() [2/2]

template<class C, typename V>
Chunk * getChunk ( uint8_t index) const
inlinenoexcept

Returns cluster chunk at specified array index. (It can be null).

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

◆ tryGetChunk() [1/2]

template<class C, typename V>
Chunk * tryGetChunk ( uint8_t x,
uint8_t y,
uint8_t z ) const
inlinenoexcept

Returns cluster chunk at specified 3D position. (It can be null).

Parameters
xchunk position along X-axis
ychunk position along Y-axis
zchunk position along Z-axis
Returns
Chunk instance if 3D position is inside array bounds.

◆ tryGetChunk() [2/2]

template<class C, typename V>
Chunk * tryGetChunk ( uint8_t index) const
inlinenoexcept

Returns cluster chunk at specified array index. (It can be null).

Parameters
indextarget chunk index inside array
Returns
Chunk instance if index is inside array bounds.

◆ unsafeGetChunk() [1/2]

template<class C, typename V>
Chunk * unsafeGetChunk ( uint8_t x,
uint8_t y,
uint8_t z ) const
inlinenoexcept

Returns cluster chunk at specified 3D position. (It can be null).

Warning
Skips out of bounds check in Debug and Release builds!
Parameters
xchunk position along X-axis
ychunk position along Y-axis
zchunk position along Z-axis

◆ unsafeGetChunk() [2/2]

template<class C, typename V>
Chunk * unsafeGetChunk ( uint8_t index) const
inlinenoexcept

Returns cluster chunk at specified array index. (It can be null).

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

◆ getVoxelChunk()

template<class C, typename V>
Chunk * getVoxelChunk ( int16_t & x,
int16_t & y,
int16_t & z ) const
inlinenoexcept

Returns cluster chunk at specified voxel 3D position relative to the central chunk.

Note
Use with care, it doesn't checks for out of cluster bounds!
Parameters
[in,out]xvoxel position along X-axis (Relative to the central chunk)
[in,out]yvoxel position along Y-axis (Relative to the central chunk)
[in,out]zvoxel position along Z-axis (Relative to the central chunk)
Returns
Target voxel chunk and sets local x/y/z if it is not null.

◆ tryGetVoxelChunk()

template<class C, typename V>
Chunk * tryGetVoxelChunk ( int16_t & x,
int16_t & y,
int16_t & z ) const
inlinenoexcept

Returns cluster chunk at specified voxel 3D position relative to the central chunk.

Parameters
[in,out]xvoxel position along X-axis (Relative to the central chunk)
[in,out]yvoxel position along Y-axis (Relative to the central chunk)
[in,out]zvoxel position along Z-axis (Relative to the central chunk)
Returns
Target voxel chunk and sets local x/y/z if it is not null.

◆ unsafeGetVoxelChunk()

template<class C, typename V>
Chunk * unsafeGetVoxelChunk ( int16_t & x,
int16_t & y,
int16_t & z ) const
inlinenoexcept

Returns cluster chunk at specified voxel 3D position relative to the central chunk.

Warning
Skips out of bounds check in Debug and Release builds!
Parameters
[in,out]xvoxel position along X-axis (Relative to the central chunk)
[in,out]yvoxel position along Y-axis (Relative to the central chunk)
[in,out]zvoxel position along Z-axis (Relative to the central chunk)
Returns
Target voxel chunk and sets local x/y/z if it is not null.

◆ getVoxel()

template<class C, typename V>
Voxel getVoxel ( int16_t x,
int16_t y,
int16_t z,
Voxel nullVoxel = voxel::null ) const
inlinenoexcept

Returns voxel at specified 3D position relative to the central chunk.

Note
Use with care, it doesn't checks for out of cluster bounds!
Parameters
xvoxel position along X-axis (Relative to the central chunk)
yvoxel position along Y-axis (Relative to the central chunk)
zvoxel position along Z-axis (Relative to the central chunk)
nullVoxelvoxel ID returned if chunk instance is null
Returns
Voxel at specified 3D position, or null if target chunk is null.

◆ setVoxel()

template<class C, typename V>
void setVoxel ( uint16_t x,
uint16_t y,
uint16_t z,
Voxel voxel )
inlinenoexcept

Sets voxel at specified 3D position relative to the central chunk.

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

◆ tryGetVoxel()

template<class C, typename V>
bool tryGetVoxel ( int16_t x,
int16_t y,
int16_t z,
Voxel & voxel ) const
inlinenoexcept

Returns voxel at specified 3D position relative to the central chunk.

Parameters
xvoxel position along X-axis (Relative to the central chunk)
yvoxel position along Y-axis (Relative to the central chunk)
zvoxel position along Z-axis (Relative to the central chunk)
[out]voxeltarget voxel ID on success
Returns
True if specified 3D position is inside array bounds and chunk is not null.

◆ trySetVoxel()

template<class C, typename V>
bool trySetVoxel ( uint16_t x,
uint16_t y,
uint16_t z,
Voxel voxel )
inlinenoexcept

Sets voxel at specified 3D position relative to the central chunk.

Parameters
xvoxel position along X-axis
yvoxel position along Y-axis
zvoxel position along Z-axis
voxeltarget voxel ID
Returns
True if specified 3D position is inside array bounds and chunk is not null.

◆ unsafeGetVoxel()

template<class C, typename V>
Voxel unsafeGetVoxel ( int16_t x,
int16_t y,
int16_t z,
Voxel nullVoxel = voxel::null ) const
inlinenoexcept

Returns voxel at specified 3D position relative to the central chunk.

Warning
Skips out of bounds check in Debug and Release builds!
Parameters
xvoxel position along X-axis (Relative to the central chunk)
yvoxel position along Y-axis (Relative to the central chunk)
zvoxel position along Z-axis (Relative to the central chunk)
nullVoxelvoxel ID returned if chunk instance is null
Returns
Voxel at specified 3D position, or null if target chunk is null.

Member Data Documentation

◆ length

template<class C, typename V>
uint8_t length = 3
staticconstexpr

Cluster length in chunks.

◆ layerSize

template<class C, typename V>
uint8_t layerSize = 9
staticconstexpr

Cluster layer size in chunks. (length ^ 2)

◆ size

template<class C, typename V>
uint8_t size = 27
staticconstexpr

Cluster size in chunks. (length ^ 3)

◆ positions

template<class C, typename V>
Position positions[size]
staticconstexpr
Initial value:
=
{
Position(-1, -1, -1), Position( 0, -1, -1), Position( 1, -1, -1),
Position(-1, 0, -1), Position( 0, 0, -1), Position( 1, 0, -1),
Position(-1, 1, -1), Position( 0, 1, -1), Position( 1, 1, -1),
Position(-1, -1, 0), Position( 0, -1, 0), Position( 1, -1, 0),
Position(-1, 0, 0), Position( 0, 0, 0), Position( 1, 0, 0),
Position(-1, 1, 0), Position( 0, 1, 0), Position( 1, 1, 0),
Position(-1, -1, 1), Position( 0, -1, 1), Position( 1, -1, 1),
Position(-1, 0, 1), Position( 0, 0, 1), Position( 1, 0, 1),
Position(-1, 1, 1), Position( 0, 1, 1), Position( 1, 1, 1)
}
Cluster 3D position container.
Definition cluster.hpp:46

Cluster 3D positions 3x3x3.

◆ chunks

template<class C, typename V>
Chunk* chunks[size]
protected

Cluster chunk array.