experimental optimizations

This commit is contained in:
MihailRis
2024-01-24 18:23:48 +03:00
parent f0fbceb0af
commit 4ea36f8996
3 changed files with 24 additions and 20 deletions
+7 -5
View File
@@ -40,7 +40,7 @@ void ChunksController::update(int64_t maxDuration) {
timeutil::Timer timer;
if (loadVisible()) {
int64_t mcs = timer.stop();
if (mcstotal + mcs * 2 < maxDuration * 1000) {
if (mcstotal + mcs < maxDuration * 1000) {
mcstotal += mcs;
continue;
}
@@ -55,13 +55,14 @@ bool ChunksController::loadVisible(){
const int d = chunks->d;
const int ox = chunks->ox;
const int oz = chunks->oz;
int nearX = 0;
int nearZ = 0;
int minDistance = ((w-padding*2)/2)*((w-padding*2)/2);
for (uint z = padding; z < d-padding; z++){
for (uint x = padding; x < w-padding; x++){
int index = z * w + x;
std::shared_ptr<Chunk> chunk = chunks->chunks[index];
auto chunk = chunks->chunks[index];
if (chunk != nullptr){
int surrounding = 0;
for (int oz = -1; oz <= 1; oz++){
@@ -72,10 +73,11 @@ bool ChunksController::loadVisible(){
}
chunk->surrounding = surrounding;
if (surrounding == MIN_SURROUNDING && !chunk->isLighted()) {
if (!chunk->isLoadedLights()) {
bool lightsCache = chunk->isLoadedLights();
if (!lightsCache) {
lighting->buildSkyLight(chunk->x, chunk->z);
}
lighting->onChunkLoaded(chunk->x, chunk->z);
lighting->onChunkLoaded(chunk->x, chunk->z, !lightsCache);
chunk->setLighted(true);
return true;
}
@@ -93,7 +95,7 @@ bool ChunksController::loadVisible(){
}
int index = nearZ * w + nearX;
std::shared_ptr<Chunk> chunk = chunks->chunks[index];
auto chunk = chunks->chunks[index];
if (chunk != nullptr) {
return false;
}