chunks controller & lighting optimizations
This commit is contained in:
@@ -63,11 +63,14 @@ void LightSolver::solve(){
|
|||||||
int z = entry.z+coords[i*3+2];
|
int z = entry.z+coords[i*3+2];
|
||||||
Chunk* chunk = chunks->getChunkByVoxel(x,y,z);
|
Chunk* chunk = chunks->getChunkByVoxel(x,y,z);
|
||||||
if (chunk) {
|
if (chunk) {
|
||||||
|
int lx = x - chunk->x * CHUNK_W;
|
||||||
|
int lz = z - chunk->z * CHUNK_D;
|
||||||
chunk->setModified(true);
|
chunk->setModified(true);
|
||||||
ubyte light = chunks->getLight(x,y,z, channel);
|
|
||||||
|
ubyte light = chunk->lightmap->get(lx,y,lz, channel);
|
||||||
if (light != 0 && light == entry.light-1){
|
if (light != 0 && light == entry.light-1){
|
||||||
remqueue.push(lightentry {x, y, z, light});
|
remqueue.push(lightentry {x, y, z, light});
|
||||||
chunk->lightmap->set(x-chunk->x*CHUNK_W, y, z-chunk->z*CHUNK_D, channel, 0);
|
chunk->lightmap->set(lx, y, lz, channel, 0);
|
||||||
}
|
}
|
||||||
else if (light >= entry.light){
|
else if (light >= entry.light){
|
||||||
addqueue.push(lightentry {x, y, z, light});
|
addqueue.push(lightentry {x, y, z, light});
|
||||||
@@ -87,15 +90,18 @@ void LightSolver::solve(){
|
|||||||
int z = entry.z+coords[i*3+2];
|
int z = entry.z+coords[i*3+2];
|
||||||
Chunk* chunk = chunks->getChunkByVoxel(x,y,z);
|
Chunk* chunk = chunks->getChunkByVoxel(x,y,z);
|
||||||
if (chunk) {
|
if (chunk) {
|
||||||
|
int lx = x - chunk->x * CHUNK_W;
|
||||||
|
int lz = z - chunk->z * CHUNK_D;
|
||||||
chunk->setModified(true);
|
chunk->setModified(true);
|
||||||
int light = chunk->lightmap->get(
|
|
||||||
x - chunk->x * CHUNK_W, y,
|
ubyte light = chunk->lightmap->get(lx, y, lz, channel);
|
||||||
z - chunk->z * CHUNK_D,
|
voxel& v = chunk->voxels[vox_index(lx, y, lz)];
|
||||||
channel);
|
const Block* block = blockDefs[v.id];
|
||||||
voxel* v = chunks->get(x,y,z);
|
|
||||||
const Block* block = blockDefs[v->id];
|
|
||||||
if (block->lightPassing && light+2 <= entry.light){
|
if (block->lightPassing && light+2 <= entry.light){
|
||||||
chunk->lightmap->set(x-chunk->x*CHUNK_W, y, z-chunk->z*CHUNK_D, channel, entry.light-1);
|
chunk->lightmap->set(
|
||||||
|
x-chunk->x*CHUNK_W, y, z-chunk->z*CHUNK_D,
|
||||||
|
channel,
|
||||||
|
entry.light-1);
|
||||||
addqueue.push(lightentry {x, y, z, ubyte(entry.light-1)});
|
addqueue.push(lightentry {x, y, z, ubyte(entry.light-1)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,23 +63,24 @@ bool ChunksController::loadVisible(){
|
|||||||
int index = z * w + x;
|
int index = z * w + x;
|
||||||
auto chunk = chunks->chunks[index];
|
auto chunk = chunks->chunks[index];
|
||||||
if (chunk != nullptr){
|
if (chunk != nullptr){
|
||||||
int surrounding = 0;
|
if (!chunk->isLighted()) {
|
||||||
for (int oz = -1; oz <= 1; oz++){
|
int surrounding = 0;
|
||||||
for (int ox = -1; ox <= 1; ox++){
|
for (int oz = -1; oz <= 1; oz++){
|
||||||
Chunk* other = chunks->getChunk(chunk->x+ox, chunk->z+oz);
|
for (int ox = -1; ox <= 1; ox++){
|
||||||
if (other != nullptr) surrounding++;
|
Chunk* other = chunks->getChunk(chunk->x+ox, chunk->z+oz);
|
||||||
|
if (other != nullptr) surrounding++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chunk->surrounding = surrounding;
|
||||||
|
if (surrounding == MIN_SURROUNDING) {
|
||||||
|
bool lightsCache = chunk->isLoadedLights();
|
||||||
|
if (!lightsCache) {
|
||||||
|
lighting->buildSkyLight(chunk->x, chunk->z);
|
||||||
|
}
|
||||||
|
lighting->onChunkLoaded(chunk->x, chunk->z, !lightsCache);
|
||||||
|
chunk->setLighted(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
chunk->surrounding = surrounding;
|
|
||||||
if (surrounding == MIN_SURROUNDING && !chunk->isLighted()) {
|
|
||||||
timeutil::ScopeLogTimer log(555);
|
|
||||||
bool lightsCache = chunk->isLoadedLights();
|
|
||||||
if (!lightsCache) {
|
|
||||||
lighting->buildSkyLight(chunk->x, chunk->z);
|
|
||||||
}
|
|
||||||
lighting->onChunkLoaded(chunk->x, chunk->z, !lightsCache);
|
|
||||||
chunk->setLighted(true);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user