diff --git a/src/MinedMap.cpp b/src/MinedMap.cpp index bb2c46e..404927a 100644 --- a/src/MinedMap.cpp +++ b/src/MinedMap.cpp @@ -77,7 +77,8 @@ static void addChunk(Resource::Color image[DIM*DIM], uint8_t lightmap[2*DIM*DIM] const World::Chunk::Height &height = layer.v[x][z]; World::Block block = chunk.getBlock(x, height, z); - image[i] = block.getColor(biomemaps[1][1].get()[i]); + if (block.isVisible()) + image[i] = block.getColor(biomemaps[1][1].get()[i]); lightmap[2*i+1] = (1 - block.blockLight/15.f)*192; } } @@ -259,7 +260,6 @@ static void makeMap(const std::string ®iondir, const std::string &outputdir, } std::unique_ptr image(new Resource::Color[DIM*DIM]); - std::memset(image.get(), 0, 4*DIM*DIM); std::unique_ptr lightmap(new uint8_t[2*DIM*DIM]); std::memset(lightmap.get(), 0, 2*DIM*DIM); diff --git a/src/Resource/Biome.cpp b/src/Resource/Biome.cpp index 2d2dbb5..440b1d4 100644 --- a/src/Resource/Biome.cpp +++ b/src/Resource/Biome.cpp @@ -34,59 +34,35 @@ namespace MinedMap { namespace Resource { -static Biome::FloatColor operator+(const Biome::FloatColor &a, const Biome::FloatColor &b){ - return Biome::FloatColor { - a.r+b.r, - a.g+b.g, - a.b+b.b, - }; -} - -static Biome::FloatColor & operator*=(Biome::FloatColor &a, const Biome::FloatColor &b) { - a.r *= b.r; - a.g *= b.g; - a.b *= b.b; - - return a; -} - -static Biome::FloatColor operator*(float s, const Biome::FloatColor &c) { - return Biome::FloatColor { - s*c.r, - s*c.g, - s*c.b, - }; -} - -static Biome::FloatColor colorFromParams(float temp, float rain, bool grass) { - const Biome::FloatColor grassColors[3] = { +static FloatColor colorFromParams(float temp, float rain, bool grass) { + const FloatColor grassColors[3] = { {0.502f, 0.706f, 0.592f}, // lower right {0.247f, 0.012f, -0.259f}, // lower left - lower right {-0.471f, 0.086f, -0.133f}, // upper left - lower left }; - const Biome::FloatColor foliageColors[3] = { + const FloatColor foliageColors[3] = { {0.376f, 0.631f, 0.482f}, // lower right {0.306f, 0.012f, -0.317f}, // lower left - lower right {-0.580f, 0.106f, -0.165f}, // upper left - lower left }; - const Biome::FloatColor *colors = grass ? grassColors : foliageColors; + const FloatColor *colors = grass ? grassColors : foliageColors; return colors[0] + temp*colors[1] + rain*colors[2]; } -Biome::FloatColor Biome::getGrassColor(float temp, float rain) const { +FloatColor Biome::getGrassColor(float temp, float rain) const { return colorFromParams(temp, rain, true); } -Biome::FloatColor Biome::getFoliageColor(float temp, float rain) const { +FloatColor Biome::getFoliageColor(float temp, float rain) const { return colorFromParams(temp, rain, false); } -Color Biome::getBlockColor(const BlockType *type, unsigned height) const { - Biome::FloatColor c = { +FloatColor Biome::getBlockColor(const BlockType *type, unsigned height) const { + FloatColor c = { float(type->color.r), float(type->color.g), float(type->color.b), @@ -108,12 +84,11 @@ Color Biome::getBlockColor(const BlockType *type, unsigned height) const { float h = 0.5f + height * 0.005f; - return Color { - uint8_t(clamp(c.r * h, 0, 255)), - uint8_t(clamp(c.g * h, 0, 255)), - uint8_t(clamp(c.b * h, 0, 255)), - 0xff, - }; + c.r = clamp(c.r * h, 0, 255); + c.g = clamp(c.g * h, 0, 255); + c.b = clamp(c.b * h, 0, 255); + + return c; } diff --git a/src/Resource/Biome.hpp b/src/Resource/Biome.hpp index b63406a..e094f17 100644 --- a/src/Resource/Biome.hpp +++ b/src/Resource/Biome.hpp @@ -35,11 +35,6 @@ namespace Resource { class BlockType; class Biome { -public: - struct FloatColor { - float r, g, b; - }; - private: float temp, rain; FloatColor water; @@ -54,7 +49,7 @@ public: Biome(float temp0, float rain0, FloatColor water0 = {0.247f, 0.463f, 0.894f}) : temp(temp0), rain(rain0), water(water0) {} - Color getBlockColor(const BlockType *type, unsigned height) const; + FloatColor getBlockColor(const BlockType *type, unsigned height) const; }; extern const Biome *const BIOME_DEFAULT; diff --git a/src/Resource/Color.hpp b/src/Resource/Color.hpp index 2eddc0b..bad2df6 100644 --- a/src/Resource/Color.hpp +++ b/src/Resource/Color.hpp @@ -32,8 +32,39 @@ namespace MinedMap { namespace Resource { +struct FloatColor { + float r, g, b; +}; + +static inline FloatColor operator+(const FloatColor &a, const FloatColor &b){ + return FloatColor { + a.r+b.r, + a.g+b.g, + a.b+b.b, + }; +} + +static inline FloatColor & operator*=(FloatColor &a, const FloatColor &b) { + a.r *= b.r; + a.g *= b.g; + a.b *= b.b; + + return a; +} + +static inline FloatColor operator*(float s, const FloatColor &c) { + return FloatColor { + s*c.r, + s*c.g, + s*c.b, + }; +} + struct Color { uint8_t r, g, b, a; + + Color() : r(0), g(0), b(0), a(0) {} + Color(FloatColor c) : r(c.r), g(c.g), b(c.b), a(0xff) {} }; } diff --git a/src/World/Block.hpp b/src/World/Block.hpp index 3143d15..30ed186 100644 --- a/src/World/Block.hpp +++ b/src/World/Block.hpp @@ -39,10 +39,13 @@ struct Block { unsigned depth; uint8_t blockLight; + bool isVisible() const { + return type && (type->flags & BLOCK_OPAQUE); + } - Resource::Color getColor(uint8_t biome) const { - if (!type || !(type->flags & BLOCK_OPAQUE)) - return Resource::Color {}; + Resource::FloatColor getColor(uint8_t biome) const { + if (!isVisible()) + return Resource::FloatColor {}; return (Resource::BIOMES[biome] ?: Resource::BIOME_DEFAULT)->getBlockColor(type, depth); }