0

Only pass the part of the dict we need to the chunk renderer

This commit is contained in:
Ryan McCue
2010-12-13 20:34:17 +10:00
parent 211f489f66
commit 8ec7986353
2 changed files with 21 additions and 12 deletions

View File

@@ -112,12 +112,12 @@ def iterate_chunkblocks(xoff,yoff):
transparent_blocks = set([0, 6, 8, 9, 18, 20, 37, 38, 39, 40, 44, 50, 51, 52, 53, transparent_blocks = set([0, 6, 8, 9, 18, 20, 37, 38, 39, 40, 44, 50, 51, 52, 53,
59, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 81, 83, 85]) 59, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 81, 83, 85])
def render_and_save(chunkfile, cachedir, worldobj, cave=False, queue=None): def render_and_save(chunkfile, cachedir, worldobj, cached, cave=False, queue=None):
"""Used as the entry point for the multiprocessing workers (since processes """Used as the entry point for the multiprocessing workers (since processes
can't target bound methods) or to easily render and save one chunk can't target bound methods) or to easily render and save one chunk
Returns the image file location""" Returns the image file location"""
a = ChunkRenderer(chunkfile, cachedir, worldobj, queue) a = ChunkRenderer(chunkfile, cachedir, worldobj, cached, queue)
try: try:
return a.render_and_save(cave) return a.render_and_save(cave)
except ChunkCorrupt: except ChunkCorrupt:
@@ -140,7 +140,7 @@ class ChunkCorrupt(Exception):
pass pass
class ChunkRenderer(object): class ChunkRenderer(object):
def __init__(self, chunkfile, cachedir, worldobj, queue): def __init__(self, chunkfile, cachedir, cached, worldobj, queue):
"""Make a new chunk renderer for the given chunkfile. """Make a new chunk renderer for the given chunkfile.
chunkfile should be a full path to the .dat file to process chunkfile should be a full path to the .dat file to process
cachedir is a directory to save the resulting chunk images to cachedir is a directory to save the resulting chunk images to
@@ -169,7 +169,7 @@ class ChunkRenderer(object):
moredirs, dir2 = os.path.split(destdir) moredirs, dir2 = os.path.split(destdir)
_, dir1 = os.path.split(moredirs) _, dir1 = os.path.split(moredirs)
self.cachedir = os.path.join(cachedir, dir1, dir2) self.cachedir = os.path.join(cachedir, dir1, dir2)
self.dirbits = (dir1, dir2) self.cached = cached
if self.world.useBiomeData: if self.world.useBiomeData:
@@ -304,9 +304,9 @@ class ChunkRenderer(object):
def find_oldimage(self, cave): def find_oldimage(self, cave):
# Get the name of the existing image. # Get the name of the existing image.
oldimg = oldimg_path = None oldimg = oldimg_path = None
key = ".".join((self.dirbits[0], self.dirbits[1], self.blockid, "cave" if cave else "nocave")) key = ".".join((self.blockid, "cave" if cave else "nocave"))
if key in self.world.cached: if key in self.cached:
oldimg_path = self.world.cached[key] oldimg_path = self.cached[key]
_, oldimg = os.path.split(oldimg_path) _, oldimg = os.path.split(oldimg_path)
logging.debug("Found cached image {0}".format(oldimg)) logging.debug("Found cached image {0}".format(oldimg))
return oldimg, oldimg_path return oldimg, oldimg_path

View File

@@ -36,6 +36,7 @@ and for extracting information about available worlds
""" """
base36decode = functools.partial(int, base=36) base36decode = functools.partial(int, base=36)
cached = collections.defaultdict(dict)
def _convert_coords(chunks): def _convert_coords(chunks):
@@ -108,7 +109,6 @@ class WorldRenderer(object):
textures.prepareBiomeData(worlddir) textures.prepareBiomeData(worlddir)
self.chunklist = chunklist self.chunklist = chunklist
self.cached = collections.defaultdict(dict)
# In order to avoid having to look up the cache file names in # In order to avoid having to look up the cache file names in
# ChunkRenderer, get them all and store them here # ChunkRenderer, get them all and store them here
@@ -119,8 +119,9 @@ class WorldRenderer(object):
dirname, dir_b = os.path.split(root) dirname, dir_b = os.path.split(root)
_, dir_a = os.path.split(dirname) _, dir_a = os.path.split(dirname)
_, x, z, cave, _ = filename.split('.', 4) _, x, z, cave, _ = filename.split('.', 4)
bits = '.'.join((dir_a, dir_b, x, z, cave)) dir = '/'.join((dir_a, dir_b))
self.cached[bits] = os.path.join(root, filename) bits = '.'.join((x, z, cave))
cached[dir][bits] = os.path.join(root, filename)
# stores Points Of Interest to be mapped with markers # stores Points Of Interest to be mapped with markers
@@ -294,7 +295,11 @@ class WorldRenderer(object):
results[(col, row)] = imgpath results[(col, row)] = imgpath
continue continue
result = chunk.render_and_save(chunkfile, self.cachedir, self, cave=self.caves, queue=q) moredirs, dir2 = os.path.split(os.path.dirname(self.chunkfile))
dir1 = os.path.basename(moredirs)
cachename = '/'.join(dir1, dir2)
result = chunk.render_and_save(chunkfile, self.cachedir, self, cached[chunkname], queue=q)
results[(col, row)] = result results[(col, row)] = result
if i > 0: if i > 0:
try: try:
@@ -320,8 +325,12 @@ class WorldRenderer(object):
results[(col, row)] = imgpath results[(col, row)] = imgpath
continue continue
moredirs, dir2 = os.path.split(os.path.dirname(self.chunkfile))
dir1 = os.path.basename(moredirs)
cachename = '/'.join(dir1, dir2)
result = pool.apply_async(chunk.render_and_save, result = pool.apply_async(chunk.render_and_save,
args=(chunkfile,self.cachedir,self), args=(chunkfile,self.cachedir,self, cached[chunkname]),
kwds=dict(cave=self.caves, queue=q)) kwds=dict(cave=self.caves, queue=q))
asyncresults.append((col, row, result)) asyncresults.append((col, row, result))