From 3d0d8b75931351bedecbd5ff7a77450f6e7c0560 Mon Sep 17 00:00:00 2001 From: EmaMaker Date: Fri, 4 Aug 2023 13:01:39 +0200 Subject: [PATCH] chunkmgr: chunk can be meshed if all neighbors are generated (Restores seemless chunk borders) --- src/chunkmanager.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/chunkmanager.cpp b/src/chunkmanager.cpp index 01f08dc..7ca8c28 100644 --- a/src/chunkmanager.cpp +++ b/src/chunkmanager.cpp @@ -126,13 +126,27 @@ namespace chunkmanager if(x > 1023 || y > 1023 || z > 1023) continue; - ChunkTable::accessor a; + ChunkTable::accessor a, a1, a2, b1, b2, c1, c2; if(!chunks.find(a, index)) chunks.emplace(a, std::make_pair(index, new Chunk::Chunk(glm::vec3(x,y,z)))); if(! (a->second->getState(Chunk::CHUNK_STATE_GENERATED))) { chunks_to_generate_queue.push(std::make_pair(a->second, GENERATION_PRIORITY_NORMAL)); }else if(! (a->second->getState(Chunk::CHUNK_STATE_MESHED))){ - chunks_to_mesh_queue.push(std::make_pair(a->second, MESHING_PRIORITY_NORMAL)); + if( + (x + 1 > 1023 || (chunks.find(a1, calculateIndex(x+1, y, z)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (x - 1 < 0|| (chunks.find(a1, calculateIndex(x-1, y, z)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (y + 1 > 1023 || (chunks.find(a1, calculateIndex(x, y+1, z)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (y - 1 < 0|| (chunks.find(a1, calculateIndex(x, y-1, z)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (z + 1 > 1023 || (chunks.find(a1, calculateIndex(x, y, z+1)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (z - 1 < 0|| (chunks.find(a1, calculateIndex(x, y, z-1)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) + ) + chunks_to_mesh_queue.push(std::make_pair(a->second, MESHING_PRIORITY_NORMAL)); } a.release();