22 inline SectionIndices IndicesFromRelPos(
const Vector3i a_RelPos)
33 bool IsCompressed(
const size_t ElementCount)
38 template <
size_t ElementCount,
typename ValueType>
39 ValueType UnpackDefaultValue(
const ValueType DefaultValue)
41 if (IsCompressed(ElementCount))
43 return DefaultValue & 0xF;
54 template<
class ElementType,
size_t ElementCount, ElementType DefaultValue>
61 if (
const auto & Other = a_Other.
Store[Y]; Other !=
nullptr)
63 Store[Y] = std::make_unique<Type>(*Other);
72 template<
class ElementType,
size_t ElementCount, ElementType DefaultValue>
75 const auto Indices = IndicesFromRelPos(a_Position);
76 const auto & Section = Store[Indices.Section];
78 if (Section !=
nullptr)
80 if (IsCompressed(ElementCount))
86 return (*Section)[Indices.Index];
90 return UnpackDefaultValue<ElementCount>(DefaultValue);
97 template<
class ElementType,
size_t ElementCount, ElementType DefaultValue>
100 return Store[a_Y].get();
107 template<
class ElementType,
size_t ElementCount, ElementType DefaultValue>
110 const auto Indices = IndicesFromRelPos(a_Position);
111 auto & Section = Store[Indices.Section];
113 if (Section ==
nullptr)
115 if (a_Value == UnpackDefaultValue<ElementCount>(DefaultValue))
120 Section = cpp20::make_unique_for_overwrite<Type>();
121 std::fill(Section->begin(), Section->end(), DefaultValue);
124 if (IsCompressed(ElementCount))
130 (*Section)[Indices.Index] = a_Value;
138 template<
class ElementType,
size_t ElementCount, ElementType DefaultValue>
141 auto & Section = Store[a_Y];
142 const auto SourceEnd = std::end(a_Source);
144 if (Section !=
nullptr)
146 std::copy(a_Source, SourceEnd, Section->begin());
148 else if (std::any_of(a_Source, SourceEnd, [](
const auto Value) {
return Value != DefaultValue; }))
150 Section = cpp20::make_unique_for_overwrite<Type>();
151 std::copy(a_Source, SourceEnd, Section->begin());
159 template<
class ElementType,
size_t ElementCount, ElementType DefaultValue>
164 SetSection(*
reinterpret_cast<const ElementType (*)[ElementCount]
>(a_Source + Y * ElementCount), Y);
std::array< ElementType, ElementCount > Type
void SetSection(const ElementType(&a_Source)[ElementCount], size_t a_Y)
Copies the data from the specified flat section array into the internal representation.
Type * GetSection(size_t a_Y) const
Returns a raw pointer to the internal representation of the specified section.
ElementType Get(Vector3i a_Position) const
Gets one value at the given position.
void Assign(const ChunkDataStore< ElementType, ElementCount, DefaultValue > &a_Other)
Copy assign from another ChunkDataStore.
void SetAll(const ElementType(&a_Source)[cChunkDef::NumSections *ElementCount])
Copies the data from the specified flat array into the internal representation.
std::unique_ptr< Type > Store[cChunkDef::NumSections]
Contains all the sections this ChunkDataStore manages.
void Set(Vector3i a_Position, ElementType a_Value)
Sets one value at the given position.
void SetAll(const cChunkDef::BlockTypes &a_BlockSource, const cChunkDef::BlockNibbles &a_MetaSource)
static constexpr size_t SectionBlockCount
NIBBLETYPE[SectionMetaCount] SectionMetaType
void Assign(const ChunkBlockData &a_Other)
void SetSection(const SectionType &a_BlockSource, const SectionMetaType &a_MetaSource, size_t a_Y)
BLOCKTYPE[SectionBlockCount] SectionType
ChunkDataStore< NIBBLETYPE, SectionMetaCount, DefaultMetaValue > m_Metas
ChunkDataStore< BLOCKTYPE, SectionBlockCount, DefaultValue > m_Blocks
void SetAll(const cChunkDef::BlockNibbles &a_BlockLightSource, const cChunkDef::BlockNibbles &a_SkyLightSource)
NIBBLETYPE[SectionLightCount] SectionType
ChunkDataStore< NIBBLETYPE, SectionLightCount, DefaultBlockLightValue > m_BlockLights
void SetSection(const SectionType &a_BlockLightSource, const SectionType &a_SkyLightSource, size_t a_Y)
ChunkDataStore< NIBBLETYPE, SectionLightCount, DefaultSkyLightValue > m_SkyLights
void Assign(const ChunkLightData &a_Other)
BLOCKTYPE BlockTypes[NumBlocks]
The type used for block type operations and storage, AXIS_ORDER ordering.
static bool IsValidRelPos(Vector3i a_RelPos)
Validates a chunk relative coordinate.
static void PackNibble(NIBBLETYPE *const a_Buffer, const size_t a_Index, const NIBBLETYPE a_Nibble)
static size_t MakeIndex(int x, int y, int z)
static NIBBLETYPE ExpandNibble(const NIBBLETYPE *const a_Buffer, const size_t a_Index)
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
static const size_t NumSections
static const int SectionHeight