diff --git a/src/lighting/LightSolver.cpp b/src/lighting/LightSolver.cpp index f43b4d487..a8d97424a 100644 --- a/src/lighting/LightSolver.cpp +++ b/src/lighting/LightSolver.cpp @@ -55,7 +55,7 @@ void LightSolver::remove(int x, int y, int z) { } void LightSolver::solve(Chunk* prevailingChunk) { - const int coords[] = { + static const int coords[] = { 0, 0, 1, 0, 0,-1, 0, 1, 0, diff --git a/src/lighting/Lighting.cpp b/src/lighting/Lighting.cpp index b17b6f333..c7f3445a5 100644 --- a/src/lighting/Lighting.cpp +++ b/src/lighting/Lighting.cpp @@ -14,9 +14,8 @@ static debug::Logger logger("lighting"); -Lighting::Lighting(const Content& content, Chunks& chunks) - : content(content), chunks(chunks) { - auto& indices = *content.getIndices(); +Lighting::Lighting(const ContentIndices& indices, Chunks& chunks) + : indices(indices), chunks(chunks) { solverR = std::make_unique(indices, chunks, 0); solverG = std::make_unique(indices, chunks, 1); solverB = std::make_unique(indices, chunks, 2); @@ -70,7 +69,7 @@ void Lighting::prebuildSkyLight(Chunk& chunk, const ContentIndices& indices) { } void Lighting::buildSkyLight(int cx, int cz){ - const auto blockDefs = content.getIndices()->blocks.getDefs(); + const auto blockDefs = indices.blocks.getDefs(); Chunk* chunk = chunks.getChunk(cx, cz); if (chunk == nullptr) { @@ -110,7 +109,7 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand) { auto& solverB = *this->solverB; auto& solverS = *this->solverS; - auto blockDefs = content.getIndices()->blocks.getDefs(); + auto blockDefs = indices.blocks.getDefs(); auto chunk = chunks.getChunk(cx, cz); if (chunk == nullptr) { logger.error() << "attempted to build lights to chunk missing in local matrix"; @@ -174,69 +173,72 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand) { } void Lighting::onBlockSet(int x, int y, int z, blockid_t id){ - const auto& block = content.getIndices()->blocks.require(id); - solverR->remove(x,y,z); - solverG->remove(x,y,z); - solverB->remove(x,y,z); + const auto& block = indices.blocks.require(id); - if (id == 0){ - auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z}); - solverR->solve(chunk); - solverG->solve(chunk); - solverB->solve(chunk); - if (chunks.getLight(x,y+1,z, 3) == 0xF){ - for (int i = y; i >= 0; i--){ - voxel* vox = chunks.get(x,i,z); - if ((vox == nullptr || vox->id != 0) && block.skyLightPassing) + auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z}); + + if (block.skyLightPassing) { + if (chunks.getLight(x, y + 1, z, 3) == 0xF) { + for (int i = y; i >= 0; i--) { + voxel* vox = chunks.get(x, i, z); + if (vox == nullptr || + indices.blocks.require(vox->id).skyLightPassing == + false) break; - solverS->add(x,i,z, 0xF); + solverS->add(x, i, z, 0xF); } } - const int coords[] = { - 0, 0, 1, - 0, 0,-1, - 0, 1, 0, - 0,-1, 0, - 1, 0, 0, - -1, 0, 0 - }; - for (int i = 0; i < 6; i++) { - int lx = x + coords[i * 3]; - int ly = y + coords[i * 3 + 1]; - int lz = z + coords[i * 3 + 2]; - - solverR->add(lx, ly, lz); - solverG->add(lx, ly, lz); - solverB->add(lx, ly, lz); - solverS->add(lx, ly, lz); - solverR->solve(chunk); - solverG->solve(chunk); - solverB->solve(chunk); - solverS->solve(chunk); - } } else { - auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z}); - if (!block.skyLightPassing){ - solverS->remove(x,y,z); - for (int i = y-1; i >= 0; i--){ - solverS->remove(x,i,z); - if (i == 0 || chunks.get(x,i-1,z)->id != 0){ - break; - } + solverS->remove(x, y, z); + for (int i = y - 1; i >= 0; i--) { + voxel* vox = chunks.get(x, i, z); + if (vox == nullptr || + indices.blocks.require(vox->id).skyLightPassing == false) { + break; } - solverS->solve(chunk); - } - solverR->solve(chunk); - solverG->solve(chunk); - solverB->solve(chunk); - - if (block.emission[0] || block.emission[1] || block.emission[2]){ - solverR->add(x,y,z,block.emission[0]); - solverG->add(x,y,z,block.emission[1]); - solverB->add(x,y,z,block.emission[2]); - solverR->solve(chunk); - solverG->solve(chunk); - solverB->solve(chunk); + solverS->remove(x, i, z); } + solverS->solve(); } + + solverR->remove(x, y, z); + solverG->remove(x, y, z); + solverB->remove(x, y, z); + + solverR->solve(chunk); + solverG->solve(chunk); + solverB->solve(chunk); + + static const int coords[] = { + 0, 0, 1, + 0, 0,-1, + 0, 1, 0, + 0,-1, 0, + 1, 0, 0, + -1, 0, 0 + }; + for (int i = 0; i < 6; i++) { + int lx = x + coords[i * 3]; + int ly = y + coords[i * 3 + 1]; + int lz = z + coords[i * 3 + 2]; + + solverR->add(lx, ly, lz); + solverG->add(lx, ly, lz); + solverB->add(lx, ly, lz); + solverS->add(lx, ly, lz); + } + + if (block.emission[0]) { + solverR->add(x, y, z, block.emission[0]); + } + if (block.emission[1]) { + solverG->add(x, y, z, block.emission[1]); + } + if (block.emission[2]) { + solverB->add(x, y, z, block.emission[2]); + } + solverR->solve(chunk); + solverG->solve(chunk); + solverB->solve(chunk); + solverS->solve(chunk); } diff --git a/src/lighting/Lighting.hpp b/src/lighting/Lighting.hpp index 622027f05..b5aec6d8f 100644 --- a/src/lighting/Lighting.hpp +++ b/src/lighting/Lighting.hpp @@ -2,21 +2,20 @@ #include "typedefs.hpp" -class Content; class ContentIndices; class Chunk; class Chunks; class LightSolver; class Lighting { - const Content& content; + const ContentIndices& indices; Chunks& chunks; std::unique_ptr solverR; std::unique_ptr solverG; std::unique_ptr solverB; std::unique_ptr solverS; public: - Lighting(const Content& content, Chunks& chunks); + Lighting(const ContentIndices& indices, Chunks& chunks); ~Lighting(); void clear(); diff --git a/src/logic/LevelController.cpp b/src/logic/LevelController.cpp index 870fed923..ae0fa6798 100644 --- a/src/logic/LevelController.cpp +++ b/src/logic/LevelController.cpp @@ -2,6 +2,7 @@ #include +#include "content/Content.hpp" #include "debug/Logger.hpp" #include "engine/Engine.hpp" #include "engine/EnginePaths.hpp" @@ -41,7 +42,7 @@ LevelController::LevelController( if (clientPlayer) { chunks->lighting = std::make_unique( - level->content, *clientPlayer->chunks + *level->content.getIndices(), *clientPlayer->chunks ); } blocks = std::make_unique(