summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-02-01 15:19:18 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-02-01 15:19:18 +0100
commit9b1d92387dd83e7340c7ee5f06dbad0a971981b0 (patch)
tree1978e746b9f8e73c36474797e5a277c9571b12c9
parent143b9f6c78f7cf4c9ed603e57cedb3abf8fb7a3d (diff)
downloadMinedMap-9b1d92387dd83e7340c7ee5f06dbad0a971981b0.tar
MinedMap-9b1d92387dd83e7340c7ee5f06dbad0a971981b0.zip
Use biome data
-rw-r--r--src/MinedMap.cpp2
-rw-r--r--src/World/Block.cpp2
-rw-r--r--src/World/Block.hpp6
-rw-r--r--src/World/Chunk.cpp9
-rw-r--r--src/World/Chunk.hpp5
5 files changed, 20 insertions, 4 deletions
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<NBT::ListTag<NBT::CompoundTag>>("Sections"));
maxY = (assertValue(sections->back()->get<NBT::ByteTag>("Y"))->getValue() + 1) * SIZE;
+
+ std::shared_ptr<const NBT::ByteArrayTag> biomeTag = assertValue(level->get<NBT::ByteArrayTag>("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<uint8_t[]> blockData;
std::unique_ptr<uint8_t[]> blockSkyLight;
std::unique_ptr<uint8_t[]> 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();