mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-07-01 13:29:06 +02:00
BlockType: replace list of booleans with flags bitfield
This commit is contained in:
parent
446e74791f
commit
ef4b6eac02
8 changed files with 800 additions and 787 deletions
|
@ -99,11 +99,11 @@ Color Biome::getBlockColor(const BlockType *type, unsigned height) const {
|
|||
float t = clamp(temp - std::max(0.0f, (height-64)/600.0f), 0, 1);
|
||||
float r = clamp(rain, 0, 1) * t;
|
||||
|
||||
if (type->grass)
|
||||
if (type->flags & BLOCK_GRASS)
|
||||
c *= getGrassColor(t, r);
|
||||
if (type->foliage)
|
||||
if (type->flags & BLOCK_FOLIAGE)
|
||||
c *= getFoliageColor(t, r);
|
||||
if (type->blue)
|
||||
if (type->flags & BLOCK_WATER)
|
||||
c *= getWaterColor(t, r);
|
||||
|
||||
float h = 0.5f + height * 0.005f;
|
||||
|
|
|
@ -33,6 +33,11 @@
|
|||
namespace MinedMap {
|
||||
namespace Resource {
|
||||
|
||||
#define BLOCK_OPAQUE (1u << 0)
|
||||
#define BLOCK_GRASS (1u << 1)
|
||||
#define BLOCK_FOLIAGE (1u << 2)
|
||||
#define BLOCK_WATER (1u << 3)
|
||||
|
||||
struct BlockType {
|
||||
private:
|
||||
static const std::unordered_map<std::string, BlockType> Types;
|
||||
|
@ -40,10 +45,7 @@ private:
|
|||
public:
|
||||
static const BlockType * lookup(const std::string &name);
|
||||
|
||||
bool opaque;
|
||||
bool grass;
|
||||
bool foliage;
|
||||
bool blue;
|
||||
uint8_t flags;
|
||||
struct {
|
||||
uint8_t r, g, b;
|
||||
} color;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -42,7 +42,7 @@ struct Block {
|
|||
|
||||
|
||||
Resource::Color getColor() const {
|
||||
if (!type || !type->opaque)
|
||||
if (!type || !(type->flags & BLOCK_OPAQUE))
|
||||
return Resource::Color {};
|
||||
|
||||
return (Resource::BIOMES[biome] ?: Resource::BIOME_DEFAULT)->getBlockColor(type, height);
|
||||
|
|
|
@ -84,7 +84,7 @@ bool Chunk::getBlock(Block *block, const Section *section, size_t x, size_t y, s
|
|||
return false;
|
||||
|
||||
const Resource::BlockType *type = section->getBlockStateAt(x, y, z);
|
||||
if (!type || !type->opaque)
|
||||
if (!type || !(type->flags & BLOCK_OPAQUE))
|
||||
return false;
|
||||
|
||||
if (!block->type) {
|
||||
|
@ -93,7 +93,7 @@ bool Chunk::getBlock(Block *block, const Section *section, size_t x, size_t y, s
|
|||
block->biome = getBiome(x, y, z);
|
||||
}
|
||||
|
||||
if (type->blue)
|
||||
if (type->flags & BLOCK_WATER)
|
||||
return false;
|
||||
|
||||
block->height = SIZE*section->getY() + y;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue