From 9b1d92387dd83e7340c7ee5f06dbad0a971981b0 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 1 Feb 2015 15:19:18 +0100 Subject: Use biome data --- src/MinedMap.cpp | 2 +- src/World/Block.cpp | 2 +- src/World/Block.hpp | 6 ++++-- src/World/Chunk.cpp | 9 +++++++++ src/World/Chunk.hpp | 5 +++++ 5 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/MinedMap.cpp b/src/MinedMap.cpp index c33dabb..594268c 100644 --- a/src/MinedMap.cpp +++ b/src/MinedMap.cpp @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) { for (size_t x = 0; x < World::Chunk::SIZE; x++) { for (size_t z = 0; z < World::Chunk::SIZE; z++) - image[Z*World::Chunk::SIZE+z][X*World::Chunk::SIZE+x] = htonl(layer.blocks[x][z].getColor(0)); + image[Z*World::Chunk::SIZE+z][X*World::Chunk::SIZE+x] = htonl(layer.blocks[x][z].getColor()); } } } diff --git a/src/World/Block.cpp b/src/World/Block.cpp index f02c107..ae6c9cd 100644 --- a/src/World/Block.cpp +++ b/src/World/Block.cpp @@ -32,7 +32,7 @@ namespace MinedMap { namespace World { -uint32_t Block::getColor(uint8_t biome) const { +uint32_t Block::getColor() const { const World::BlockType &t = World::BLOCK_TYPES[id]; if (!t.opaque) diff --git a/src/World/Block.hpp b/src/World/Block.hpp index 2bdbaa5..3613cac 100644 --- a/src/World/Block.hpp +++ b/src/World/Block.hpp @@ -41,9 +41,11 @@ struct Block { uint8_t blockLight; uint8_t skyLight; - Block() : id(0), data(0), height(0), blockLight(0), skyLight(0) {} + uint8_t biome; - uint32_t getColor(uint8_t biome) const; + Block() : id(0), data(0), height(0), blockLight(0), skyLight(0), biome(0) {} + + uint32_t getColor() const; }; } diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp index 5a6f95b..3a1e9a2 100644 --- a/src/World/Chunk.cpp +++ b/src/World/Chunk.cpp @@ -105,6 +105,13 @@ void Chunk::analyzeChunk() { sections = assertValue(level->get>("Sections")); maxY = (assertValue(sections->back()->get("Y"))->getValue() + 1) * SIZE; + + std::shared_ptr biomeTag = assertValue(level->get("Biomes")); + if (biomeTag->getLength() != SIZE*SIZE) + throw std::invalid_argument("corrupt biome data"); + + biomes = biomeTag->getValue(); + blockIDs.reset(new uint8_t[maxY * SIZE * SIZE]); blockData.reset(new uint8_t[maxY * SIZE * SIZE / 2]); blockSkyLight.reset(new uint8_t[maxY * SIZE * SIZE / 2]); @@ -170,6 +177,8 @@ Chunk::Blocks Chunk::getTopLayer() const { b.height = h; + b.biome = getBiomeAt(x, z); + done++; } } diff --git a/src/World/Chunk.hpp b/src/World/Chunk.hpp index a4948b7..d05328c 100644 --- a/src/World/Chunk.hpp +++ b/src/World/Chunk.hpp @@ -67,6 +67,7 @@ private: std::unique_ptr blockData; std::unique_ptr blockSkyLight; std::unique_ptr blockBlockLight; + const uint8_t *biomes; size_t getIndex(size_t x, size_t y, size_t z) const { @@ -101,6 +102,10 @@ private: return getHalf(blockSkyLight.get(), x, y, z); } + uint8_t getBiomeAt(size_t x, size_t z) const { + return biomes[z*SIZE + x]; + } + void inflateChunk(Buffer buffer); void parseChunk(); -- cgit v1.2.3