Fixed first chunks lighting concurrency problem

This commit is contained in:
MihailRis
2022-03-06 03:01:08 +03:00
committed by GitHub
parent 07e2fe8b3b
commit 35f8ebe79c
+9 -1
View File
@@ -61,16 +61,24 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){
if (chunk != nullptr) if (chunk != nullptr)
return false; return false;
static int _totalLoaded = 0;
ChunksLoader* freeLoader = nullptr; ChunksLoader* freeLoader = nullptr;
for (int i = 0; i < LOADERS_COUNT; i++){ for (int i = 0; i < LOADERS_COUNT; i++){
ChunksLoader* loader = loaders[i]; ChunksLoader* loader = loaders[i];
if (loader->isBusy()) if (loader->isBusy()){
// Use only one loader at start to prevent near chunks lighting artifacts
if (_totalLoaded < 4){
break;
}
continue; continue;
}
freeLoader = loader; freeLoader = loader;
break; break;
} }
if (freeLoader == nullptr) if (freeLoader == nullptr)
return false; return false;
_totalLoaded++;
chunk = new Chunk(nearX+ox,nearY+oy,nearZ+oz); chunk = new Chunk(nearX+ox,nearY+oy,nearZ+oz);
if (worldFiles->getChunk(chunk->x, chunk->z, (char*)chunk->voxels)) if (worldFiles->getChunk(chunk->x, chunk->z, (char*)chunk->voxels))
chunk->loaded = true; chunk->loaded = true;