Improved client checking for blocks before trying to mesh nothing. also more cChunkDef inclusions.

This commit is contained in:
Rebekah 2024-02-15 07:46:09 -05:00
parent 85c6edf829
commit 639e867fd4
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5

View File

@ -568,6 +568,12 @@ public:
return std::make_pair(mask, reverse_mask); return std::make_pair(mask, reverse_mask);
} }
}; };
bool IsEmpty() const {
for (auto i : this->raw_chunk_data)
if (i != ENUM_BLOCK_TYPE::E_BLOCK_AIR)
return false;
return true;
}
enum MesherComplexity { enum MesherComplexity {
kPlain, kPlain,
kNieve, kNieve,
@ -593,6 +599,10 @@ public:
}; };
static constexpr bool gfx_mesher_debuglog = false; static constexpr bool gfx_mesher_debuglog = false;
std::vector<ChunkMeshedQuad> MeshChunk(MesherComplexity cmplxity) const { std::vector<ChunkMeshedQuad> MeshChunk(MesherComplexity cmplxity) const {
bool is_chunk_only_air = this->IsEmpty();
if (is_chunk_only_air)
return {}; // Your fault you didnt check it first...
std::vector<ChunkMeshedQuad> finished_quads; std::vector<ChunkMeshedQuad> finished_quads;
if (gfx_mesher_debuglog) if (gfx_mesher_debuglog)
std::cout << "Start Meshing: "; std::cout << "Start Meshing: ";
@ -630,7 +640,8 @@ 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
if (gfx_mesher_debuglog) if (gfx_mesher_debuglog)
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; // i believe its faster(vs an array) when checking the entire thing for boolean
const auto IsBlockMarkedOff = [&](std::size_t blockidx) -> bool { return chunk_finished_checksum[blockidx]; }; const auto IsBlockMarkedOff = [&](std::size_t blockidx) -> bool { return chunk_finished_checksum[blockidx]; };
const auto FindOpenSpace = [&]() -> std::optional<std::size_t> { 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++) {
@ -642,6 +653,7 @@ public:
} }
return std::optional<std::size_t>(); 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.has_value()) if (!unmeshed_face.has_value())
@ -760,9 +772,9 @@ public:
return finished_quads; return finished_quads;
} }
static bool IsPosValidWithinChunk(ChunkVecType block_coords) { static bool IsPosValidWithinChunk(ChunkVecType block_coords) {
if (block_coords.x >= cChunkDef::Width) if (!cChunkDef::IsValidWidth(block_coords.x))
return false; return false;
if (block_coords.y >= cChunkDef::Width) if (!cChunkDef::IsValidWidth(block_coords.y))
return false; return false;
return true; return true;
} }
@ -851,6 +863,8 @@ public:
virtual void Update() override { virtual void Update() override {
this->CBaseWidget::Update(); this->CBaseWidget::Update();
if (current_render_quads.empty()) { if (current_render_quads.empty()) {
if (world_slice->IsEmpty())
return;
current_render_quads = world_slice->MeshChunk(FalseChunk::MesherComplexity(settings->dropdown->Value())); current_render_quads = world_slice->MeshChunk(FalseChunk::MesherComplexity(settings->dropdown->Value()));
if (FalseChunk::gfx_mesher_debuglog) { if (FalseChunk::gfx_mesher_debuglog) {