mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01: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
|
@ -209,8 +209,8 @@
|
|||
"brown_wall_banner": null,
|
||||
"brown_wool": {},
|
||||
"bubble_column": {
|
||||
"blue": true,
|
||||
"texture": "water_still"
|
||||
"texture": "water_still",
|
||||
"water": true
|
||||
},
|
||||
"bubble_coral": null,
|
||||
"bubble_coral_block": {},
|
||||
|
@ -1428,8 +1428,8 @@
|
|||
"warped_wall_sign": null,
|
||||
"warped_wart_block": {},
|
||||
"water": {
|
||||
"blue": true,
|
||||
"texture": "water_still"
|
||||
"texture": "water_still",
|
||||
"water": true
|
||||
},
|
||||
"weeping_vines": {},
|
||||
"weeping_vines_plant": {},
|
||||
|
|
|
@ -42,7 +42,7 @@ for name, info in blocks.items():
|
|||
'opaque': False,
|
||||
'grass': False,
|
||||
'foliage': False,
|
||||
'blue': False,
|
||||
'water': False,
|
||||
}
|
||||
|
||||
if info is None:
|
||||
|
@ -54,7 +54,7 @@ for name, info in blocks.items():
|
|||
output[id]['opaque'] = True
|
||||
output[id]['grass'] = info.get('grass', False)
|
||||
output[id]['foliage'] = info.get('foliage', False)
|
||||
output[id]['blue'] = info.get('blue', False)
|
||||
output[id]['water'] = info.get('water', False)
|
||||
|
||||
with open(sys.argv[3], 'w') as f:
|
||||
json.dump(output, f)
|
||||
|
|
|
@ -15,12 +15,23 @@ output = {}
|
|||
|
||||
with open(sys.argv[2], 'w') as f:
|
||||
for name, info in colors.items():
|
||||
print('{"%s", {%s, %s, %s, %s, {%u, %u, %u}}},' % (
|
||||
flags = []
|
||||
if info['opaque']:
|
||||
flags.append('BLOCK_OPAQUE')
|
||||
if info['grass']:
|
||||
flags.append('BLOCK_GRASS')
|
||||
if info['foliage']:
|
||||
flags.append('BLOCK_FOLIAGE')
|
||||
if info['water']:
|
||||
flags.append('BLOCK_WATER')
|
||||
if flags:
|
||||
flags = '|'.join(flags)
|
||||
else:
|
||||
flags = '0'
|
||||
|
||||
print('{"%s", {%s, {%u, %u, %u}}},' % (
|
||||
name,
|
||||
['false', 'true'][info['opaque']],
|
||||
['false', 'true'][info['grass']],
|
||||
['false', 'true'][info['foliage']],
|
||||
['false', 'true'][info['blue']],
|
||||
flags,
|
||||
info['color']['r'],
|
||||
info['color']['g'],
|
||||
info['color']['b'],
|
||||
|
|
|
@ -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
Reference in a new issue