summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-02-02 00:46:39 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-02-02 00:46:39 +0100
commit1e5e31581689d372fbf32bfdcc0a89417dbf6b70 (patch)
treee0866cff853e27e02d9457ae78578cabba12b4e6
parent22b9cfcb8bcf3567e15e2cfa2a6af5544e268973 (diff)
downloadMinedMap-1e5e31581689d372fbf32bfdcc0a89417dbf6b70.tar
MinedMap-1e5e31581689d372fbf32bfdcc0a89417dbf6b70.zip
Chunk: refactor getTopLayer()
-rw-r--r--src/World/Block.hpp2
-rw-r--r--src/World/Chunk.cpp47
-rw-r--r--src/World/Chunk.hpp1
3 files changed, 26 insertions, 24 deletions
diff --git a/src/World/Block.hpp b/src/World/Block.hpp
index 3613cac..f078503 100644
--- a/src/World/Block.hpp
+++ b/src/World/Block.hpp
@@ -44,6 +44,8 @@ struct Block {
uint8_t biome;
Block() : id(0), data(0), height(0), blockLight(0), skyLight(0), biome(0) {}
+ Block(uint8_t id0, uint8_t data0, unsigned height0, uint8_t blockLight0, uint8_t skyLight0, uint8_t biome0)
+ : id(id0), data(data0), height(height0), blockLight(blockLight0), skyLight(skyLight0), biome(biome0) {}
uint32_t getColor() const;
};
diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp
index 64b3988..17b5406 100644
--- a/src/World/Chunk.cpp
+++ b/src/World/Chunk.cpp
@@ -138,6 +138,28 @@ void Chunk::analyzeChunk() {
}
}
+Block Chunk::getBlock(size_t x, size_t y, size_t z) const {
+ size_t y2 = y;
+ if (y2 < maxY-1)
+ y2++;
+
+ unsigned h;
+ for (h = y; h > 0; h--) {
+ uint8_t id2 = getBlockAt(x, h, z);
+ if (id2 != 8 && id2 != 9)
+ break;
+ }
+
+ return Block(
+ getBlockAt(x, y, z),
+ getDataAt(x, y, z),
+ h,
+ getBlockLightAt(x, y2, z),
+ getSkyLightAt(x, y2, z),
+ getBiomeAt(x, z)
+ );
+}
+
Chunk::Blocks Chunk::getTopLayer() const {
size_t done = 0;
Blocks ret;
@@ -155,30 +177,7 @@ Chunk::Blocks Chunk::getTopLayer() const {
if (!Resource::BLOCK_TYPES[id].opaque)
continue;
- Block &b = ret.blocks[x][z];
-
- b.id = id;
- b.data = getDataAt(x, y, z);
-
- size_t y2 = y;
- if (y2 < maxY-1)
- y2++;
-
- b.blockLight = getBlockLightAt(x, y2, z);
- b.skyLight = getSkyLightAt(x, y2, z);
-
-
- unsigned h;
- for (h = y; h > 0; h--) {
- uint8_t id2 = getBlockAt(x, h, z);
- if (id2 != 8 && id2 != 9)
- break;
- }
-
- b.height = h;
-
- b.biome = getBiomeAt(x, z);
-
+ ret.blocks[x][z] = getBlock(x, y, z);
done++;
}
}
diff --git a/src/World/Chunk.hpp b/src/World/Chunk.hpp
index d05328c..a08f9e6 100644
--- a/src/World/Chunk.hpp
+++ b/src/World/Chunk.hpp
@@ -122,6 +122,7 @@ public:
return *sections;
}
+ Block getBlock(size_t x, size_t y, size_t z) const;
Blocks getTopLayer() const;
};