17 bool IsAllValue(
const T * a_Array,
size_t a_NumElements, T a_Value)
19 for (
size_t i = 0; i < a_NumElements; i++)
21 if (a_Array[i] != a_Value)
33 struct sSectionIndices
39 sSectionIndices IndicesFromRelPos(
Vector3i a_RelPos)
69 a_Other.m_Sections[i] =
nullptr;
111 if (&a_Other ==
this)
116 if (
m_Pool != a_Other.m_Pool)
128 a_Other.m_Sections[i] =
nullptr;
142 auto Idxs = IndicesFromRelPos(a_RelPos);
161 ASSERT(!
"cChunkData::SetMeta(): index out of range!");
165 auto Idxs = IndicesFromRelPos(a_RelPos);
175 ASSERT(!
"Failed to allocate a new section in Chunkbuffer");
191 auto Idxs = IndicesFromRelPos(a_RelPos);
213 ASSERT(!
"cChunkData::SetMeta(): index out of range!");
217 auto Idxs = IndicesFromRelPos(a_RelPos);
220 if ((a_Nibble & 0xf) == 0x00)
227 ASSERT(!
"Failed to allocate a new section in Chunkbuffer");
235 ((a_Nibble & 0x0f) << ((Idxs.Index & 1) * 4))
237 return oldval != a_Nibble;
248 auto Idxs = IndicesFromRelPos(a_RelPos);
258 ASSERT(!
"cChunkData::GetMeta(): coords out of chunk range!");
270 auto Idxs = IndicesFromRelPos(a_RelPos);
280 ASSERT(!
"cChunkData::GetMeta(): coords out of chunk range!");
294 ASSERT(!
"cChunkData::GetSection: section index out of range");
304 static_assert(
NumSections <= 16U,
"cChunkData::GetSectionBitmask needs a bigger data type");
335 size_t ToSkip = a_Idx;
430 if (Section ==
nullptr)
433 std::fill(std::begin(Section->m_BlockMetas), std::end(Section->m_BlockMetas), 0x00);
434 std::fill(std::begin(Section->m_BlockLight), std::end(Section->m_BlockLight), 0x00);
435 std::fill(std::begin(Section->m_BlockSkyLight), std::end(Section->m_BlockSkyLight), 0xff);
442 if (Section !=
nullptr)
444 std::fill(std::begin(Section->m_BlockTypes), std::end(Section->m_BlockTypes), a_Value);
460 if (Section ==
nullptr)
463 std::fill(std::begin(Section->m_BlockTypes), std::end(Section->m_BlockTypes), 0x00);
464 std::fill(std::begin(Section->m_BlockLight), std::end(Section->m_BlockLight), 0x00);
465 std::fill(std::begin(Section->m_BlockSkyLight), std::end(Section->m_BlockSkyLight), 0xff);
473 if (Section !=
nullptr)
475 std::fill(std::begin(Section->m_BlockMetas), std::end(Section->m_BlockMetas), NewMeta);
491 if (Section ==
nullptr)
494 std::fill(std::begin(Section->m_BlockTypes), std::end(Section->m_BlockTypes), 0x00);
495 std::fill(std::begin(Section->m_BlockMetas), std::end(Section->m_BlockMetas), 0x00);
496 std::fill(std::begin(Section->m_BlockSkyLight), std::end(Section->m_BlockSkyLight), 0xff);
504 if (Section !=
nullptr)
506 std::fill(std::begin(Section->m_BlockLight), std::end(Section->m_BlockLight), NewLight);
522 if (Section ==
nullptr)
525 std::fill(std::begin(Section->m_BlockTypes), std::end(Section->m_BlockTypes), 0x00);
526 std::fill(std::begin(Section->m_BlockMetas), std::end(Section->m_BlockMetas), 0x00);
527 std::fill(std::begin(Section->m_BlockLight), std::end(Section->m_BlockLight), 0x00);
535 if (Section !=
nullptr)
537 std::fill(std::begin(Section->m_BlockSkyLight), std::end(Section->m_BlockSkyLight), NewSkyLight);
560 if (IsAllValue(a_Src + i *
SectionBlockCount, SectionBlockCount, static_cast<BLOCKTYPE>(0)))
568 memcpy(
m_Sections[i]->m_BlockTypes, &a_Src[i * SectionBlockCount],
sizeof(
m_Sections[i]->m_BlockTypes));
614 if (a_Src ==
nullptr)
650 if (a_Src ==
nullptr)
void CopyMetas(NIBBLETYPE *a_Dest) const
Copies the metadata into the specified flat array.
cChunkData(cAllocationPool< sChunkSection > &a_Pool)
BLOCKTYPE m_BlockTypes[SectionBlockCount]
unsigned char BLOCKTYPE
The datatype used by blockdata.
const sChunkSection * GetSection(size_t a_SectionNum) const
Return a pointer to the chunk section or nullptr if all air.
static bool IsValidRelPos(Vector3i a_RelPos)
Validates a chunk relative coordinate.
NIBBLETYPE GetBlockLight(Vector3i a_RelPos) const
BLOCKTYPE GetBlock(Vector3i a_RelPos) const
void CopyBlockLight(NIBBLETYPE *a_Dest) const
Copies the block light data into the specified flat array.
sChunkSection * Allocate(void)
Allocates a new section.
void CopySkyLight(NIBBLETYPE *a_Dest) const
Copies the skylight data into the specified flat array.
void SetBlockLight(const NIBBLETYPE *a_Src)
Copies the blocklight data from the specified flat array into the internal representation.
void SetBlock(Vector3i a_RelPos, BLOCKTYPE a_Block)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
void CopyBlockTypes(BLOCKTYPE *a_Dest, size_t a_Idx=0, size_t a_Length=cChunkDef::NumBlocks) const
Copies the blocktype data into the specified flat array.
static int MakeIndexNoCheck(int x, int y, int z)
void SetBlockTypes(const BLOCKTYPE *a_Src)
Copies the blocktype data from the specified flat array into the internal representation.
void Free(sChunkSection *a_Section)
Frees the specified section, previously allocated using Allocate().
cAllocationPool< sChunkSection > & m_Pool
static const size_t SectionBlockCount
void ZeroSection(sChunkSection *a_Section) const
Sets the data in the specified section to their default values.
NIBBLETYPE GetSkyLight(Vector3i a_RelPos) const
void FillBlockTypes(BLOCKTYPE a_Value)
Fills the chunk with the specified block.
void FillBlockLight(NIBBLETYPE a_Value)
Fills the chunk with the specified block light.
NIBBLETYPE m_BlockSkyLight[SectionBlockCount/2]
void SetSkyLight(const NIBBLETYPE *a_Src)
Copies the skylight data from the specified flat array into the internal representation.
void FillMetas(NIBBLETYPE a_Value)
Fills the chunk with the specified meta value.
NIBBLETYPE m_BlockMetas[SectionBlockCount/2]
UInt16 GetSectionBitmask() const
Returns a bitmask of chunk sections which are currently stored.
bool SetMeta(Vector3i a_RelPos, NIBBLETYPE a_Nibble)
void Assign(const cChunkData &a_Other)
Copy assign from another cChunkData.
static const size_t NumSections
void FillSkyLight(NIBBLETYPE a_Value)
Fills the chunk with the specified sky light.
void SetMetas(const NIBBLETYPE *a_Src)
Copies the metadata from the specified flat array into the internal representation.
UInt32 NumPresentSections() const
Returns the number of sections present (i.e.
sChunkSection * m_Sections[NumSections]
NIBBLETYPE m_BlockLight[SectionBlockCount/2]
void Clear()
Clears all data.
static const int SectionHeight
NIBBLETYPE GetMeta(Vector3i a_RelPos) const