diff --git a/src/chunkmanager.cpp b/src/chunkmanager.cpp index 5250a03..73d7982 100644 --- a/src/chunkmanager.cpp +++ b/src/chunkmanager.cpp @@ -167,9 +167,9 @@ namespace chunkmanager int gen{0}, mesh{0}, unload{0}; if( - distx >= -RENDER_DISTANCE && distx <= RENDER_DISTANCE && - disty >= -RENDER_DISTANCE && disty <= RENDER_DISTANCE && - distz >= -RENDER_DISTANCE && distz <= RENDER_DISTANCE + distx >= -RENDER_DISTANCE && distx < RENDER_DISTANCE && + disty >= -RENDER_DISTANCE && disty < RENDER_DISTANCE && + distz >= -RENDER_DISTANCE && distz < RENDER_DISTANCE ){ // If within distance @@ -189,7 +189,22 @@ namespace chunkmanager // If generated but not yet meshed // TODO: not getting meshed if(!c->getState(Chunk::CHUNK_STATE_MESHED)){ - if(c->isFree()){ + ChunkTable::accessor a1; + if(c->isFree() && + (distx+1 >= RENDER_DISTANCE || x + 1 > 1023 || (chunks.find(a1, Chunk::calculateIndex(x+1, y, z)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (distx-1 < -RENDER_DISTANCE || x - 1 < 0 || (chunks.find(a1, Chunk::calculateIndex(x-1, y, z)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (disty+1 >= RENDER_DISTANCE || y + 1 > 1023 || (chunks.find(a1, Chunk::calculateIndex(x, y+1, z)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (disty-1 < -RENDER_DISTANCE || y - 1 < 0|| (chunks.find(a1, Chunk::calculateIndex(x, y-1, z)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (distz+1 >= RENDER_DISTANCE || z + 1 > 1023 || (chunks.find(a1, Chunk::calculateIndex(x, y, z+1)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) && + (distz-1 < -RENDER_DISTANCE || z - 1 < 0|| (chunks.find(a1, Chunk::calculateIndex(x, y, z-1)) && + a1->second->getState(Chunk::CHUNK_STATE_GENERATED))) + ) + { // Mesh c->setState(Chunk::CHUNK_STATE_IN_MESHING_QUEUE, true); chunks_to_mesh_queue.push(std::make_pair(c, MESHING_PRIORITY_NORMAL)); @@ -344,7 +359,6 @@ namespace chunkmanager } } - /* Block getBlockAtPos(int x, int y, int z){ if(x < 0 || y < 0 || z < 0) return Block::NULLBLK; @@ -356,7 +370,7 @@ namespace chunkmanager //std::cout << "Block at " << x << ", " << y << ", " << z << " is in chunk " << cx << "," << cy << "," << cz << "\n"; ChunkTable::accessor a; - if(!chunks.find(a, calculateIndex(cx, cy, cz))) return Block::NULLBLK; + if(!chunks.find(a, Chunk::calculateIndex(cx, cy, cz))) return Block::NULLBLK; else { int bx = x % CHUNK_SIZE; int by = y % CHUNK_SIZE; @@ -366,5 +380,5 @@ namespace chunkmanager //std::cout << "Block is at " << bx << "," << by << "," << bz << "(" << (int)b << ")\n"; return b; } - }*/ + } }; diff --git a/src/chunkmesher.cpp b/src/chunkmesher.cpp index a296eb0..f00014a 100755 --- a/src/chunkmesher.cpp +++ b/src/chunkmesher.cpp @@ -11,6 +11,8 @@ #include "spacefilling.hpp" #include "utils.hpp" +#define CHUNKMESHER_BORDERS 0 + namespace chunkmesher{ ChunkMeshDataQueue MeshDataQueue; @@ -95,8 +97,7 @@ void mesh(Chunk::Chunk* chunk) Block b1, b2; if(x[dim] >= 0) b1 = blocks[HILBERT_XYZ_ENCODE[x[0]][x[1]][x[2]]]; else{ - b1 = Block::NULLBLK; - /* + // b1 = Block::NULLBLK; int cx = chunk->getPosition().x*CHUNK_SIZE; int cy = chunk->getPosition().y*CHUNK_SIZE; int cz = chunk->getPosition().z*CHUNK_SIZE; @@ -105,14 +106,13 @@ void mesh(Chunk::Chunk* chunk) int by = cy+x[1]; int bz = cz+x[2]; - b1 = chunkmanager::getBlockAtPos(bx, by, bz);*/ + b1 = chunkmanager::getBlockAtPos(bx, by, bz); } if(x[dim] < CHUNK_SIZE - 1) b2 = blocks[HILBERT_XYZ_ENCODE[x[0] + q[0]][x[1] + q[1]][x[2] + q[2]]]; else{ - b2 = Block::NULLBLK; - /* + //b2 = Block::NULLBLK; int cx = chunk->getPosition().x*CHUNK_SIZE; int cy = chunk->getPosition().y*CHUNK_SIZE; int cz = chunk->getPosition().z*CHUNK_SIZE; @@ -121,7 +121,7 @@ void mesh(Chunk::Chunk* chunk) int by = cy+x[1] + q[1]; int bz = cz+x[2] + q[2]; - b2 = chunkmanager::getBlockAtPos(bx, by, bz);*/ + b2 = chunkmanager::getBlockAtPos(bx, by, bz); } // Compute the mask @@ -129,9 +129,15 @@ void mesh(Chunk::Chunk* chunk) // The else case provides face culling for adjacent solid faces // Checking for NULLBLK avoids creating empty faces if nearby chunk was not // yet generated +#if CHUNKMESHER_BORDERS == 1 mask[n++] = b1 == b2 ? Block::NULLBLK : backFace ? b1 == Block::NULLBLK || b1 == Block::AIR ? b2 : Block::NULLBLK : b2 == Block::NULLBLK || b2 == Block::AIR ? b1 : Block::NULLBLK; +#else + mask[n++] = b1 == b2 ? Block::NULLBLK + : backFace ? b1 == Block::AIR ? b2 : Block::NULLBLK + : b2 == Block::AIR ? b1 : Block::NULLBLK; +#endif } }