Chunk is invisible until being surrounded by chunks in every direction
This commit is contained in:
parent
551d4cac85
commit
aa08a0bc6b
@ -17,6 +17,7 @@ public:
|
||||
bool modified = true;
|
||||
bool ready = false;
|
||||
bool loaded = false;
|
||||
int surrounding = 0;
|
||||
int references = 1;
|
||||
Chunk(int x, int y, int z);
|
||||
~Chunk();
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
|
||||
ChunksController::ChunksController(Chunks* chunks, Lighting* lighting) : chunks(chunks), lighting(lighting){
|
||||
loadersCount = std::thread::hardware_concurrency() - 1;
|
||||
if (loadersCount <= 0)
|
||||
loadersCount = 1;
|
||||
loaders = new ChunksLoader*[loadersCount];
|
||||
for (int i = 0; i < loadersCount; i++){
|
||||
loaders[i] = new ChunksLoader();
|
||||
@ -54,8 +56,17 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){
|
||||
for (int x = 2; x < w-2; x++){
|
||||
int index = (y * d + z) * w + x;
|
||||
Chunk* chunk = chunks->chunks[index];
|
||||
if (chunk != nullptr)
|
||||
if (chunk != nullptr){
|
||||
int surrounding = 0;
|
||||
for (int oz = -1; oz <= 1; oz++){
|
||||
for (int ox = -1; ox <= 1; ox++){
|
||||
Chunk* other = chunks->getChunk(chunk->x+ox, chunk->y, chunk->z+oz);
|
||||
if (other != nullptr) surrounding++;
|
||||
}
|
||||
}
|
||||
chunk->surrounding = surrounding;
|
||||
continue;
|
||||
}
|
||||
int lx = x - w / 2;
|
||||
int ly = y - h / 2;
|
||||
int lz = z - d / 2;
|
||||
@ -138,7 +149,7 @@ bool ChunksController::_buildMeshes(VoxelRenderer* renderer, int tick) {
|
||||
Mesh* mesh = chunks->meshes[index];
|
||||
if (mesh != nullptr && !chunk->modified)
|
||||
continue;
|
||||
if (!chunk->ready){
|
||||
if (!chunk->ready || chunk->surrounding < 9){
|
||||
continue;
|
||||
}
|
||||
int lx = x - w / 2;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user