experimental optimizations
This commit is contained in:
parent
f0fbceb0af
commit
4ea36f8996
@ -93,7 +93,7 @@ void Lighting::buildSkyLight(int cx, int cz){
|
||||
solverS->solve();
|
||||
}
|
||||
|
||||
void Lighting::onChunkLoaded(int cx, int cz){
|
||||
void Lighting::onChunkLoaded(int cx, int cz, bool expand){
|
||||
const Block* const* blockDefs = content->getIndices()->getBlockDefs();
|
||||
const Chunk* chunk = chunks->getChunk(cx, cz);
|
||||
|
||||
@ -104,7 +104,7 @@ void Lighting::onChunkLoaded(int cx, int cz){
|
||||
const Block* block = blockDefs[vox.id];
|
||||
int gx = x + cx * CHUNK_W;
|
||||
int gz = z + cz * CHUNK_D;
|
||||
if (block->emission[0] || block->emission[1] || block->emission[2]){
|
||||
if (block->rt.emissive){
|
||||
solverR->add(gx,y,gz,block->emission[0]);
|
||||
solverG->add(gx,y,gz,block->emission[1]);
|
||||
solverB->add(gx,y,gz,block->emission[2]);
|
||||
@ -113,18 +113,20 @@ void Lighting::onChunkLoaded(int cx, int cz){
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = -1; y <= CHUNK_H; y++){
|
||||
for (int z = -1; z <= CHUNK_D; z++){
|
||||
for (int x = -1; x <= CHUNK_W; x++){
|
||||
if (!(x == -1 || x == CHUNK_W || z == -1 || z == CHUNK_D))
|
||||
continue;
|
||||
int gx = x + cx * CHUNK_W;
|
||||
int gz = z + cz * CHUNK_D;
|
||||
if (chunks->getLight(x,y,z)){
|
||||
solverR->add(gx,y,gz);
|
||||
solverG->add(gx,y,gz);
|
||||
solverB->add(gx,y,gz);
|
||||
solverS->add(gx,y,gz);
|
||||
if (expand) {
|
||||
for (int y = -1; y <= CHUNK_H; y++){
|
||||
for (int z = -1; z <= CHUNK_D; z++){
|
||||
for (int x = -1; x <= CHUNK_W; x++){
|
||||
if (!(x == -1 || x == CHUNK_W || z == -1 || z == CHUNK_D))
|
||||
continue;
|
||||
int gx = x + cx * CHUNK_W;
|
||||
int gz = z + cz * CHUNK_D;
|
||||
if (chunks->getLight(x,y,z)){
|
||||
solverR->add(gx,y,gz);
|
||||
solverG->add(gx,y,gz);
|
||||
solverB->add(gx,y,gz);
|
||||
solverS->add(gx,y,gz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ public:
|
||||
void clear();
|
||||
void prebuildSkyLight(int cx, int cz);
|
||||
void buildSkyLight(int cx, int cz);
|
||||
void onChunkLoaded(int cx, int cz);
|
||||
void onChunkLoaded(int cx, int cz, bool expand);
|
||||
void onBlockSet(int x, int y, int z, int id);
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user