def render_all(self, tilesetlist, status_callback): """Render all of the tilesets in the given tilesetlist. status_callback is called periodically to update status. The callback should take the following arguments: (phase, items_completed, total_items), where total_items may be none if there is no useful estimate. """ # TODO use status callback # setup tilesetlist self.setup_tilesets(tilesetlist) # iterate through all possible phases num_phases = [tileset.get_num_phases() for tileset in tilesetlist] for phase in xrange(max(num_phases)): # construct a list of iterators to use for this phase work_iterators = [] for i, tileset in enumerate(tilesetlist): if phase < num_phases[i]: def make_work_iterator(tset, p): return ((tset, workitem) for workitem in tset.iterate_work_items(p)) work_iterators.append(make_work_iterator(tileset, phase)) # keep track of total jobs, and how many jobs are done total_jobs = 0 for tileset, phases in zip(tilesetlist, num_phases): if phase < phases: jobs_for_tileset = tileset.get_phase_length(phase) # if one is unknown, the total is unknown if jobs_for_tileset is None: total_jobs = None break else: total_jobs += jobs_for_tileset finished_jobs = 0 # do the first status update self._status_update(status_callback, phase, finished_jobs, total_jobs, force=True) # go through these iterators round-robin style for tileset, (workitem, deps) in util.roundrobin(work_iterators): self._pending_jobs.append((tileset, workitem, deps)) finished_jobs += self._dispatch_jobs() self._status_update(status_callback, phase, finished_jobs, total_jobs) # after each phase, wait for the work to finish while len(self._pending_jobs) > 0 or len(self._running_jobs) > 0: finished_jobs += self._dispatch_jobs() self._status_update(status_callback, phase, finished_jobs, total_jobs)
def render_all(self, tilesetlist, observer): """Render all of the tilesets in the given tilesetlist. status_callback is called periodically to update status. The callback should take the following arguments: (phase, items_completed, total_items), where total_items may be none if there is no useful estimate. """ # TODO use status callback # setup tilesetlist self.setup_tilesets(tilesetlist) # iterate through all possible phases num_phases = [tileset.get_num_phases() for tileset in tilesetlist] for phase in xrange(max(num_phases)): # construct a list of iterators to use for this phase work_iterators = [] for i, tileset in enumerate(tilesetlist): if phase < num_phases[i]: def make_work_iterator(tset, p): return ((tset, workitem) for workitem in tset.iterate_work_items(p)) work_iterators.append(make_work_iterator(tileset, phase)) # keep track of total jobs, and how many jobs are done total_jobs = 0 for tileset, phases in zip(tilesetlist, num_phases): if phase < phases: jobs_for_tileset = tileset.get_phase_length(phase) # if one is unknown, the total is unknown if jobs_for_tileset is None: total_jobs = None break else: total_jobs += jobs_for_tileset observer.start(total_jobs) # go through these iterators round-robin style for tileset, (workitem, deps) in util.roundrobin(work_iterators): self._pending_jobs.append((tileset, workitem, deps)) observer.add(self._dispatch_jobs()) # after each phase, wait for the work to finish while len(self._pending_jobs) > 0 or len(self._running_jobs) > 0: observer.add(self._dispatch_jobs()) observer.finish()
def __init__(self, components): self.params = pluck('params', components) self.storage = pluck('storage', components) program_parts = pluck('program', components) self.program = list(roundrobin(*program_parts))