restore seamless chunk borders
parent
df933bebdd
commit
e593696af3
|
@ -167,9 +167,9 @@ namespace chunkmanager
|
||||||
int gen{0}, mesh{0}, unload{0};
|
int gen{0}, mesh{0}, unload{0};
|
||||||
|
|
||||||
if(
|
if(
|
||||||
distx >= -RENDER_DISTANCE && distx <= RENDER_DISTANCE &&
|
distx >= -RENDER_DISTANCE && distx < RENDER_DISTANCE &&
|
||||||
disty >= -RENDER_DISTANCE && disty <= RENDER_DISTANCE &&
|
disty >= -RENDER_DISTANCE && disty < RENDER_DISTANCE &&
|
||||||
distz >= -RENDER_DISTANCE && distz <= RENDER_DISTANCE
|
distz >= -RENDER_DISTANCE && distz < RENDER_DISTANCE
|
||||||
){
|
){
|
||||||
|
|
||||||
// If within distance
|
// If within distance
|
||||||
|
@ -189,7 +189,22 @@ namespace chunkmanager
|
||||||
// If generated but not yet meshed
|
// If generated but not yet meshed
|
||||||
// TODO: not getting meshed
|
// TODO: not getting meshed
|
||||||
if(!c->getState(Chunk::CHUNK_STATE_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
|
// Mesh
|
||||||
c->setState(Chunk::CHUNK_STATE_IN_MESHING_QUEUE, true);
|
c->setState(Chunk::CHUNK_STATE_IN_MESHING_QUEUE, true);
|
||||||
chunks_to_mesh_queue.push(std::make_pair(c, MESHING_PRIORITY_NORMAL));
|
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){
|
Block getBlockAtPos(int x, int y, int z){
|
||||||
if(x < 0 || y < 0 || z < 0) return Block::NULLBLK;
|
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";
|
//std::cout << "Block at " << x << ", " << y << ", " << z << " is in chunk " << cx << "," << cy << "," << cz << "\n";
|
||||||
ChunkTable::accessor a;
|
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 {
|
else {
|
||||||
int bx = x % CHUNK_SIZE;
|
int bx = x % CHUNK_SIZE;
|
||||||
int by = y % CHUNK_SIZE;
|
int by = y % CHUNK_SIZE;
|
||||||
|
@ -366,5 +380,5 @@ namespace chunkmanager
|
||||||
//std::cout << "Block is at " << bx << "," << by << "," << bz << "(" << (int)b << ")\n";
|
//std::cout << "Block is at " << bx << "," << by << "," << bz << "(" << (int)b << ")\n";
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "spacefilling.hpp"
|
#include "spacefilling.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
|
#define CHUNKMESHER_BORDERS 0
|
||||||
|
|
||||||
namespace chunkmesher{
|
namespace chunkmesher{
|
||||||
|
|
||||||
ChunkMeshDataQueue MeshDataQueue;
|
ChunkMeshDataQueue MeshDataQueue;
|
||||||
|
@ -95,8 +97,7 @@ void mesh(Chunk::Chunk* chunk)
|
||||||
Block b1, b2;
|
Block b1, b2;
|
||||||
if(x[dim] >= 0) b1 = blocks[HILBERT_XYZ_ENCODE[x[0]][x[1]][x[2]]];
|
if(x[dim] >= 0) b1 = blocks[HILBERT_XYZ_ENCODE[x[0]][x[1]][x[2]]];
|
||||||
else{
|
else{
|
||||||
b1 = Block::NULLBLK;
|
// b1 = Block::NULLBLK;
|
||||||
/*
|
|
||||||
int cx = chunk->getPosition().x*CHUNK_SIZE;
|
int cx = chunk->getPosition().x*CHUNK_SIZE;
|
||||||
int cy = chunk->getPosition().y*CHUNK_SIZE;
|
int cy = chunk->getPosition().y*CHUNK_SIZE;
|
||||||
int cz = chunk->getPosition().z*CHUNK_SIZE;
|
int cz = chunk->getPosition().z*CHUNK_SIZE;
|
||||||
|
@ -105,14 +106,13 @@ void mesh(Chunk::Chunk* chunk)
|
||||||
int by = cy+x[1];
|
int by = cy+x[1];
|
||||||
int bz = cz+x[2];
|
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]
|
if(x[dim] < CHUNK_SIZE - 1) b2 = blocks[HILBERT_XYZ_ENCODE[x[0] + q[0]][x[1]
|
||||||
+ q[1]][x[2] + q[2]]];
|
+ q[1]][x[2] + q[2]]];
|
||||||
else{
|
else{
|
||||||
b2 = Block::NULLBLK;
|
//b2 = Block::NULLBLK;
|
||||||
/*
|
|
||||||
int cx = chunk->getPosition().x*CHUNK_SIZE;
|
int cx = chunk->getPosition().x*CHUNK_SIZE;
|
||||||
int cy = chunk->getPosition().y*CHUNK_SIZE;
|
int cy = chunk->getPosition().y*CHUNK_SIZE;
|
||||||
int cz = chunk->getPosition().z*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 by = cy+x[1] + q[1];
|
||||||
int bz = cz+x[2] + q[2];
|
int bz = cz+x[2] + q[2];
|
||||||
|
|
||||||
b2 = chunkmanager::getBlockAtPos(bx, by, bz);*/
|
b2 = chunkmanager::getBlockAtPos(bx, by, bz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the mask
|
// Compute the mask
|
||||||
|
@ -129,9 +129,15 @@ void mesh(Chunk::Chunk* chunk)
|
||||||
// The else case provides face culling for adjacent solid faces
|
// The else case provides face culling for adjacent solid faces
|
||||||
// Checking for NULLBLK avoids creating empty faces if nearby chunk was not
|
// Checking for NULLBLK avoids creating empty faces if nearby chunk was not
|
||||||
// yet generated
|
// yet generated
|
||||||
|
#if CHUNKMESHER_BORDERS == 1
|
||||||
mask[n++] = b1 == b2 ? Block::NULLBLK
|
mask[n++] = b1 == b2 ? Block::NULLBLK
|
||||||
: backFace ? b1 == Block::NULLBLK || b1 == Block::AIR ? b2 : Block::NULLBLK
|
: backFace ? b1 == Block::NULLBLK || b1 == Block::AIR ? b2 : Block::NULLBLK
|
||||||
: b2 == Block::NULLBLK || b2 == Block::AIR ? b1 : 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue