Skip to content

Commit cdb0b57

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 7171af5 commit cdb0b57

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
@@ -2034,42 +2034,38 @@ def iterate_newer_chunks(self, filemtime):
20342034
yield x,z,mtime
20352035

20362036
class CroppedRegionSet(RegionSetWrapper):
2037-
def __init__(self, rsetobj, xmin, zmin, xmax, zmax):
2037+
def __init__(self, rsetobj, cropzones):
20382038
super(CroppedRegionSet, self).__init__(rsetobj)
2039-
self.xmin = xmin//16
2040-
self.xmax = xmax//16
2041-
self.zmin = zmin//16
2042-
self.zmax = zmax//16
2043-
2044-
def get_chunk(self,x,z):
2045-
if (
2046-
self.xmin <= x <= self.xmax and
2047-
self.zmin <= z <= self.zmax
2048-
):
2049-
return super(CroppedRegionSet, self).get_chunk(x,z)
2039+
newcropzones = []
2040+
for cz in cropzones:
2041+
# Crop zone format: (xmin, zmin, xmax, zmax)
2042+
newcropzones.append(tuple([x // 16 for x in cz]))
2043+
self.cropzones = newcropzones
2044+
2045+
def chunk_in_cropzone(self, x, z):
2046+
# Determines if chunk at (x, z) is within one of the defined crop zones
2047+
for cz in self.cropzones:
2048+
if cz[0] <= x <= cz[2] and cz[1] <= z <= cz[3]:
2049+
return True
2050+
return False
2051+
2052+
def get_chunk(self, x, z):
2053+
if self.chunk_in_cropzone(x, z):
2054+
return super(CroppedRegionSet, self).get_chunk(x, z)
20502055
else:
20512056
raise ChunkDoesntExist("This chunk is out of the requested bounds")
20522057

20532058
def iterate_chunks(self):
2054-
return ((x,z,mtime) for (x,z,mtime) in super(CroppedRegionSet,self).iterate_chunks()
2055-
if
2056-
self.xmin <= x <= self.xmax and
2057-
self.zmin <= z <= self.zmax
2058-
)
2059+
return ((x, z, mtime) for (x, z ,mtime) in super(CroppedRegionSet,self).iterate_chunks()
2060+
if self.chunk_in_cropzone(x, z))
20592061

20602062
def iterate_newer_chunks(self, filemtime):
2061-
return ((x,z,mtime) for (x,z,mtime) in super(CroppedRegionSet,self).iterate_newer_chunks(filemtime)
2062-
if
2063-
self.xmin <= x <= self.xmax and
2064-
self.zmin <= z <= self.zmax
2065-
)
2063+
return ((x, z, mtime) for (x, z, mtime) in super(CroppedRegionSet,self).iterate_newer_chunks(filemtime)
2064+
if self.chunk_in_cropzone(x, z))
20662065

20672066
def get_chunk_mtime(self,x,z):
2068-
if (
2069-
self.xmin <= x <= self.xmax and
2070-
self.zmin <= z <= self.zmax
2071-
):
2072-
return super(CroppedRegionSet, self).get_chunk_mtime(x,z)
2067+
if self.chunk_in_cropzone(x, z):
2068+
return super(CroppedRegionSet, self).get_chunk_mtime(x, z)
20732069
else:
20742070
return None
20752071

0 commit comments

Comments
 (0)