From 38d8bd07386cb415cbe23d2fe56ed8be38cf4c53 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 24 Aug 2021 21:03:18 +0200 Subject: [PATCH] Chunk: replace withDepth argument with extensible flags field --- src/MinedMap.cpp | 4 ++-- src/World/Chunk.cpp | 10 +++++----- src/World/Chunk.hpp | 7 +++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/MinedMap.cpp b/src/MinedMap.cpp index 4855b6f..a361ab0 100644 --- a/src/MinedMap.cpp +++ b/src/MinedMap.cpp @@ -56,7 +56,7 @@ static const size_t DIM = World::Region::SIZE*World::Chunk::SIZE; static void addChunkBiome(uint8_t biomemap[DIM*DIM], size_t X, size_t Z, const World::ChunkData *data) { World::Chunk chunk(data); - World::Chunk::Heightmap layer = chunk.getTopLayer(false); + World::Chunk::Heightmap layer = chunk.getTopLayer(0); for (size_t x = 0; x < World::Chunk::SIZE; x++) { for (size_t z = 0; z < World::Chunk::SIZE; z++) { @@ -127,7 +127,7 @@ static void addChunk(Resource::Color image[DIM*DIM], uint8_t lightmap[2*DIM*DIM] const World::ChunkData *data, const std::unique_ptr biomemaps[3][3] ) { World::Chunk chunk(data); - World::Chunk::Heightmap layer = chunk.getTopLayer(true); + World::Chunk::Heightmap layer = chunk.getTopLayer(World::Chunk::WITH_DEPTH); for (size_t x = 0; x < World::Chunk::SIZE; x++) { for (size_t z = 0; z < World::Chunk::SIZE; z++) { diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp index 423d7e8..e428892 100644 --- a/src/World/Chunk.cpp +++ b/src/World/Chunk.cpp @@ -101,11 +101,11 @@ Block Chunk::getBlock(size_t x, Chunk::Height height, size_t z) const { return block; } -bool Chunk::getHeight(Chunk::Height *height, const Section *section, size_t x, size_t y, size_t z, bool withDepth) const { +bool Chunk::getHeight(Chunk::Height *height, const Section *section, size_t x, size_t y, size_t z, int flags) const { if (height->depth > 0) return false; - if (!withDepth && height->y > 0) + if (!(flags & WITH_DEPTH) && height->y > 0) return false; const Resource::BlockType *type = section->getBlockStateAt(x, y, z); @@ -115,7 +115,7 @@ bool Chunk::getHeight(Chunk::Height *height, const Section *section, size_t x, s if (height->y == 0) height->y = SIZE*section->getY() + y; - if (!withDepth) + if (!(flags & WITH_DEPTH)) return true; if (type->flags & BLOCK_WATER) @@ -126,7 +126,7 @@ bool Chunk::getHeight(Chunk::Height *height, const Section *section, size_t x, s return true; } -Chunk::Heightmap Chunk::getTopLayer(bool withDepth) const { +Chunk::Heightmap Chunk::getTopLayer(int flags) const { size_t done = 0; Heightmap ret = {}; @@ -145,7 +145,7 @@ Chunk::Heightmap Chunk::getTopLayer(bool withDepth) const { for (size_t z = 0; z < SIZE; z++) { for (size_t x = 0; x < SIZE; x++) { - if (getHeight(&ret.v[x][z], section, x, y, z, withDepth)) + if (getHeight(&ret.v[x][z], section, x, y, z, flags)) done++; } } diff --git a/src/World/Chunk.hpp b/src/World/Chunk.hpp index ccbba54..bcffa1e 100644 --- a/src/World/Chunk.hpp +++ b/src/World/Chunk.hpp @@ -50,6 +50,9 @@ public: static const size_t BSIZE = SIZE / BGROUP; static const size_t BMAXY = MAXY / BGROUP; + // Flags + static const int WITH_DEPTH = (1 << 0); + struct Height { unsigned y; unsigned depth; @@ -67,7 +70,7 @@ private: std::shared_ptr biomeIntsPre115; std::shared_ptr biomeInts; - bool getHeight(Height *height, const Section *section, size_t x, size_t y, size_t z, bool withDepth) const; + bool getHeight(Height *height, const Section *section, size_t x, size_t y, size_t z, int flags) const; const Resource::BlockType * getBlockStateAt(size_t x, size_t y, size_t z) const { size_t Y = y / SIZE; @@ -89,7 +92,7 @@ public: uint8_t getBiome(size_t x, size_t y, size_t z) const; Block getBlock(size_t x, Height y, size_t z) const; - Heightmap getTopLayer(bool withDepth) const; + Heightmap getTopLayer(int flags) const; }; }