Chunk is invisible until being surrounded by chunks in every direction

This commit is contained in:
MihailRis 2022-03-06 22:19:44 +03:00 committed by GitHub
parent 551d4cac85
commit aa08a0bc6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -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();

View File

@ -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;