1
0
Fork 0
Tiger Wang 2021-03-06 12:59:39 +00:00 committed by GitHub
parent 00e6239b20
commit d9a2b8611c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 36 deletions

View File

@ -130,33 +130,24 @@ public:
namespace ChunkDef
{
using cForEachSectionCallback = cFunctionRef<void(
size_t,
ChunkBlockData::BlockArray *,
ChunkBlockData::MetaArray *,
ChunkLightData::LightArray *,
ChunkLightData::LightArray *)>;
/** Invokes the callback functor for every chunk section containing at least one present block or light section data.
This is used to collect all data for all sections. */
inline void ForEachSection(const ChunkBlockData & a_BlockData, const ChunkLightData & a_LightData, cForEachSectionCallback a_Callback)
{
for (size_t Y = 0; Y < cChunkDef::NumSections; ++Y)
{
const auto Blocks = a_BlockData.GetSection(Y);
const auto Metas = a_BlockData.GetMetaSection(Y);
const auto BlockLights = a_LightData.GetBlockLightSection(Y);
const auto SkyLights = a_LightData.GetSkyLightSection(Y);
if ((Blocks != nullptr) || (Metas != nullptr) || (BlockLights != nullptr) || (SkyLights != nullptr))
{
a_Callback(Y, Blocks, Metas, BlockLights, SkyLights);
}
}
}
}
/** Invokes the callback functor for every chunk section containing at least one present block or light section data.
This is used to collect all data for all sections.
In macro form to work around a Visual Studio 2017 ICE bug. */
#define ChunkDef_ForEachSection(BlockData, LightData, Callback) \
do \
{ \
for (size_t Y = 0; Y < cChunkDef::NumSections; ++Y) \
{ \
const auto Blocks = BlockData.GetSection(Y); \
const auto Metas = BlockData.GetMetaSection(Y); \
const auto BlockLights = LightData.GetBlockLightSection(Y); \
const auto SkyLights = LightData.GetSkyLightSection(Y); \
if ((Blocks != nullptr) || (Metas != nullptr) || (BlockLights != nullptr) || (SkyLights != nullptr)) \
{ \
Callback \
} \
} \
} while (false)

View File

@ -21,7 +21,7 @@ namespace
size_t Present = 0;
UInt16 Mask = 0;
ChunkDef::ForEachSection(a_BlockData, a_LightData, [&Present, &Mask](const auto Y, auto, auto, auto, auto)
ChunkDef_ForEachSection(a_BlockData, a_LightData,
{
Present++;
Mask |= (1 << Y);
@ -206,7 +206,7 @@ inline void cChunkDataSerializer::Serialize47(const int a_ChunkX, const int a_Ch
// each array stores all present sections of the same kind packed together
// Write the block types to the packet:
ChunkDef::ForEachSection(a_BlockData, a_LightData, [this](auto, const auto Blocks, const auto Metas, auto, auto)
ChunkDef_ForEachSection(a_BlockData, a_LightData,
{
const bool BlocksExist = Blocks != nullptr;
const bool MetasExist = Metas != nullptr;
@ -221,7 +221,7 @@ inline void cChunkDataSerializer::Serialize47(const int a_ChunkX, const int a_Ch
});
// Write the block lights:
ChunkDef::ForEachSection(a_BlockData, a_LightData, [this](auto, auto, auto, const auto BlockLights, auto)
ChunkDef_ForEachSection(a_BlockData, a_LightData,
{
if (BlockLights == nullptr)
{
@ -234,7 +234,7 @@ inline void cChunkDataSerializer::Serialize47(const int a_ChunkX, const int a_Ch
});
// Write the sky lights:
ChunkDef::ForEachSection(a_BlockData, a_LightData, [this](auto, auto, auto, auto, const auto SkyLights)
ChunkDef_ForEachSection(a_BlockData, a_LightData,
{
if (SkyLights == nullptr)
{
@ -295,7 +295,7 @@ inline void cChunkDataSerializer::Serialize107(const int a_ChunkX, const int a_C
m_Packet.WriteVarInt32(static_cast<UInt32>(ChunkSize));
// Write each chunk section...
ChunkDef::ForEachSection(a_BlockData, a_LightData, [this](auto, const auto Blocks, const auto Metas, const auto BlockLights, const auto SkyLights)
ChunkDef_ForEachSection(a_BlockData, a_LightData,
{
m_Packet.WriteBEUInt8(BitsPerEntry);
m_Packet.WriteVarInt32(0); // Palette length is 0
@ -353,7 +353,7 @@ inline void cChunkDataSerializer::Serialize110(const int a_ChunkX, const int a_C
m_Packet.WriteVarInt32(static_cast<UInt32>(ChunkSize));
// Write each chunk section...
ChunkDef::ForEachSection(a_BlockData, a_LightData, [this](auto, const auto Blocks, const auto Metas, const auto BlockLights, const auto SkyLights)
ChunkDef_ForEachSection(a_BlockData, a_LightData,
{
m_Packet.WriteBEUInt8(BitsPerEntry);
m_Packet.WriteVarInt32(0); // Palette length is 0
@ -414,7 +414,7 @@ inline void cChunkDataSerializer::Serialize393(const int a_ChunkX, const int a_C
m_Packet.WriteVarInt32(static_cast<UInt32>(ChunkSize));
// Write each chunk section...
ChunkDef::ForEachSection(a_BlockData, a_LightData, [this](auto, const auto Blocks, const auto Metas, const auto BlockLights, const auto SkyLights)
ChunkDef_ForEachSection(a_BlockData, a_LightData,
{
m_Packet.WriteBEUInt8(BitsPerEntry);
m_Packet.WriteVarInt32(static_cast<UInt32>(ChunkSectionDataArraySize));
@ -479,7 +479,7 @@ inline void cChunkDataSerializer::Serialize477(const int a_ChunkX, const int a_C
m_Packet.WriteVarInt32(static_cast<UInt32>(ChunkSize));
// Write each chunk section...
ChunkDef::ForEachSection(a_BlockData, a_LightData, [this](auto, const auto Blocks, const auto Metas, auto, auto)
ChunkDef_ForEachSection(a_BlockData, a_LightData,
{
m_Packet.WriteBEInt16(-1);
m_Packet.WriteBEUInt8(BitsPerEntry);

View File

@ -1182,7 +1182,7 @@ void NBTChunkSerializer::Serialize(const cWorld & aWorld, cChunkCoords aCoords,
// Save blockdata:
aWriter.BeginList("Sections", TAG_Compound);
ChunkDef::ForEachSection(serializer.m_BlockData, serializer.m_LightData, [&aWriter](const auto Y, const auto Blocks, const auto Metas, const auto BlockLights, const auto SkyLights)
ChunkDef_ForEachSection(serializer.m_BlockData, serializer.m_LightData,
{
aWriter.BeginCompound("");