diff --git a/src/voxel_engine.cpp b/src/voxel_engine.cpp index 50552026..d03b9e7b 100644 --- a/src/voxel_engine.cpp +++ b/src/voxel_engine.cpp @@ -310,7 +310,10 @@ int main() { chunks->setCenter(wfile, camera->position.x,0,camera->position.z); chunksController._buildMeshes(&renderer, frame); - chunksController.loadVisible(wfile); + + int freeLoaders = chunksController.countFreeLoaders(); + for (int i = 0; i < freeLoaders; i++) + chunksController.loadVisible(wfile); draw_world(camera, assets, chunks, occlusion); diff --git a/src/voxels/ChunksController.cpp b/src/voxels/ChunksController.cpp index b7bad1ce..c6039f1c 100644 --- a/src/voxels/ChunksController.cpp +++ b/src/voxels/ChunksController.cpp @@ -24,6 +24,18 @@ ChunksController::~ChunksController(){ delete[] loaders; } +int ChunksController::countFreeLoaders(){ + if (_totalLoaded < 4) + return loaders[0]->isBusy() ? 0 : 1; + + int count = 0; + for (int i = 0; i < LOADERS_COUNT; i++){ + if (!loaders[i]->isBusy()) + count++; + } + return count; +} + bool ChunksController::loadVisible(WorldFiles* worldFiles){ const int w = chunks->w; const int h = chunks->h; @@ -61,16 +73,10 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){ if (chunk != nullptr) return false; - static int _totalLoaded = 0; - ChunksLoader* freeLoader = nullptr; for (int i = 0; i < LOADERS_COUNT; i++){ ChunksLoader* loader = loaders[i]; if (loader->isBusy()){ - // Use only one loader at start to prevent near chunks lighting artifacts - if (_totalLoaded < 4){ - break; - } continue; } freeLoader = loader; @@ -187,7 +193,6 @@ bool ChunksController::_buildMeshes(VoxelRenderer* renderer, int tick) { } mesh = renderer->render(chunk, (const Chunk**)closes); chunks->meshes[index] = mesh; - //std::cout << "2: built mesh for " << chunk << std::endl; return true; } return false;