experimental optimizations
This commit is contained in:
+16
-14
@@ -93,7 +93,7 @@ void Lighting::buildSkyLight(int cx, int cz){
|
|||||||
solverS->solve();
|
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 Block* const* blockDefs = content->getIndices()->getBlockDefs();
|
||||||
const Chunk* chunk = chunks->getChunk(cx, cz);
|
const Chunk* chunk = chunks->getChunk(cx, cz);
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ void Lighting::onChunkLoaded(int cx, int cz){
|
|||||||
const Block* block = blockDefs[vox.id];
|
const Block* block = blockDefs[vox.id];
|
||||||
int gx = x + cx * CHUNK_W;
|
int gx = x + cx * CHUNK_W;
|
||||||
int gz = z + cz * CHUNK_D;
|
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]);
|
solverR->add(gx,y,gz,block->emission[0]);
|
||||||
solverG->add(gx,y,gz,block->emission[1]);
|
solverG->add(gx,y,gz,block->emission[1]);
|
||||||
solverB->add(gx,y,gz,block->emission[2]);
|
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++){
|
if (expand) {
|
||||||
for (int z = -1; z <= CHUNK_D; z++){
|
for (int y = -1; y <= CHUNK_H; y++){
|
||||||
for (int x = -1; x <= CHUNK_W; x++){
|
for (int z = -1; z <= CHUNK_D; z++){
|
||||||
if (!(x == -1 || x == CHUNK_W || z == -1 || z == CHUNK_D))
|
for (int x = -1; x <= CHUNK_W; x++){
|
||||||
continue;
|
if (!(x == -1 || x == CHUNK_W || z == -1 || z == CHUNK_D))
|
||||||
int gx = x + cx * CHUNK_W;
|
continue;
|
||||||
int gz = z + cz * CHUNK_D;
|
int gx = x + cx * CHUNK_W;
|
||||||
if (chunks->getLight(x,y,z)){
|
int gz = z + cz * CHUNK_D;
|
||||||
solverR->add(gx,y,gz);
|
if (chunks->getLight(x,y,z)){
|
||||||
solverG->add(gx,y,gz);
|
solverR->add(gx,y,gz);
|
||||||
solverB->add(gx,y,gz);
|
solverG->add(gx,y,gz);
|
||||||
solverS->add(gx,y,gz);
|
solverB->add(gx,y,gz);
|
||||||
|
solverS->add(gx,y,gz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
void prebuildSkyLight(int cx, int cz);
|
void prebuildSkyLight(int cx, int cz);
|
||||||
void buildSkyLight(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);
|
void onBlockSet(int x, int y, int z, int id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ void ChunksController::update(int64_t maxDuration) {
|
|||||||
timeutil::Timer timer;
|
timeutil::Timer timer;
|
||||||
if (loadVisible()) {
|
if (loadVisible()) {
|
||||||
int64_t mcs = timer.stop();
|
int64_t mcs = timer.stop();
|
||||||
if (mcstotal + mcs * 2 < maxDuration * 1000) {
|
if (mcstotal + mcs < maxDuration * 1000) {
|
||||||
mcstotal += mcs;
|
mcstotal += mcs;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -55,13 +55,14 @@ bool ChunksController::loadVisible(){
|
|||||||
const int d = chunks->d;
|
const int d = chunks->d;
|
||||||
const int ox = chunks->ox;
|
const int ox = chunks->ox;
|
||||||
const int oz = chunks->oz;
|
const int oz = chunks->oz;
|
||||||
|
|
||||||
int nearX = 0;
|
int nearX = 0;
|
||||||
int nearZ = 0;
|
int nearZ = 0;
|
||||||
int minDistance = ((w-padding*2)/2)*((w-padding*2)/2);
|
int minDistance = ((w-padding*2)/2)*((w-padding*2)/2);
|
||||||
for (uint z = padding; z < d-padding; z++){
|
for (uint z = padding; z < d-padding; z++){
|
||||||
for (uint x = padding; x < w-padding; x++){
|
for (uint x = padding; x < w-padding; x++){
|
||||||
int index = z * w + x;
|
int index = z * w + x;
|
||||||
std::shared_ptr<Chunk> chunk = chunks->chunks[index];
|
auto chunk = chunks->chunks[index];
|
||||||
if (chunk != nullptr){
|
if (chunk != nullptr){
|
||||||
int surrounding = 0;
|
int surrounding = 0;
|
||||||
for (int oz = -1; oz <= 1; oz++){
|
for (int oz = -1; oz <= 1; oz++){
|
||||||
@@ -72,10 +73,11 @@ bool ChunksController::loadVisible(){
|
|||||||
}
|
}
|
||||||
chunk->surrounding = surrounding;
|
chunk->surrounding = surrounding;
|
||||||
if (surrounding == MIN_SURROUNDING && !chunk->isLighted()) {
|
if (surrounding == MIN_SURROUNDING && !chunk->isLighted()) {
|
||||||
if (!chunk->isLoadedLights()) {
|
bool lightsCache = chunk->isLoadedLights();
|
||||||
|
if (!lightsCache) {
|
||||||
lighting->buildSkyLight(chunk->x, chunk->z);
|
lighting->buildSkyLight(chunk->x, chunk->z);
|
||||||
}
|
}
|
||||||
lighting->onChunkLoaded(chunk->x, chunk->z);
|
lighting->onChunkLoaded(chunk->x, chunk->z, !lightsCache);
|
||||||
chunk->setLighted(true);
|
chunk->setLighted(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -93,7 +95,7 @@ bool ChunksController::loadVisible(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int index = nearZ * w + nearX;
|
int index = nearZ * w + nearX;
|
||||||
std::shared_ptr<Chunk> chunk = chunks->chunks[index];
|
auto chunk = chunks->chunks[index];
|
||||||
if (chunk != nullptr) {
|
if (chunk != nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user