Automatic number of loaders selecting

This commit is contained in:
MihailRis 2022-03-06 03:24:05 +03:00 committed by GitHub
parent cbfa073550
commit 551d4cac85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -8,18 +8,20 @@
#include "../files/WorldFiles.h"
#include "ChunksLoader.h"
#include <iostream>
#include <thread>
#define LOADERS_COUNT 3
ChunksController::ChunksController(Chunks* chunks, Lighting* lighting) : chunks(chunks), lighting(lighting){
loaders = new ChunksLoader*[LOADERS_COUNT];
for (int i = 0; i < LOADERS_COUNT; i++){
loadersCount = std::thread::hardware_concurrency() - 1;
loaders = new ChunksLoader*[loadersCount];
for (int i = 0; i < loadersCount; i++){
loaders[i] = new ChunksLoader();
}
std::cout << "created " << loadersCount << " loaders" << std::endl;
}
ChunksController::~ChunksController(){
for (int i = 0; i < LOADERS_COUNT; i++)
for (int i = 0; i < loadersCount; i++)
delete loaders[i];
delete[] loaders;
}
@ -29,7 +31,7 @@ int ChunksController::countFreeLoaders(){
return loaders[0]->isBusy() ? 0 : 1;
int count = 0;
for (int i = 0; i < LOADERS_COUNT; i++){
for (int i = 0; i < loadersCount; i++){
if (!loaders[i]->isBusy())
count++;
}
@ -74,7 +76,7 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){
return false;
ChunksLoader* freeLoader = nullptr;
for (int i = 0; i < LOADERS_COUNT; i++){
for (int i = 0; i < loadersCount; i++){
ChunksLoader* loader = loaders[i];
if (loader->isBusy()){
continue;

View File

@ -12,6 +12,7 @@ private:
Chunks* chunks;
Lighting* lighting;
ChunksLoader** loaders;
int loadersCount;
int _totalLoaded = 0;
public:
ChunksController(Chunks* chunks, Lighting* lighting);