0

Inline render_to_image since it was just creating a ChunkRender object can calling it.

Moved biome init code out of chunk.py and into rendernode.py for per-worker initialization
This commit is contained in:
Xon
2011-03-28 12:48:18 +08:00
parent d2252acfe6
commit d547727556
3 changed files with 17 additions and 14 deletions

View File

@@ -177,8 +177,8 @@ class ChunkRenderer(object):
self.queue = queue self.queue = queue
self.regionfile = worldobj.get_region_path(*chunkcoords) self.regionfile = worldobj.get_region_path(*chunkcoords)
if not os.path.exists(self.regionfile): #if not os.path.exists(self.regionfile):
raise ValueError("Could not find regionfile: %s" % self.regionfile) # raise ValueError("Could not find regionfile: %s" % self.regionfile)
## TODO TODO all of this class ## TODO TODO all of this class
@@ -187,7 +187,7 @@ class ChunkRenderer(object):
#chunkcoords = filename_split[1:3] #chunkcoords = filename_split[1:3]
#self.coords = map(world.base36decode, chunkcoords) #self.coords = map(world.base36decode, chunkcoords)
self.blockid = "%d.%d" % chunkcoords #self.blockid = "%d.%d" % chunkcoords
# chunk coordinates (useful to converting local block coords to # chunk coordinates (useful to converting local block coords to
# global block coords) # global block coords)
@@ -197,12 +197,6 @@ class ChunkRenderer(object):
self.world = worldobj self.world = worldobj
self.rendermode = rendermode self.rendermode = rendermode
if self.world.useBiomeData:
# make sure we've at least *tried* to load the color arrays in this process...
textures.prepareBiomeData(self.world.worlddir)
if not textures.grasscolor or not textures.foliagecolor:
raise Exception("Can't find grasscolor.png or foliagecolor.png")
def _load_level(self): def _load_level(self):
"""Loads and returns the level structure""" """Loads and returns the level structure"""
if not hasattr(self, "_level"): if not hasattr(self, "_level"):

View File

@@ -434,6 +434,8 @@ class QuadtreeGen(object):
# Compile this image # Compile this image
tileimg = Image.new("RGBA", (width, height), (38,92,255,0)) tileimg = Image.new("RGBA", (width, height), (38,92,255,0))
world = self.world
rendermode = self.rendermode
# col colstart will get drawn on the image starting at x coordinates -(384/2) # col colstart will get drawn on the image starting at x coordinates -(384/2)
# row rowstart will get drawn on the image starting at y coordinates -(192/2) # row rowstart will get drawn on the image starting at y coordinates -(192/2)
for col, row, chunkx, chunky, regionfile in chunks: for col, row, chunkx, chunky, regionfile in chunks:
@@ -441,8 +443,10 @@ class QuadtreeGen(object):
ypos = -96 + (row-rowstart)*96 ypos = -96 + (row-rowstart)*96
# draw the chunk! # draw the chunk!
# TODO POI queue a = chunk.ChunkRenderer((chunkx, chunky), world, rendermode, poi_queue)
chunk.render_to_image((chunkx, chunky), tileimg, (xpos, ypos), self, False, poi_queue) a.chunk_render(tileimg, xpos, ypos, None)
# chunk.render_to_image((chunkx, chunky), tileimg, (xpos, ypos), self, False, None)
# Save them # Save them
tileimg.save(imgpath) tileimg.save(imgpath)

View File

@@ -60,6 +60,12 @@ def pool_initializer(rendernode):
#stash the quadtree objects in a global variable after fork() for windows compat. #stash the quadtree objects in a global variable after fork() for windows compat.
global child_rendernode global child_rendernode
child_rendernode = rendernode child_rendernode = rendernode
for quadtree in rendernode.quadtrees:
if quadtree.world.useBiomeData:
# make sure we've at least *tried* to load the color arrays in this process...
textures.prepareBiomeData(quadtree.world.worlddir)
if not textures.grasscolor or not textures.foliagecolor:
raise Exception("Can't find grasscolor.png or foliagecolor.png")
#http://docs.python.org/library/itertools.html #http://docs.python.org/library/itertools.html
def roundrobin(iterables): def roundrobin(iterables):
@@ -119,8 +125,7 @@ class RenderNode(object):
# Create a pool # Create a pool
if procs == 1: if procs == 1:
pool = FakePool() pool = FakePool()
global child_rendernode pool_initializer(self)
child_rendernode = self
else: else:
pool = multiprocessing.Pool(processes=procs,initializer=pool_initializer,initargs=(self,)) pool = multiprocessing.Pool(processes=procs,initializer=pool_initializer,initargs=(self,))
#warm up the pool so it reports all the worker id's #warm up the pool so it reports all the worker id's