From c80f54cba794c653732e5cba1f329817d332070d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 19 Sep 2015 23:01:41 +0900 Subject: Chunk: allow generating unlighted maps for chunks without light data --- src/World/Chunk.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/World') diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp index dae66ff..f722655 100644 --- a/src/World/Chunk.cpp +++ b/src/World/Chunk.cpp @@ -99,8 +99,7 @@ void Chunk::parseChunk() { void Chunk::analyzeChunk() { std::shared_ptr lightPopulatedTag = level->get("LightPopulated"); - if (!(lightPopulatedTag && lightPopulatedTag->getValue())) - throw std::invalid_argument("light data missing"); + bool lightPopulated = lightPopulatedTag && lightPopulatedTag->getValue(); sections = assertValue(level->get>("Sections")); maxY = (assertValue(sections->back()->get("Y"))->getValue() + 1) * SIZE; @@ -126,18 +125,24 @@ void Chunk::analyzeChunk() { for (auto §ion : *sections) { std::shared_ptr blocks = assertValue(section->get("Blocks")); std::shared_ptr data = assertValue(section->get("Data")); - std::shared_ptr blockLight = assertValue(section->get("BlockLight")); - std::shared_ptr skyLight = assertValue(section->get("SkyLight")); size_t Y = assertValue(section->get("Y"))->getValue(); - if (blocks->getLength() != SIZE*SIZE*SIZE || data->getLength() != SIZE*SIZE*SIZE/2 - || blockLight->getLength() != SIZE*SIZE*SIZE/2 || skyLight->getLength() != SIZE*SIZE*SIZE/2) + if (blocks->getLength() != SIZE*SIZE*SIZE || data->getLength() != SIZE*SIZE*SIZE/2) throw std::invalid_argument("corrupt chunk data"); + if (lightPopulated) { + std::shared_ptr blockLight = assertValue(section->get("BlockLight")); + std::shared_ptr skyLight = assertValue(section->get("SkyLight")); + + if (blockLight->getLength() != SIZE*SIZE*SIZE/2 || skyLight->getLength() != SIZE*SIZE*SIZE/2) + throw std::invalid_argument("corrupt chunk data"); + + std::memcpy(blockBlockLight.get() + Y*SIZE*SIZE*SIZE/2, blockLight->getValue(), SIZE*SIZE*SIZE/2); + std::memcpy(blockSkyLight.get() + Y*SIZE*SIZE*SIZE/2, skyLight->getValue(), SIZE*SIZE*SIZE/2); + } + std::memcpy(blockIDs.get() + Y*SIZE*SIZE*SIZE, blocks->getValue(), SIZE*SIZE*SIZE); std::memcpy(blockData.get() + Y*SIZE*SIZE*SIZE/2, data->getValue(), SIZE*SIZE*SIZE/2); - std::memcpy(blockBlockLight.get() + Y*SIZE*SIZE*SIZE/2, blockLight->getValue(), SIZE*SIZE*SIZE/2); - std::memcpy(blockSkyLight.get() + Y*SIZE*SIZE*SIZE/2, skyLight->getValue(), SIZE*SIZE*SIZE/2); } } -- cgit v1.2.3