X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fchunk.cpp;h=cc53e912683cb99e576219709fd2151bf867019a;hb=c877ddd21f402381d88a6bebdd5c7c0b4ac28ba9;hp=66b049f00366e1ea4a91cb2f0f69d7b200c3d48b;hpb=32a2a1231de8438f8408007c41247361b1c52417;p=blank.git diff --git a/src/chunk.cpp b/src/chunk.cpp index 66b049f..cc53e91 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -194,7 +194,6 @@ void work_dark() { } } } - work_light(); } } @@ -207,17 +206,27 @@ void Chunk::SetBlock(int index, const Block &block) { if (&old_type == &new_type) return; - if (new_type.luminosity > 0) { - if (GetLight(index) < new_type.luminosity) { - SetLight(index, new_type.luminosity); - light_queue.emplace(this, ToPos(index)); - work_light(); - } - } else if (new_type.block_light && GetLight(index) != 0) { + if (new_type.luminosity > old_type.luminosity) { + // light added + SetLight(index, new_type.luminosity); + light_queue.emplace(this, ToPos(index)); + work_light(); + } else if (new_type.luminosity < old_type.luminosity) { + // light removed + dark_queue.emplace(this, ToPos(index)); SetLight(index, 0); + work_dark(); + SetLight(index, new_type.luminosity); + light_queue.emplace(this, ToPos(index)); + work_light(); + } else if (new_type.block_light && !old_type.block_light) { + // obstacle added dark_queue.emplace(this, ToPos(index)); + SetLight(index, 0); work_dark(); - } else if (old_type.block_light && !new_type.block_light) { + work_light(); + } else if (!new_type.block_light && old_type.block_light) { + // obstacle removed int level = 0; for (int face = 0; face < Block::FACE_COUNT; ++face) { Pos next_pos(ToPos(index) + Block::FaceNormal(Block::Face(face))); @@ -470,15 +479,15 @@ glm::mat4 Chunk::ToTransform(int idx) const { } -ChunkLoader::ChunkLoader(const BlockTypeRegistry ®, const Generator &gen) +ChunkLoader::ChunkLoader(const Config &config, const BlockTypeRegistry ®, const Generator &gen) : base(0, 0, 0) , reg(reg) , gen(gen) , loaded() , to_generate() , to_free() -, load_dist(6) -, unload_dist(8) { +, load_dist(config.load_dist) +, unload_dist(config.unload_dist) { }