Skip to content

Commit 241ce6e

Browse files
committed
Improve multiple crop zone support
Amends handling of the 'crop' render option such that when multiple crop zones are specified, one CroppedRegionSet with many crop zones is used rather than many CroppedRegionSets each with one crop zone. This resolves issues where crop zones within the same render could clobber each others tiles if close enough and could be rendered with a different number of zoom levels.
1 parent 91ea874 commit 241ce6e

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

overviewer.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -531,20 +531,12 @@ def set_renderchecks(checkname, num):
531531

532532
# If a crop is requested, wrap the regionset here
533533
if "crop" in render:
534-
rsets = []
535-
for zone in render['crop']:
536-
rsets.append(world.CroppedRegionSet(rset, *zone))
537-
else:
538-
rsets = [rset]
534+
rset = world.CroppedRegionSet(rset, render['crop'])
539535

540536
# If this is to be a rotated regionset, wrap it in a RotatedRegionSet
541537
# object
542538
if (render['northdirection'] > 0):
543-
newrsets = []
544-
for r in rsets:
545-
r = world.RotatedRegionSet(r, render['northdirection'])
546-
newrsets.append(r)
547-
rsets = newrsets
539+
rset = world.RotatedRegionSet(rset, render['northdirection'])
548540

549541
###############################
550542
# Do the final prep and create the TileSet object
@@ -560,9 +552,8 @@ def set_renderchecks(checkname, num):
560552
"dimension", "changelist", "showspawn", "overlay", "base", "poititle", "maxzoom",
561553
"showlocationmarker", "minzoom", "center"])
562554
tileSetOpts.update({"spawn": w.find_true_spawn()}) # TODO find a better way to do this
563-
for rset in rsets:
564-
tset = tileset.TileSet(w, rset, assetMrg, tex, tileSetOpts, tileset_dir)
565-
tilesets.append(tset)
555+
tset = tileset.TileSet(w, rset, assetMrg, tex, tileSetOpts, tileset_dir)
556+
tilesets.append(tset)
566557

567558
# If none of the requested dimenstions exist, tilesets will be empty
568559
if not tilesets:

overviewer_core/world.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,42 +1743,38 @@ def iterate_newer_chunks(self, filemtime):
17431743
yield x,z,mtime
17441744

17451745
class CroppedRegionSet(RegionSetWrapper):
1746-
def __init__(self, rsetobj, xmin, zmin, xmax, zmax):
1746+
def __init__(self, rsetobj, cropzones):
17471747
super(CroppedRegionSet, self).__init__(rsetobj)
1748-
self.xmin = xmin//16
1749-
self.xmax = xmax//16
1750-
self.zmin = zmin//16
1751-
self.zmax = zmax//16
1752-
1753-
def get_chunk(self,x,z):
1754-
if (
1755-
self.xmin <= x <= self.xmax and
1756-
self.zmin <= z <= self.zmax
1757-
):
1758-
return super(CroppedRegionSet, self).get_chunk(x,z)
1748+
newcropzones = []
1749+
for cz in cropzones:
1750+
# Crop zone format: (xmin, zmin, xmax, zmax)
1751+
newcropzones.append(tuple([x // 16 for x in cz]))
1752+
self.cropzones = newcropzones
1753+
1754+
def chunk_in_cropzone(self, x, z):
1755+
# Determines if chunk at (x, z) is within one of the defined crop zones
1756+
for cz in self.cropzones:
1757+
if cz[0] <= x <= cz[2] and cz[1] <= z <= cz[3]:
1758+
return True
1759+
return False
1760+
1761+
def get_chunk(self, x, z):
1762+
if self.chunk_in_cropzone(x, z):
1763+
return super(CroppedRegionSet, self).get_chunk(x, z)
17591764
else:
17601765
raise ChunkDoesntExist("This chunk is out of the requested bounds")
17611766

17621767
def iterate_chunks(self):
1763-
return ((x,z,mtime) for (x,z,mtime) in super(CroppedRegionSet,self).iterate_chunks()
1764-
if
1765-
self.xmin <= x <= self.xmax and
1766-
self.zmin <= z <= self.zmax
1767-
)
1768+
return ((x, z, mtime) for (x, z ,mtime) in super(CroppedRegionSet,self).iterate_chunks()
1769+
if self.chunk_in_cropzone(x, z))
17681770

17691771
def iterate_newer_chunks(self, filemtime):
1770-
return ((x,z,mtime) for (x,z,mtime) in super(CroppedRegionSet,self).iterate_newer_chunks(filemtime)
1771-
if
1772-
self.xmin <= x <= self.xmax and
1773-
self.zmin <= z <= self.zmax
1774-
)
1772+
return ((x, z, mtime) for (x, z, mtime) in super(CroppedRegionSet,self).iterate_newer_chunks(filemtime)
1773+
if self.chunk_in_cropzone(x, z))
17751774

17761775
def get_chunk_mtime(self,x,z):
1777-
if (
1778-
self.xmin <= x <= self.xmax and
1779-
self.zmin <= z <= self.zmax
1780-
):
1781-
return super(CroppedRegionSet, self).get_chunk_mtime(x,z)
1776+
if self.chunk_in_cropzone(x, z):
1777+
return super(CroppedRegionSet, self).get_chunk_mtime(x, z)
17821778
else:
17831779
return None
17841780

0 commit comments

Comments
 (0)