2014-05-10 11:15:45 -04:00
|
|
|
|
2014-05-27 07:44:56 -04:00
|
|
|
#include "Globals.h"
|
2019-08-26 15:38:34 -04:00
|
|
|
#include "../TestHelpers.h"
|
2014-05-21 14:58:48 -04:00
|
|
|
#include "ChunkData.h"
|
2014-05-10 11:15:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-26 15:38:34 -04:00
|
|
|
|
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
/** Helper that copies a data store into a contiguous flat array, filling in a default value for sections that aren't present. */
|
|
|
|
template <class StoreType, typename GetType, typename DefaultType, typename OutType>
|
|
|
|
static void CopyAll(const StoreType & Data, GetType Getter, DefaultType Default, OutType & Out)
|
2014-05-10 11:15:45 -04:00
|
|
|
{
|
2021-03-05 08:03:55 -05:00
|
|
|
constexpr auto SectionCount = std::extent_v<OutType> / 16;
|
2016-06-16 11:34:17 -04:00
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
for (size_t Y = 0; Y != 16; Y++)
|
2018-02-04 17:15:31 -05:00
|
|
|
{
|
2021-03-05 08:03:55 -05:00
|
|
|
const auto Section = (Data.*Getter)(Y);
|
|
|
|
static_assert(SectionCount == std::tuple_size<std::remove_pointer_t<decltype(Section)>>::value, "Output array has wrong size");
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
if (Section == nullptr)
|
2014-06-16 10:12:50 -04:00
|
|
|
{
|
2021-03-05 08:03:55 -05:00
|
|
|
std::fill_n(Out + Y * SectionCount, SectionCount, Default);
|
2014-06-16 10:12:50 -04:00
|
|
|
}
|
2021-03-05 08:03:55 -05:00
|
|
|
else
|
2018-07-23 14:12:51 -04:00
|
|
|
{
|
2021-03-05 08:03:55 -05:00
|
|
|
std::copy(Section->begin(), Section->end(), Out + Y * SectionCount);
|
2018-07-23 14:12:51 -04:00
|
|
|
}
|
2021-03-05 08:03:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Performs the entire Copies test. */
|
|
|
|
static void Test()
|
|
|
|
{
|
|
|
|
LOGD("Test started");
|
|
|
|
|
2014-05-11 14:40:32 -04:00
|
|
|
{
|
2021-03-05 08:03:55 -05:00
|
|
|
ChunkBlockData buffer;
|
2018-02-04 17:15:31 -05:00
|
|
|
|
|
|
|
buffer.SetBlock({ 3, 1, 4 }, 0xDE);
|
|
|
|
buffer.SetMeta({ 3, 1, 4 }, 0xA);
|
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
ChunkBlockData copy;
|
2017-08-21 12:56:53 -04:00
|
|
|
copy.Assign(buffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(copy.GetBlock({ 3, 1, 4 }), 0xDE);
|
|
|
|
TEST_EQUAL(copy.GetMeta({ 3, 1, 4 }), 0xA);
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
|
2021-03-05 08:03:55 -05:00
|
|
|
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]{};
|
2014-05-11 14:40:32 -04:00
|
|
|
for (int i = 0; i < 16 * 16 * 256; i += 4)
|
|
|
|
{
|
2014-05-29 14:18:37 -04:00
|
|
|
SrcBlockBuffer[i + 0] = 0xde;
|
|
|
|
SrcBlockBuffer[i + 1] = 0xad;
|
|
|
|
SrcBlockBuffer[i + 2] = 0xbe;
|
|
|
|
SrcBlockBuffer[i + 3] = 0xef;
|
2014-05-11 14:40:32 -04:00
|
|
|
}
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
|
2014-05-24 08:33:40 -04:00
|
|
|
BLOCKTYPE DstBlockBuffer[16 * 16 * 256];
|
2021-03-05 08:03:55 -05:00
|
|
|
CopyAll(buffer, &ChunkBlockData::GetSection, ChunkBlockData::DefaultValue, DstBlockBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1), 0);
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-17 08:39:28 -04:00
|
|
|
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
|
2021-03-05 08:03:55 -05:00
|
|
|
buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
|
|
|
|
CopyAll(buffer, &ChunkBlockData::GetSection, ChunkBlockData::DefaultValue, DstBlockBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1), 0);
|
2014-05-17 08:39:28 -04:00
|
|
|
}
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-17 08:39:28 -04:00
|
|
|
{
|
2021-03-05 08:03:55 -05:00
|
|
|
ChunkBlockData buffer;
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]{};
|
2014-05-24 08:33:40 -04:00
|
|
|
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
|
2014-05-11 14:40:32 -04:00
|
|
|
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
|
|
|
|
{
|
2014-05-29 14:18:37 -04:00
|
|
|
SrcNibbleBuffer[i + 0] = 0xde;
|
|
|
|
SrcNibbleBuffer[i + 1] = 0xad;
|
|
|
|
SrcNibbleBuffer[i + 2] = 0xbe;
|
|
|
|
SrcNibbleBuffer[i + 3] = 0xef;
|
2014-05-11 14:40:32 -04:00
|
|
|
}
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
|
2014-05-24 08:33:40 -04:00
|
|
|
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256/ 2];
|
2021-03-05 08:03:55 -05:00
|
|
|
CopyAll(buffer, &ChunkBlockData::GetMetaSection, ChunkBlockData::DefaultMetaValue, DstNibbleBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-17 08:39:28 -04:00
|
|
|
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
|
2021-03-05 08:03:55 -05:00
|
|
|
buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
|
|
|
|
CopyAll(buffer, &ChunkBlockData::GetMetaSection, ChunkBlockData::DefaultMetaValue, DstNibbleBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
|
2014-05-17 08:39:28 -04:00
|
|
|
}
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-17 08:39:28 -04:00
|
|
|
{
|
2021-03-05 08:03:55 -05:00
|
|
|
ChunkLightData buffer;
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
|
2014-05-11 14:40:32 -04:00
|
|
|
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
|
|
|
|
{
|
2014-05-29 14:18:37 -04:00
|
|
|
SrcNibbleBuffer[i + 0] = 0xde;
|
|
|
|
SrcNibbleBuffer[i + 1] = 0xad;
|
|
|
|
SrcNibbleBuffer[i + 2] = 0xbe;
|
|
|
|
SrcNibbleBuffer[i + 3] = 0xef;
|
2014-05-11 14:40:32 -04:00
|
|
|
}
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
|
2014-05-24 08:33:40 -04:00
|
|
|
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256 / 2];
|
2021-03-05 08:03:55 -05:00
|
|
|
CopyAll(buffer, &ChunkLightData::GetBlockLightSection, ChunkLightData::DefaultBlockLightValue, DstNibbleBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1), 0);
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-17 08:39:28 -04:00
|
|
|
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
|
2021-03-05 08:03:55 -05:00
|
|
|
buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
|
|
|
|
CopyAll(buffer, &ChunkLightData::GetBlockLightSection, ChunkLightData::DefaultBlockLightValue, DstNibbleBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1), 0);
|
2014-05-17 08:39:28 -04:00
|
|
|
}
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-17 08:39:28 -04:00
|
|
|
{
|
2021-03-05 08:03:55 -05:00
|
|
|
ChunkLightData buffer;
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
|
2014-05-11 14:40:32 -04:00
|
|
|
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
|
|
|
|
{
|
2014-05-29 14:18:37 -04:00
|
|
|
SrcNibbleBuffer[i + 0] = 0xde;
|
|
|
|
SrcNibbleBuffer[i + 1] = 0xad;
|
|
|
|
SrcNibbleBuffer[i + 2] = 0xbe;
|
|
|
|
SrcNibbleBuffer[i + 3] = 0xef;
|
2014-05-11 14:40:32 -04:00
|
|
|
}
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
|
2014-05-24 08:33:40 -04:00
|
|
|
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256/ 2];
|
2021-03-05 08:03:55 -05:00
|
|
|
CopyAll(buffer, &ChunkLightData::GetSkyLightSection, ChunkLightData::DefaultSkyLightValue, DstNibbleBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 / 2);
|
2021-03-05 08:03:55 -05:00
|
|
|
buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
|
|
|
|
CopyAll(buffer, &ChunkLightData::GetSkyLightSection, ChunkLightData::DefaultSkyLightValue, DstNibbleBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
|
2014-05-11 10:57:56 -04:00
|
|
|
}
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-11 14:40:32 -04:00
|
|
|
{
|
2021-03-05 08:03:55 -05:00
|
|
|
ChunkBlockData buffer;
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
|
2014-05-11 14:40:32 -04:00
|
|
|
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
|
2014-05-24 08:33:40 -04:00
|
|
|
BLOCKTYPE DstBlockBuffer[16 * 16 * 256];
|
2021-03-05 08:03:55 -05:00
|
|
|
CopyAll(buffer, &ChunkBlockData::GetSection, ChunkBlockData::DefaultValue, DstBlockBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1), 0);
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
|
|
|
|
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
|
|
|
|
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256 / 2];
|
2021-03-05 08:03:55 -05:00
|
|
|
CopyAll(buffer, &ChunkBlockData::GetMetaSection, ChunkBlockData::DefaultMetaValue, DstNibbleBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
|
2021-03-05 08:03:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ChunkLightData buffer;
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
|
2014-05-24 08:33:40 -04:00
|
|
|
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
|
2021-03-05 08:03:55 -05:00
|
|
|
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256 / 2];
|
|
|
|
CopyAll(buffer, &ChunkLightData::GetBlockLightSection, ChunkLightData::DefaultBlockLightValue, DstNibbleBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
|
2018-02-04 17:15:31 -05:00
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 / 2);
|
2021-03-05 08:03:55 -05:00
|
|
|
CopyAll(buffer, &ChunkLightData::GetSkyLightSection, ChunkLightData::DefaultSkyLightValue, DstNibbleBuffer);
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
|
2014-05-11 14:40:32 -04:00
|
|
|
}
|
2014-05-10 11:15:45 -04:00
|
|
|
}
|
2019-08-26 15:38:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_TEST_MAIN("ChunkData Copies",
|
2021-03-05 08:03:55 -05:00
|
|
|
Test()
|
2019-08-26 15:38:34 -04:00
|
|
|
)
|