diff --git a/src/nyqubel-client/client.cpp b/src/nyqubel-client/client.cpp index e7e656e00..bbcf031a7 100644 --- a/src/nyqubel-client/client.cpp +++ b/src/nyqubel-client/client.cpp @@ -568,6 +568,12 @@ public: 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 { kPlain, kNieve, @@ -593,6 +599,10 @@ public: }; static constexpr bool gfx_mesher_debuglog = false; std::vector 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 finished_quads; if (gfx_mesher_debuglog) 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 if (gfx_mesher_debuglog) 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 FindOpenSpace = [&]() -> std::optional { for (std::size_t x = 0; x < cChunkDef::Width; x++) { @@ -642,6 +653,7 @@ public: } return std::optional(); }; + while (!chunk_finished_checksum.all()) { const auto unmeshed_face = FindOpenSpace(); if (!unmeshed_face.has_value()) @@ -760,9 +772,9 @@ public: return finished_quads; } static bool IsPosValidWithinChunk(ChunkVecType block_coords) { - if (block_coords.x >= cChunkDef::Width) + if (!cChunkDef::IsValidWidth(block_coords.x)) return false; - if (block_coords.y >= cChunkDef::Width) + if (!cChunkDef::IsValidWidth(block_coords.y)) return false; return true; } @@ -851,6 +863,8 @@ public: virtual void Update() override { this->CBaseWidget::Update(); if (current_render_quads.empty()) { + if (world_slice->IsEmpty()) + return; current_render_quads = world_slice->MeshChunk(FalseChunk::MesherComplexity(settings->dropdown->Value())); if (FalseChunk::gfx_mesher_debuglog) {