0

world: optimise bad block translation code

Makes Overviewer like 45% faster lol
This commit is contained in:
Nicolas F
2019-07-09 17:24:42 +02:00
parent e0e33a9acb
commit a5071663cd

View File

@@ -1164,40 +1164,26 @@ class RegionSet(object):
def _get_blockdata_v113(self, section, unrecognized_block_types): def _get_blockdata_v113(self, section, unrecognized_block_types):
# Translate each entry in the palette to a 1.2-era (block, data) int pair. # Translate each entry in the palette to a 1.2-era (block, data) int pair.
num_palette_entries = len(section['Palette']) num_palette_entries = len(section['Palette'])
palette_translated = [] # (block, data) pairs, num_palette_entries in length translated_blocks = numpy.zeros((num_palette_entries,), dtype=numpy.uint16) # block IDs
palette_block_counts = [] # ints, num_palette_entries in length translated_data = numpy.zeros((num_palette_entries,), dtype=numpy.uint8) # block data
unrecognized_palette_entries = []
for i in range(num_palette_entries): for i in range(num_palette_entries):
key = section['Palette'][i] key = section['Palette'][i]
palette_block_counts.append(0)
try: try:
palette_translated.append(self._get_block(key)) translated_blocks[i], translated_data[i] = self._get_block(key)
except KeyError as e: except KeyError:
# Unknown block type? Track it, treat it as air, and move on. pass # We already have initialised arrays with 0 (= air)
unrecognized_palette_entries.append(i)
palette_translated.append(self._blockmap['minecraft:air'])
# Turn the BlockStates array into a 16x16x16 numpy matrix of shorts. # Turn the BlockStates array into a 16x16x16 numpy matrix of shorts.
blocks = numpy.zeros((4096,), dtype=numpy.uint16) blocks = numpy.zeros((4096,), dtype=numpy.uint16)
data = numpy.zeros((4096,), dtype=numpy.uint8) data = numpy.zeros((4096,), dtype=numpy.uint8)
block_states = self._packed_longarray_to_shorts(section['BlockStates'], 4096) block_states = self._packed_longarray_to_shorts(section['BlockStates'], 4096)
for i in range(4096): blocks[::1] = translated_blocks[block_states]
palette_index = block_states[i] data[::1] = translated_data[block_states]
(blocks[i], data[i]) = palette_translated[palette_index]
palette_block_counts[palette_index] += 1
# Turn the Data array into a 16x16x16 matrix, same as SkyLight # Turn the Data array into a 16x16x16 matrix, same as SkyLight
blocks = blocks.reshape((16, 16, 16)) blocks = blocks.reshape((16, 16, 16))
data = data.reshape((16, 16, 16)) data = data.reshape((16, 16, 16))
for i in unrecognized_palette_entries:
if palette_block_counts[i] > 0:
palette_entry = section['Palette'][i]
k = palette_entry['Name']
if 'Properties' in palette_entry:
k += " %s" % str(palette_entry['Properties'])
unrecognized_block_types[k] = unrecognized_block_types.get(k, 0) + palette_block_counts[i]
return (blocks, data) return (blocks, data)
def _get_blockdata_v112(self, section): def _get_blockdata_v112(self, section):