Use biome data

This commit is contained in:
Matthias Schiffer 2015-02-01 15:19:18 +01:00
parent 143b9f6c78
commit 9b1d92387d
5 changed files with 20 additions and 4 deletions

View file

@ -97,7 +97,7 @@ int main(int argc, char *argv[]) {
for (size_t x = 0; x < World::Chunk::SIZE; x++) { for (size_t x = 0; x < World::Chunk::SIZE; x++) {
for (size_t z = 0; z < World::Chunk::SIZE; z++) 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());
} }
} }
} }

View file

@ -32,7 +32,7 @@
namespace MinedMap { namespace MinedMap {
namespace World { namespace World {
uint32_t Block::getColor(uint8_t biome) const { uint32_t Block::getColor() const {
const World::BlockType &t = World::BLOCK_TYPES[id]; const World::BlockType &t = World::BLOCK_TYPES[id];
if (!t.opaque) if (!t.opaque)

View file

@ -41,9 +41,11 @@ struct Block {
uint8_t blockLight; uint8_t blockLight;
uint8_t skyLight; 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;
}; };
} }

View file

@ -105,6 +105,13 @@ void Chunk::analyzeChunk() {
sections = assertValue(level->get<NBT::ListTag<NBT::CompoundTag>>("Sections")); sections = assertValue(level->get<NBT::ListTag<NBT::CompoundTag>>("Sections"));
maxY = (assertValue(sections->back()->get<NBT::ByteTag>("Y"))->getValue() + 1) * SIZE; 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]); blockIDs.reset(new uint8_t[maxY * SIZE * SIZE]);
blockData.reset(new uint8_t[maxY * SIZE * SIZE / 2]); blockData.reset(new uint8_t[maxY * SIZE * SIZE / 2]);
blockSkyLight.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.height = h;
b.biome = getBiomeAt(x, z);
done++; done++;
} }
} }

View file

@ -67,6 +67,7 @@ private:
std::unique_ptr<uint8_t[]> blockData; std::unique_ptr<uint8_t[]> blockData;
std::unique_ptr<uint8_t[]> blockSkyLight; std::unique_ptr<uint8_t[]> blockSkyLight;
std::unique_ptr<uint8_t[]> blockBlockLight; std::unique_ptr<uint8_t[]> blockBlockLight;
const uint8_t *biomes;
size_t getIndex(size_t x, size_t y, size_t z) const { 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); 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 inflateChunk(Buffer buffer);
void parseChunk(); void parseChunk();