0

Made rendernode.py POI queue world independant

This commit is contained in:
Xon
2011-03-29 07:38:49 +08:00
parent db7c61a090
commit 0caa033292
2 changed files with 41 additions and 33 deletions

View File

@@ -186,7 +186,7 @@ def main():
q.append(qtree) q.append(qtree)
#create the distributed render #create the distributed render
r = rendernode.RenderNode(q, world=w) r = rendernode.RenderNode(q)
# write out the map and web assets # write out the map and web assets
m = googlemap.MapGen(q, skipjs=options.skipjs, web_assets_hook=options.web_assets_hook) m = googlemap.MapGen(q, skipjs=options.skipjs, web_assets_hook=options.web_assets_hook)

View File

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