More efficient chunk loaders handling
This commit is contained in:
parent
35f8ebe79c
commit
f0a74dd821
@ -310,7 +310,10 @@ int main() {
|
|||||||
|
|
||||||
chunks->setCenter(wfile, camera->position.x,0,camera->position.z);
|
chunks->setCenter(wfile, camera->position.x,0,camera->position.z);
|
||||||
chunksController._buildMeshes(&renderer, frame);
|
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);
|
draw_world(camera, assets, chunks, occlusion);
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,18 @@ ChunksController::~ChunksController(){
|
|||||||
delete[] loaders;
|
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){
|
bool ChunksController::loadVisible(WorldFiles* worldFiles){
|
||||||
const int w = chunks->w;
|
const int w = chunks->w;
|
||||||
const int h = chunks->h;
|
const int h = chunks->h;
|
||||||
@ -61,16 +73,10 @@ 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;
|
||||||
@ -187,7 +193,6 @@ bool ChunksController::_buildMeshes(VoxelRenderer* renderer, int tick) {
|
|||||||
}
|
}
|
||||||
mesh = renderer->render(chunk, (const Chunk**)closes);
|
mesh = renderer->render(chunk, (const Chunk**)closes);
|
||||||
chunks->meshes[index] = mesh;
|
chunks->meshes[index] = mesh;
|
||||||
//std::cout << "2: built mesh for " << chunk << std::endl;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user