0

Shuffle around wall IDs, change wall check

Previously, walls were all numbered at 21000+. This is bad because
our blockmap is an array, so this caused our blockmap to take up
80 MiB of RAM in each worker process.

This commit changes the wall numbering, and exploits some bitmasking
to have the wall check run in constant time no matter how many walls
there are. This is done with a simple mask and xor to check the prefix.

RAM usage for the blockmap thus drops to like 44 MiB.

This is in preparation for adding more walls for 1.16.
This commit is contained in:
Nicolas F
2020-07-13 19:15:47 +02:00
parent a3e4812ca9
commit fcb3f2644d
6 changed files with 60 additions and 68 deletions

View File

@@ -58,6 +58,13 @@ bool block_class_is_subset(
return false;
}
bool block_class_is_wall(mc_block_t block) {
mc_block_t mask = 0b11111111;
mc_block_t prefix = 0b111 << 8; // 1792 is the starting offset
// if the xor zeroes all bits, the prefix must've matched.
return (block & ~mask) ^ prefix == 0;
}
const mc_block_t block_class_stair[] = {
block_oak_stairs,
block_brick_stairs,
@@ -252,20 +259,3 @@ const mc_block_t block_class_alt_height[] = {
block_purpur_slab,
block_wooden_slab};
const size_t block_class_alt_height_len = COUNT_OF(block_class_alt_height);
const mc_block_t block_class_wall[] = {
block_andesite_wall,
block_brick_wall,
block_cobblestone_wall,
block_diorite_wall,
block_end_stone_brick_wall,
block_granite_wall,
block_mossy_cobblestone_wall,
block_mossy_stone_brick_wall,
block_nether_brick_wall,
block_prismarine_wall,
block_red_nether_brick_wall,
block_red_sandstone_wall,
block_sandstone_wall,
block_stone_brick_wall};
const size_t block_class_wall_len = COUNT_OF(block_class_wall);

View File

@@ -28,6 +28,8 @@ bool block_class_is_subset(
const mc_block_t block_class[],
size_t block_class_len);
bool block_class_is_wall(mc_block_t block);
extern const mc_block_t block_class_stair[];
extern const size_t block_class_stair_len;
@@ -46,7 +48,4 @@ extern const size_t block_class_ancil_len;
extern const mc_block_t block_class_alt_height[];
extern const size_t block_class_alt_height_len;
extern const mc_block_t block_class_wall[];
extern const size_t block_class_wall_len;
#endif

View File

@@ -354,7 +354,7 @@ generate_pseudo_data(RenderState* state, uint16_t ancilData) {
}
}
return data;
} else if (block_class_is_subset(state->block, block_class_wall, block_class_wall_len)) {
} else if (block_class_is_wall(state->block)) {
/* check for walls and add one bit with the type of wall (mossy or cobblestone)*/
if (ancilData == 0x1) {
return check_adjacent_blocks(state, x, y, z, state->block) | 0x10;

View File

@@ -268,6 +268,26 @@ enum mc_block_id {
block_blackstone = 1004,
block_netherite_block = 1005,
// adding a gap in the numbering of walls to keep them all
// in one numbering block starting at 1792
// all blocks between 1792 and 2047 are considered walls
// this is because our check looks for the prefix 0b11100000000
block_andesite_wall = 1792,
block_brick_wall = 1793,
block_cobblestone_wall = 1794,
block_diorite_wall = 1795,
block_end_stone_brick_wall = 1796,
block_granite_wall = 1797,
block_mossy_cobblestone_wall = 1798,
block_mossy_stone_brick_wall = 1799,
block_nether_brick_wall = 1800,
block_prismarine_wall = 1801,
block_red_nether_brick_wall = 1802,
block_red_sandstone_wall = 1803,
block_sandstone_wall = 1804,
block_stone_brick_wall = 1805,
// end of walls
block_prismarine_stairs = 11337,
block_dark_prismarine_stairs = 11338,
block_prismarine_brick_stairs = 11339,
@@ -344,23 +364,7 @@ enum mc_block_id {
block_honey_block = 11504,
block_sweet_berry_bush = 11505,
block_campfire = 11506,
block_bell = 11507,
// adding a gap in the numbering of walls to keep them all
// in one numbering block starting at 21000
block_andesite_wall = 21000,
block_brick_wall = 21001,
block_cobblestone_wall = 21002,
block_diorite_wall = 21003,
block_end_stone_brick_wall = 21004,
block_granite_wall = 21005,
block_mossy_cobblestone_wall = 21006,
block_mossy_stone_brick_wall = 21007,
block_nether_brick_wall = 21008,
block_prismarine_wall = 21009,
block_red_nether_brick_wall = 21010,
block_red_sandstone_wall = 21011,
block_sandstone_wall = 21012,
block_stone_brick_wall = 21013
block_bell = 11507
};
typedef uint16_t mc_block_t;

View File

@@ -4691,24 +4691,24 @@ def beacon(self, blockid, data):
# cobblestone and mossy cobblestone walls, chorus plants, mossy stone brick walls
# one additional bit of data value added for mossy and cobblestone
@material(blockid=[199]+list(range(21000,21013+1)), data=list(range(32)), transparent=True, nospawn=True)
@material(blockid=[199]+list(range(1792, 1805 + 1)), data=list(range(32)), transparent=True, nospawn=True)
def cobblestone_wall(self, blockid, data):
walls_id_to_tex = {
199: "assets/minecraft/textures/block/chorus_plant.png", # chorus plants
21000: "assets/minecraft/textures/block/andesite.png",
21001: "assets/minecraft/textures/block/bricks.png",
21002: "assets/minecraft/textures/block/cobblestone.png",
21003: "assets/minecraft/textures/block/diorite.png",
21004: "assets/minecraft/textures/block/end_stone_bricks.png",
21005: "assets/minecraft/textures/block/granite.png",
21006: "assets/minecraft/textures/block/mossy_cobblestone.png",
21007: "assets/minecraft/textures/block/mossy_stone_bricks.png",
21008: "assets/minecraft/textures/block/nether_bricks.png",
21009: "assets/minecraft/textures/block/prismarine.png",
21010: "assets/minecraft/textures/block/red_nether_bricks.png",
21011: "assets/minecraft/textures/block/red_sandstone.png",
21012: "assets/minecraft/textures/block/sandstone.png",
21013: "assets/minecraft/textures/block/stone_bricks.png"
1792: "assets/minecraft/textures/block/andesite.png",
1793: "assets/minecraft/textures/block/bricks.png",
1794: "assets/minecraft/textures/block/cobblestone.png",
1795: "assets/minecraft/textures/block/diorite.png",
1796: "assets/minecraft/textures/block/end_stone_bricks.png",
1797: "assets/minecraft/textures/block/granite.png",
1798: "assets/minecraft/textures/block/mossy_cobblestone.png",
1799: "assets/minecraft/textures/block/mossy_stone_bricks.png",
1800: "assets/minecraft/textures/block/nether_bricks.png",
1801: "assets/minecraft/textures/block/prismarine.png",
1802: "assets/minecraft/textures/block/red_nether_bricks.png",
1803: "assets/minecraft/textures/block/red_sandstone.png",
1804: "assets/minecraft/textures/block/sandstone.png",
1805: "assets/minecraft/textures/block/stone_bricks.png"
}
t = self.load_image_texture(walls_id_to_tex[blockid]).copy()

View File

@@ -814,21 +814,20 @@ class RegionSet(object):
'minecraft:campfire': (11506, 0),
'minecraft:bell': (11507, 0),
# adding a gap in the numbering of walls to keep them all
# in one numbering block starting at 21000
'minecraft:andesite_wall': (21000, 0),
'minecraft:brick_wall': (21001, 0),
'minecraft:cobblestone_wall': (21002, 0),
'minecraft:diorite_wall': (21003, 0),
'minecraft:end_stone_brick_wall': (21004, 0),
'minecraft:granite_wall': (21005, 0),
'minecraft:mossy_cobblestone_wall': (21006, 0),
'minecraft:mossy_stone_brick_wall': (21007, 0),
'minecraft:nether_brick_wall': (21008, 0),
'minecraft:prismarine_wall': (21009, 0),
'minecraft:red_nether_brick_wall': (21010, 0),
'minecraft:red_sandstone_wall': (21011, 0),
'minecraft:sandstone_wall': (21012, 0),
'minecraft:stone_brick_wall': (21013, 0),
'minecraft:andesite_wall': (1792, 0),
'minecraft:brick_wall': (1793, 0),
'minecraft:cobblestone_wall': (1794, 0),
'minecraft:diorite_wall': (1795, 0),
'minecraft:end_stone_brick_wall': (1796, 0),
'minecraft:granite_wall': (1797, 0),
'minecraft:mossy_cobblestone_wall': (1798, 0),
'minecraft:mossy_stone_brick_wall': (1799, 0),
'minecraft:nether_brick_wall': (1800, 0),
'minecraft:prismarine_wall': (1801, 0),
'minecraft:red_nether_brick_wall': (1802, 0),
'minecraft:red_sandstone_wall': (1803, 0),
'minecraft:sandstone_wall': (1804, 0),
'minecraft:stone_brick_wall': (1805, 0),
}
colors = [ 'white', 'orange', 'magenta', 'light_blue',