diff --git a/overviewer.py b/overviewer.py index a161f22..0e012fe 100755 --- a/overviewer.py +++ b/overviewer.py @@ -186,7 +186,7 @@ def main(): q.append(qtree) #create the distributed render - r = rendernode.RenderNode(q, world=w) + r = rendernode.RenderNode(q) # write out the map and web assets m = googlemap.MapGen(q, skipjs=options.skipjs, web_assets_hook=options.web_assets_hook) diff --git a/rendernode.py b/rendernode.py index c993a17..f61a986 100644 --- a/rendernode.py +++ b/rendernode.py @@ -84,7 +84,7 @@ def roundrobin(iterables): class RenderNode(object): - def __init__(self, quadtrees, world): + def __init__(self, quadtrees): """Distributes the rendering of a list of quadtrees.""" if not len(quadtrees) > 0: @@ -92,16 +92,21 @@ class RenderNode(object): self.quadtrees = quadtrees #bind an index value to the quadtree so we can find it again + #and figure out which worlds are where i = 0 + self.worlds = [] for q in quadtrees: q._render_index = i - i += 1 + i += 1 + if q.world not in self.worlds: + self.worlds.append(q.world) + manager = multiprocessing.Manager() # queue for receiving interesting events from the renderer # (like the discovery of signs! - self.poi_q = multiprocessing.Queue() - - self.world = world + #stash into the world object like we stash an index into the quadtree + for world in self.worlds: + world.poi_q = manager.Queue() def print_statusline(self, complete, total, level, unconditional=False): @@ -168,18 +173,19 @@ class RenderNode(object): timestamp = timestamp2 count_to_remove = (1000//batch_size) if count_to_remove < len(results): - try: - while (1): - # an exception will break us out of this loop - item = self.poi_q.get(block=False) - if item[0] == "newpoi": - if item[1] not in self.world.POI: - #print "got an item from the queue!" - self.world.POI.append(item[1]) - elif item[0] == "removePOI": - self.world.persistentData['POI'] = filter(lambda x: x['chunk'] != item[1], self.world.persistentData['POI']) - except Queue.Empty: - pass + for world in self.worlds: + try: + while (1): + # an exception will break us out of this loop + item = world.poi_q.get(block=False) + if item[0] == "newpoi": + if item[1] not in world.POI: + #print "got an item from the queue!" + world.POI.append(item[1]) + elif item[0] == "removePOI": + world.persistentData['POI'] = filter(lambda x: x['chunk'] != item[1], world.persistentData['POI']) + except Queue.Empty: + pass while count_to_remove > 0: count_to_remove -= 1 complete += results.popleft().get() @@ -195,18 +201,19 @@ class RenderNode(object): while len(results) > 0: complete += results.popleft().get() self.print_statusline(complete, total, 1) - try: - while (1): - # an exception will break us out of this loop - item = self.poi_q.get(block=False) - if item[0] == "newpoi": - if item[1] not in self.world.POI: - #print "got an item from the queue!" - self.world.POI.append(item[1]) - elif item[0] == "removePOI": - self.world.persistentData['POI'] = filter(lambda x: x['chunk'] != item[1], self.world.persistentData['POI']) - except Queue.Empty: - pass + for world in self.worlds: + try: + while (1): + # an exception will break us out of this loop + item = world.poi_q.get(block=False) + if item[0] == "newpoi": + if item[1] not in world.POI: + #print "got an item from the queue!" + world.POI.append(item[1]) + elif item[0] == "removePOI": + world.persistentData['POI'] = filter(lambda x: x['chunk'] != item[1], world.persistentData['POI']) + except Queue.Empty: + pass self.print_statusline(complete, total, 1, True) @@ -271,10 +278,10 @@ class RenderNode(object): jobcount += 1 if jobcount >= batch_size: jobcount = 0 - yield pool.apply_async(func=render_worldtile_batch, args= [batch, self.poi_q]) + yield pool.apply_async(func=render_worldtile_batch, args= [batch]) batch = [] if jobcount > 0: - yield pool.apply_async(func=render_worldtile_batch, args= [batch, self.poi_q]) + yield pool.apply_async(func=render_worldtile_batch, args= [batch]) def _apply_render_inntertile(self, pool, zoom,batch_size): """Same as _apply_render_worltiles but for the inntertile routine. @@ -303,7 +310,7 @@ class RenderNode(object): yield pool.apply_async(func=render_innertile_batch, args= [batch]) @catch_keyboardinterrupt -def render_worldtile_batch(batch, poi_queue): +def render_worldtile_batch(batch): global child_rendernode rendernode = child_rendernode count = 0 @@ -316,6 +323,7 @@ def render_worldtile_batch(batch, poi_queue): rowstart = job[3] rowend = job[4] path = job[5] + poi_queue = quadtree.world.poi_q path = quadtree.full_tiledir+os.sep+path # (even if tilechunks is empty, render_worldtile will delete # existing images if appropriate)