def natural_relight(): world = templevel.TempLevel("AnvilWorld") dim = world.getDimension() positions = [] for cx, cz in dim.chunkPositions(): chunk = dim.getChunk(cx, cz) for cy in chunk.sectionPositions(): positions.append((cx, cy, cz)) poses = iter(positions) def do_relight(): cx, cy, cz = poses.next() indices = numpy.indices((16, 16, 16), numpy.int32) indices.shape = 3, 16*16*16 indices += ([cx << 4], [cy << 4], [cz << 4]) x, y, z = indices relight.updateLightsByCoord(dim, x, y, z) # Find out how many sections we can do in `maxtime` seconds. start = time.time() count = 0 maxtime = 10 end = start + maxtime while time.time() < end: try: do_relight() except StopIteration: break count += 1 t = time.time() - start print "Relight natural terrain: %d/%d chunk-sections in %.02f seconds (%f sections per second; %dms per section)" % (count, len(positions), t, count / t, 1000 * t / count)
def perSection(): world = templevel.TempLevel("AnvilWorld") dim = world.getDimension() start = time.time() do_copy(dim, station, "section") t = time.time() - start - copyTime print "Relight manmade building (in copyBlocks, for each section): " \ "%d chunk-sections in %.02f seconds (%f sections per second; %dms per section)" \ % (len(positions), t, len(positions) / t, 1000 * t / len(positions))
""" from __future__ import absolute_import, division, print_function import logging import timeit from mceditlib.test import templevel log = logging.getLogger(__name__) def loadall(): ents = 0 for cPos in dim.chunkPositions(): chunk = dim.getChunk(*cPos) ents += len(chunk.Entities) + len(chunk.TileEntities) print("[Tile]Entities: ", ents) def saveall(): for cPos in dim.chunkPositions(): dim.getChunk(*cPos).dirty = True editor.saveChanges() editor = templevel.TempLevel("AnvilWorld_1.8") dim = editor.getDimension() print("Loaded %d chunks in %.02fms" % (dim.chunkCount(), timeit.timeit(loadall, number=1) * 1000)) print("Saved %d chunks in %.02fms" % (dim.chunkCount(), timeit.timeit(saveall, number=1) * 1000))
def manmade_relight(test): world = templevel.TempLevel("AnvilWorld") dim = world.getDimension() stationEditor = WorldEditor("test_files/station.schematic") station = stationEditor.getDimension() startCopy = time.time() box = do_copy(dim, station, False) copyTime = time.time() - startCopy print("Copy took %f seconds. Reducing relight-in-copyBlocks times by this much." % copyTime) positions = [] for cx, cz in box.chunkPositions(): for cy in box.sectionPositions(cx, cz): positions.append((cx, cy, cz)) assert len(positions) > box.chunkCount if test == "post" or test == "all": def postCopy(): # profiling start = time.time() count = 0 print("Relighting outside of copyBlocks. Updating %d cells" % (len(positions) * 16 * 16 * 16)) for cx, cy, cz in positions: indices = numpy.indices((16, 16, 16), numpy.int32) indices.shape = 3, 16*16*16 indices += ([cx << 4], [cy << 4], [cz << 4]) x, y, z = indices relight.updateLightsByCoord(dim, x, y, z) count += 1 t = time.time() - start print "Relight manmade building (outside copyBlocks): " \ "%d (out of %d) chunk-sections in %.02f seconds (%f sections per second; %dms per section)" \ % (count, len(positions), t, count / t, 1000 * t / count) postCopy() if test == "smart" or test == "all": def allSections(): world = templevel.TempLevel("AnvilWorld") dim = world.getDimension() start = time.time() do_copy(dim, station, "all") t = time.time() - start - copyTime print "Relight manmade building (in copyBlocks, all sections): " \ "%d chunk-sections in %.02f seconds (%f sections per second; %dms per section)" \ % (len(positions), t, len(positions) / t, 1000 * t / len(positions)) allSections() if test == "section" or test == "all": def perSection(): world = templevel.TempLevel("AnvilWorld") dim = world.getDimension() start = time.time() do_copy(dim, station, "section") t = time.time() - start - copyTime print "Relight manmade building (in copyBlocks, for each section): " \ "%d chunk-sections in %.02f seconds (%f sections per second; %dms per section)" \ % (len(positions), t, len(positions) / t, 1000 * t / len(positions)) perSection()
# print("Referrers:\n%s" % refs) # print("WorldEditor: _loadedChunks: %d (_pending_removals: %d)" % (lc, len(editor._loadedChunks._pending_removals))) print("[Tile]Entities: ", ents) def saveall(): for cPos in pos[cStart:cEnd]: dim.getChunk(*cPos).dirty = True editor.saveChanges() import sys if len(sys.argv) > 1: filename = sys.argv[1] else: filename = "AnvilWorld_1.8" editor = templevel.TempLevel(filename) dim = editor.getDimension() cStart = 0 cEnd = 10000 chunkCount = cEnd - cStart pos = list(dim.chunkPositions()) loadTime = timeit.timeit(loadall, number=1) print("Loaded %d chunks in %.02fms (%f cps)" % (chunkCount, loadTime * 1000, chunkCount/loadTime)) print("Cache hits: %d, misses: %d, rejects: %d, max rejects: %d, queue: %d" % ( editor._chunkDataCache.hits, editor._chunkDataCache.misses, editor._chunkDataCache.rejects, editor._chunkDataCache.max_rejects, len(editor._chunkDataCache.queue)))