tileset: Render in expanding order from center
This commit is contained in:
@@ -1311,7 +1311,7 @@ class RendertileSet(object):
|
|||||||
# tree
|
# tree
|
||||||
self.children = [False] * 4
|
self.children = [False] * 4
|
||||||
|
|
||||||
def posttraversal(self):
|
def posttraversal(self, offset=(0,0)):
|
||||||
"""Returns an iterator over tile paths for every tile in the
|
"""Returns an iterator over tile paths for every tile in the
|
||||||
set, including the explictly marked render-tiles, as well as the
|
set, including the explictly marked render-tiles, as well as the
|
||||||
implicitly marked ancestors of those render-tiles. Returns in
|
implicitly marked ancestors of those render-tiles. Returns in
|
||||||
@@ -1319,20 +1319,19 @@ class RendertileSet(object):
|
|||||||
yielded after their dependencies.
|
yielded after their dependencies.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return (tuple(reversed(rpath)) for rpath in self._posttraversal_helper())
|
return (tuple(reversed(rpath)) for rpath in self._posttraversal_helper(offset=offset))
|
||||||
|
|
||||||
def _posttraversal_helper(self):
|
def _posttraversal_helper(self, offset=(0,0)):
|
||||||
"""Each node returns an iterator over lists of reversed paths"""
|
"""Each node returns an iterator over lists of reversed paths"""
|
||||||
if self.depth == 1:
|
if self.depth == 1:
|
||||||
# Base case
|
# Base case
|
||||||
if self.children[0]: yield [0]
|
for childnum, _ in distance_sort(xrange(4), offset):
|
||||||
if self.children[1]: yield [1]
|
if self.children[childnum]:
|
||||||
if self.children[2]: yield [2]
|
yield [childnum]
|
||||||
if self.children[3]: yield [3]
|
|
||||||
else:
|
else:
|
||||||
for childnum, child in enumerate(self.children):
|
for (childnum, child), childoffset in distance_sort(enumerate(self.children), offset):
|
||||||
if child == True:
|
if child == True:
|
||||||
for path in post_traversal_complete_subtree_recursion_helper(self.depth-1):
|
for path in post_traversal_complete_subtree_recursion_helper(self.depth-1, offset=childoffset):
|
||||||
path.append(childnum)
|
path.append(childnum)
|
||||||
yield path
|
yield path
|
||||||
|
|
||||||
@@ -1341,7 +1340,7 @@ class RendertileSet(object):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
# Recurse
|
# Recurse
|
||||||
for path in child._posttraversal_helper():
|
for path in child._posttraversal_helper(offset=childoffset):
|
||||||
path.append(childnum)
|
path.append(childnum)
|
||||||
yield path
|
yield path
|
||||||
|
|
||||||
@@ -1520,7 +1519,7 @@ class RendertileSet(object):
|
|||||||
c += 1
|
c += 1
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def post_traversal_complete_subtree_recursion_helper(depth):
|
def post_traversal_complete_subtree_recursion_helper(depth, offset=(0,0)):
|
||||||
"""Fakes the recursive calls for RendertileSet.posttraversal() for the case
|
"""Fakes the recursive calls for RendertileSet.posttraversal() for the case
|
||||||
that a subtree is collapsed, so that items are still yielded in the correct
|
that a subtree is collapsed, so that items are still yielded in the correct
|
||||||
order.
|
order.
|
||||||
@@ -1528,18 +1527,25 @@ def post_traversal_complete_subtree_recursion_helper(depth):
|
|||||||
"""
|
"""
|
||||||
if depth == 1:
|
if depth == 1:
|
||||||
# Base case
|
# Base case
|
||||||
yield [0]
|
for childnum, _ in distance_sort(xrange(4), offset):
|
||||||
yield [1]
|
yield [childnum]
|
||||||
yield [2]
|
|
||||||
yield [3]
|
|
||||||
else:
|
else:
|
||||||
for childnum in xrange(4):
|
for childnum, childoffset in distance_sort(xrange(4), offset):
|
||||||
for item in post_traversal_complete_subtree_recursion_helper(depth-1):
|
for item in post_traversal_complete_subtree_recursion_helper(depth-1, offset=childoffset):
|
||||||
item.append(childnum)
|
item.append(childnum)
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
yield []
|
yield []
|
||||||
|
|
||||||
|
def distance_sort(children, (off_x, off_y)):
|
||||||
|
order = []
|
||||||
|
for child, (dx, dy) in izip(children, [(-1,-1), (1,-1), (-1,1), (1,1)]):
|
||||||
|
x = off_x*2 + dx
|
||||||
|
y = off_y*2 + dy
|
||||||
|
order.append((child, (x,y)))
|
||||||
|
|
||||||
|
return sorted(order, key=lambda (_, (x,y)): x*x + y*y)
|
||||||
|
|
||||||
class RenderTile(object):
|
class RenderTile(object):
|
||||||
"""A simple container class that represents a single render-tile.
|
"""A simple container class that represents a single render-tile.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user