2014-04-26 13:50:23 -04:00
|
|
|
|
2014-05-29 12:25:08 -04:00
|
|
|
// ChunkData.h
|
|
|
|
|
|
|
|
// Declares the cChunkData class that represents the block's type, meta, blocklight and skylight storage for a chunk
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-26 13:50:23 -04:00
|
|
|
#pragma once
|
|
|
|
|
2014-05-03 09:02:51 -04:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2014-06-16 10:12:50 -04:00
|
|
|
#include "AllocationPool.h"
|
2014-05-03 09:02:51 -04:00
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
|
2014-04-26 13:50:23 -04:00
|
|
|
|
2014-05-21 14:58:48 -04:00
|
|
|
class cChunkData
|
2014-04-26 13:50:23 -04:00
|
|
|
{
|
2017-08-21 12:56:53 -04:00
|
|
|
public:
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2015-07-29 11:04:03 -04:00
|
|
|
static const int SectionHeight = 16;
|
2014-06-16 10:12:50 -04:00
|
|
|
static const size_t NumSections = (cChunkDef::Height / SectionHeight);
|
|
|
|
static const size_t SectionBlockCount = SectionHeight * cChunkDef::Width * cChunkDef::Width;
|
|
|
|
|
2017-08-21 12:56:53 -04:00
|
|
|
struct sChunkSection
|
|
|
|
{
|
|
|
|
BLOCKTYPE m_BlockTypes[SectionBlockCount];
|
|
|
|
NIBBLETYPE m_BlockMetas[SectionBlockCount / 2];
|
|
|
|
NIBBLETYPE m_BlockLight[SectionBlockCount / 2];
|
|
|
|
NIBBLETYPE m_BlockSkyLight[SectionBlockCount / 2];
|
|
|
|
};
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2017-08-21 12:56:53 -04:00
|
|
|
cChunkData(cAllocationPool<sChunkSection> & a_Pool);
|
|
|
|
cChunkData(cChunkData && a_Other);
|
2014-05-24 08:37:25 -04:00
|
|
|
~cChunkData();
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-08-21 12:56:53 -04:00
|
|
|
cChunkData & operator = (cChunkData && a_Other)
|
|
|
|
{
|
|
|
|
Assign(std::move(a_Other));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Copy assign from another cChunkData */
|
|
|
|
void Assign(const cChunkData & a_Other);
|
|
|
|
|
|
|
|
/** Move assign from another cChunkData */
|
|
|
|
void Assign(cChunkData && a_Other);
|
2014-04-26 13:50:23 -04:00
|
|
|
|
2018-02-04 17:15:31 -05:00
|
|
|
BLOCKTYPE GetBlock(Vector3i a_RelPos) const;
|
|
|
|
void SetBlock(Vector3i a_RelPos, BLOCKTYPE a_Block);
|
2014-04-26 13:50:23 -04:00
|
|
|
|
2018-02-04 17:15:31 -05:00
|
|
|
NIBBLETYPE GetMeta(Vector3i a_RelPos) const;
|
|
|
|
bool SetMeta(Vector3i a_RelPos, NIBBLETYPE a_Nibble);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2018-02-04 17:15:31 -05:00
|
|
|
NIBBLETYPE GetBlockLight(Vector3i a_RelPos) const;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2018-02-04 17:15:31 -05:00
|
|
|
NIBBLETYPE GetSkyLight(Vector3i a_RelPos) const;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-08-21 12:56:53 -04:00
|
|
|
/** Return a pointer to the chunk section or nullptr if all air */
|
|
|
|
const sChunkSection * GetSection(size_t a_SectionNum) const;
|
|
|
|
|
|
|
|
/** Returns a bitmask of chunk sections which are currently stored. */
|
|
|
|
UInt16 GetSectionBitmask() const;
|
|
|
|
|
|
|
|
/** Clears all data */
|
|
|
|
void Clear();
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2014-05-29 12:25:08 -04:00
|
|
|
/** Copies the blocktype data into the specified flat array.
|
|
|
|
Optionally, only a part of the data is copied, as specified by the a_Idx and a_Length parameters. */
|
|
|
|
void CopyBlockTypes(BLOCKTYPE * a_Dest, size_t a_Idx = 0, size_t a_Length = cChunkDef::NumBlocks) const;
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2014-05-29 12:25:08 -04:00
|
|
|
/** Copies the metadata into the specified flat array. */
|
|
|
|
void CopyMetas(NIBBLETYPE * a_Dest) const;
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2014-05-29 12:25:08 -04:00
|
|
|
/** Copies the block light data into the specified flat array. */
|
2014-05-28 16:40:19 -04:00
|
|
|
void CopyBlockLight(NIBBLETYPE * a_Dest) const;
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2014-05-29 12:25:08 -04:00
|
|
|
/** Copies the skylight data into the specified flat array. */
|
2014-05-28 16:40:19 -04:00
|
|
|
void CopySkyLight (NIBBLETYPE * a_Dest) const;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-08-20 18:23:23 -04:00
|
|
|
/** Fills the chunk with the specified block. */
|
|
|
|
void FillBlockTypes(BLOCKTYPE a_Value);
|
|
|
|
|
|
|
|
/** Fills the chunk with the specified meta value. */
|
|
|
|
void FillMetas (NIBBLETYPE a_Value);
|
|
|
|
|
|
|
|
/** Fills the chunk with the specified block light. */
|
|
|
|
void FillBlockLight(NIBBLETYPE a_Value);
|
|
|
|
|
|
|
|
/** Fills the chunk with the specified sky light. */
|
|
|
|
void FillSkyLight (NIBBLETYPE a_Value);
|
|
|
|
|
2014-05-29 12:25:08 -04:00
|
|
|
/** Copies the blocktype data from the specified flat array into the internal representation.
|
|
|
|
Allocates sections that are needed for the operation.
|
|
|
|
Requires that a_Src is a valid pointer. */
|
|
|
|
void SetBlockTypes(const BLOCKTYPE * a_Src);
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2014-05-29 12:25:08 -04:00
|
|
|
/** Copies the metadata from the specified flat array into the internal representation.
|
|
|
|
Allocates sectios that are needed for the operation.
|
|
|
|
Requires that a_Src is a valid pointer. */
|
|
|
|
void SetMetas(const NIBBLETYPE * a_Src);
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2014-05-29 12:25:08 -04:00
|
|
|
/** Copies the blocklight data from the specified flat array into the internal representation.
|
|
|
|
Allocates sectios that are needed for the operation.
|
2014-10-20 16:55:07 -04:00
|
|
|
Allows a_Src to be nullptr, in which case it doesn't do anything. */
|
2014-05-29 12:25:08 -04:00
|
|
|
void SetBlockLight(const NIBBLETYPE * a_Src);
|
|
|
|
|
|
|
|
/** Copies the skylight data from the specified flat array into the internal representation.
|
|
|
|
Allocates sectios that are needed for the operation.
|
2014-10-20 16:55:07 -04:00
|
|
|
Allows a_Src to be nullptr, in which case it doesn't do anything. */
|
2014-05-29 12:25:08 -04:00
|
|
|
void SetSkyLight(const NIBBLETYPE * a_Src);
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2017-08-21 12:56:53 -04:00
|
|
|
/** Returns the number of sections present (i.e. non-air). */
|
|
|
|
UInt32 NumPresentSections() const;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-26 13:50:23 -04:00
|
|
|
private:
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2014-05-29 12:25:08 -04:00
|
|
|
sChunkSection * m_Sections[NumSections];
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2017-08-21 12:56:53 -04:00
|
|
|
cAllocationPool<sChunkSection> & m_Pool;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-05-28 16:40:19 -04:00
|
|
|
/** Allocates a new section. Entry-point to custom allocators. */
|
2014-06-16 10:12:50 -04:00
|
|
|
sChunkSection * Allocate(void);
|
|
|
|
|
2014-05-28 16:40:19 -04:00
|
|
|
/** Frees the specified section, previously allocated using Allocate().
|
2014-10-20 16:55:07 -04:00
|
|
|
Note that a_Section may be nullptr. */
|
2014-06-16 10:12:50 -04:00
|
|
|
void Free(sChunkSection * a_Section);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-05-28 16:40:19 -04:00
|
|
|
/** Sets the data in the specified section to their default values. */
|
|
|
|
void ZeroSection(sChunkSection * a_Section) const;
|
2014-06-16 10:12:50 -04:00
|
|
|
|
2014-04-26 13:50:23 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|