Added some further asserts to the greedymesher
I want it to remain functional throughout the transition.
This commit is contained in:
parent
0b817aabb7
commit
df26c64e64
@ -645,23 +645,24 @@ public:
|
|||||||
case MesherComplexity::kGreedy: { // https://www.youtube.com/watch?v=4xs66m1Of4A - Greedy Meshing Voxels Fast - Optimism in Design Handmade Seattle 2022
|
case MesherComplexity::kGreedy: { // https://www.youtube.com/watch?v=4xs66m1Of4A - Greedy Meshing Voxels Fast - Optimism in Design Handmade Seattle 2022
|
||||||
std::cout << "Greedy" << std::endl;
|
std::cout << "Greedy" << std::endl;
|
||||||
std::bitset<_chunk_array_size> chunk_finished_checksum;
|
std::bitset<_chunk_array_size> chunk_finished_checksum;
|
||||||
const auto FindOpenSpace = [&]() -> std::pair<std::size_t, std::optional<decltype(chunk_finished_checksum)::reference>> {
|
const auto IsBlockMarkedOff = [&](std::size_t vox) -> bool { return chunk_finished_checksum[vox]; };
|
||||||
|
const auto FindOpenSpace = [&]() -> std::optional<std::size_t> {
|
||||||
for (std::size_t x = 0; x < cChunkDef::Width; x++) {
|
for (std::size_t x = 0; x < cChunkDef::Width; x++) {
|
||||||
for (std::size_t y = 0; y < cChunkDef::Width; y++) {
|
for (std::size_t y = 0; y < cChunkDef::Width; y++) {
|
||||||
auto vox = this->GetVoxelFromPosInChunk({ x, y });
|
auto vox = this->GetVoxelFromPosInChunk({ x, y });
|
||||||
if (!chunk_finished_checksum[vox.pos])
|
if (!IsBlockMarkedOff(vox.pos))
|
||||||
return { vox.pos, chunk_finished_checksum[vox.pos] };
|
return vox.pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { std::size_t(-1), {} };
|
return std::optional<std::size_t>();
|
||||||
};
|
};
|
||||||
while (!chunk_finished_checksum.all()) {
|
while (!chunk_finished_checksum.all()) {
|
||||||
const auto unmeshed_face = FindOpenSpace();
|
const auto unmeshed_face = FindOpenSpace();
|
||||||
if (!unmeshed_face.second.has_value())
|
if (!unmeshed_face.has_value())
|
||||||
throw std::logic_error("Greedy ChunkMesher checksum thinks there is a unmeshed chunk but unable to find it!");
|
throw std::logic_error("Greedy ChunkMesher checksum thinks there is a unmeshed chunk but unable to find it!");
|
||||||
|
|
||||||
LocalVoxel cube;
|
LocalVoxel cube;
|
||||||
cube.pos = unmeshed_face.first;
|
cube.pos = unmeshed_face.value();
|
||||||
const auto type = this->GetVoxelType(cube);
|
const auto type = this->GetVoxelType(cube);
|
||||||
if (type == ENUM_BLOCK_TYPE::E_BLOCK_AIR) {
|
if (type == ENUM_BLOCK_TYPE::E_BLOCK_AIR) {
|
||||||
chunk_finished_checksum[cube.pos] = true;
|
chunk_finished_checksum[cube.pos] = true;
|
||||||
@ -685,7 +686,7 @@ public:
|
|||||||
auto below_block_type = this->GetVoxelType(block_to_check);
|
auto below_block_type = this->GetVoxelType(block_to_check);
|
||||||
if (below_block_type != type)
|
if (below_block_type != type)
|
||||||
break;
|
break;
|
||||||
if (chunk_finished_checksum[block_to_check.pos])
|
if (IsBlockMarkedOff(block_to_check.pos))
|
||||||
break;
|
break;
|
||||||
alike_counter++;
|
alike_counter++;
|
||||||
if (alike_counter >= max_size)
|
if (alike_counter >= max_size)
|
||||||
@ -712,6 +713,7 @@ public:
|
|||||||
auto below_block_type = this->GetVoxelType(side_block_to_check);
|
auto below_block_type = this->GetVoxelType(side_block_to_check);
|
||||||
if (below_block_type != type)
|
if (below_block_type != type)
|
||||||
break;
|
break;
|
||||||
|
assert(!IsBlockMarkedOff(side_block_to_check.pos));
|
||||||
|
|
||||||
// here we go again, dip down to this max length
|
// here we go again, dip down to this max length
|
||||||
auto additional_same_blocks_south_count = SearchLineSouthForSameTypes(side_axis_crawl.cur, same_blocks_south_count);
|
auto additional_same_blocks_south_count = SearchLineSouthForSameTypes(side_axis_crawl.cur, same_blocks_south_count);
|
||||||
@ -744,7 +746,9 @@ public:
|
|||||||
for (std::size_t y = 0; y < size.y; y++) {
|
for (std::size_t y = 0; y < size.y; y++) {
|
||||||
auto block_to_clear = origin + ChunkVecType(x, y);
|
auto block_to_clear = origin + ChunkVecType(x, y);
|
||||||
std::cout << " ------Marking Block Finished: {" << (int)block_to_clear.x << ", " << (int)block_to_clear.y << "}" << std::endl;
|
std::cout << " ------Marking Block Finished: {" << (int)block_to_clear.x << ", " << (int)block_to_clear.y << "}" << std::endl;
|
||||||
chunk_finished_checksum[this->GetVoxelFromPosInChunk(block_to_clear).pos] = true;
|
auto voxel_pos = this->GetVoxelFromPosInChunk(block_to_clear);
|
||||||
|
assert(!IsBlockMarkedOff(voxel_pos.pos));
|
||||||
|
chunk_finished_checksum[voxel_pos.pos] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user