updated analyze to count blocks with alternate blockData

This commit is contained in:
David Vierra 2011-03-13 16:46:09 -10:00
parent b0882314f6
commit 49b9392dd9

35
mce.py
View File

@ -430,24 +430,45 @@ class mce(object):
Also updates the level's 'SizeOnDisk' field, correcting its size in the Also updates the level's 'SizeOnDisk' field, correcting its size in the
world select menu. world select menu.
""" """
blockCounts = zeros( (256,), 'uint64') blockCounts = zeros( (4096,), 'uint64')
sizeOnDisk = 0; sizeOnDisk = 0;
print "Analyzing {0} chunks...".format(self.level.chunkCount) print "Analyzing {0} chunks...".format(self.level.chunkCount)
#for input to bincount, create an array of uint16s by
#shifting the data left and adding the blocks
for i, cPos in enumerate(self.level.allChunks, 1): for i, cPos in enumerate(self.level.allChunks, 1):
ch = self.level.getChunk(*cPos); ch = self.level.getChunk(*cPos);
counts = bincount(ch.Blocks.ravel()) btypes = numpy.array(ch.Data.ravel(), dtype='uint16')
btypes <<= 8
btypes += ch.Blocks.ravel()
counts = bincount(btypes)
blockCounts[:counts.shape[0]] += counts blockCounts[:counts.shape[0]] += counts
sizeOnDisk += ch.compressedSize(); sizeOnDisk += ch.compressedSize();
ch.unload(); ch.unload();
if i % 100 == 0: if i % 100 == 0:
print "Chunk {0}...".format( i ) logging.info( "Chunk {0}...".format( i ) )
for blockID in range(256):
block = self.level.materials.blockWithID(blockID, 0)
if block.hasAlternate:
for data in range(16):
i = (data << 8) + blockID
if blockCounts[i]:
idstring = "({id}:{data})".format(id=blockID, data=data)
print "{idstring:9} {name:30}: {count:<10}".format(
idstring=idstring, name=self.level.materials.blockWithID(blockID, data).name, count=blockCounts[i]);
else:
count = int(sum( blockCounts[(d<<8)+blockID] for d in range(16) ))
if count:
idstring = "({id})".format(id=blockID)
print "{idstring:9} {name:30}: {count:<10}".format(
idstring=idstring, name=self.level.materials.blockWithID(blockID, 0).name, count=count);
for i in range(256):
if blockCounts[i]:
print "{0:30}: {1:10}".format(self.level.materials.names[i], blockCounts[i]);
print "Size on disk: {0:.3}MB".format(sizeOnDisk / 1048576.0) print "Size on disk: {0:.3}MB".format(sizeOnDisk / 1048576.0)
self.level.SizeOnDisk = sizeOnDisk self.level.SizeOnDisk = sizeOnDisk
self.needsSave = True self.needsSave = True