From fbdeb90f9f5735d72e6739a8cf5acb7070584e9c Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Tue, 20 Dec 2011 23:17:28 -0500 Subject: [PATCH] overviewer.py now runs without crashing but still is broken --- overviewer.py | 19 ++----- overviewer_core/quadtree.py | 5 +- overviewer_core/world.py | 109 ++++++++++++++++-------------------- 3 files changed, 57 insertions(+), 76 deletions(-) diff --git a/overviewer.py b/overviewer.py index b4a6a29..f5e36be 100755 --- a/overviewer.py +++ b/overviewer.py @@ -414,23 +414,16 @@ dir but you forgot to put quotes around the directory, since it contains spaces. # First do world-level preprocessing. This scans the world hierarchy, reads # in the region files and caches chunk modified times, and determines the # chunk bounds (max and min in both dimensions) - w = world.World(worlddir, destdir, regionlist=regionlist, north_direction=north_direction) + w = world.World(worlddir) if north_direction == 'auto': - north_direction = w.persistentData['north_direction'] + # TODO get this from the asset manager # north_direction = w.persistentData['north_direction'] options.north_direction = north_direction - elif (w.persistentData['north_direction'] != north_direction and - not options.forcerender and - not w.persistentDataIsNew - ): - logging.error("Conflicting north-direction setting!") - logging.error("Overviewer.dat gives previous north-direction as "+w.persistentData['north_direction']) - logging.error("Requested north-direction was "+north_direction) - logging.error("To change north-direction of an existing render, use --forcerender") - doExit(code=1, consoleMsg=False) + + # TODO deal with changed north direction # A couple other things we need to figure out about the world: - w.determine_bounds() - w.find_true_spawn() + w.get_regionsets()[0].determine_bounds() + # w.find_true_spawn() logging.info("Rendering the following tilesets: %s", ",".join(options.rendermode)) diff --git a/overviewer_core/quadtree.py b/overviewer_core/quadtree.py index c24e43d..16460cc 100644 --- a/overviewer_core/quadtree.py +++ b/overviewer_core/quadtree.py @@ -30,6 +30,7 @@ from PIL import Image from . import chunk from .optimizeimages import optimize_image from c_overviewer import get_render_mode_inheritance +import util """ @@ -540,12 +541,12 @@ class QuadtreeGen(object): # # IDEA: check last render time against mtime of the region to short # circuit checking mtimes of all chunks in a region - for chunkx, chunky, chunkmtime in self.world.iterate_chunk_metadata(): + for chunkx, chunky, chunkmtime in self.world.get_regionsets()[0].iterate_chunks(): chunkcount += 1 #if chunkcount % 10000 == 0: # logging.info(" %s chunks scanned", chunkcount) - chunkcol, chunkrow = self.world.convert_coords(chunkx, chunky) + chunkcol, chunkrow = util.convert_coords(chunkx, chunky) #logging.debug("Looking at chunk %s,%s", chunkcol, chunkrow) # find tile coordinates diff --git a/overviewer_core/world.py b/overviewer_core/world.py index c6c776b..77885a1 100644 --- a/overviewer_core/world.py +++ b/overviewer_core/world.py @@ -31,6 +31,7 @@ import numpy import chunk import nbt import textures +import util """ This module has routines for extracting information about available worlds @@ -82,10 +83,11 @@ class World(object): for root, dirs, files in os.walk(self.worlddir): # any .mcr files in this directory? - mcrs = filter(lambda x: x.endswith(".mcr")) + print "looking in", root + mcrs = filter(lambda x: x.endswith(".mcr"), files) if mcrs: # construct a regionset object for this - rset = RegionSet(self, os.path.join(self.worlddir, root)) + rset = RegionSet(self, root) self.regionsets.append(rset) # TODO consider reordering self.regionsets so that the 'default' region is first @@ -127,23 +129,6 @@ class World(object): def get_region_mtime(self,filename): return (self.regions[filename][0],self.regions[filename][1]) - - def convert_coords(self, chunkx, chunky): - """Takes a coordinate (chunkx, chunky) where chunkx and chunky are - in the chunk coordinate system, and figures out the row and column - in the image each one should be. Returns (col, row).""" - - # columns are determined by the sum of the chunk coords, rows are the - # difference - # change this function, and you MUST change unconvert_coords - return (chunkx + chunky, chunky - chunkx) - - def unconvert_coords(self, col, row): - """Undoes what convert_coords does. Returns (chunkx, chunky).""" - - # col + row = chunky + chunky => (col + row)/2 = chunky - # col - row = chunkx + chunkx => (col - row)/2 = chunkx - return ((col - row) / 2, (col + row) / 2) def find_true_spawn(self): """Adds the true spawn location to self.POI. The spawn Y coordinate @@ -191,48 +176,6 @@ class World(object): msg="Spawn", type="spawn", chunk=(chunkX, chunkY))) self.spawn = (disp_spawnX, spawnY, disp_spawnZ) - def determine_bounds(self): - """Scan the world directory, to fill in - self.{min,max}{col,row} for use later in quadtree.py. - - """ - - logging.info("Scanning chunks") - # find the dimensions of the map, in region files - minx = maxx = miny = maxy = 0 - found_regions = False - for x, y in self.regionfiles: - found_regions = True - minx = min(minx, x) - maxx = max(maxx, x) - miny = min(miny, y) - maxy = max(maxy, y) - if not found_regions: - logging.error("Error: No chunks found!") - sys.exit(1) - logging.debug("Done scanning chunks") - - # turn our region coordinates into chunk coordinates - minx = minx * 32 - miny = miny * 32 - maxx = maxx * 32 + 32 - maxy = maxy * 32 + 32 - - # Translate chunks to our diagonal coordinate system - mincol = maxcol = minrow = maxrow = 0 - for chunkx, chunky in [(minx, miny), (minx, maxy), (maxx, miny), (maxx, maxy)]: - col, row = self.convert_coords(chunkx, chunky) - mincol = min(mincol, col) - maxcol = max(maxcol, col) - minrow = min(minrow, row) - maxrow = max(maxrow, row) - - #logging.debug("map size: (%i, %i) to (%i, %i)" % (mincol, minrow, maxcol, maxrow)) - - self.mincol = mincol - self.maxcol = maxcol - self.minrow = minrow - self.maxrow = maxrow def _get_north_rotations(self): # default to lower-left for now @@ -399,6 +342,7 @@ Old name: world.iterate_chunk_metadata logging.warning("Ignoring non region file '%s' in regionlist", f) else: + print "regiondir is", self.regiondir for path in glob(self.regiondir + "/r.*.*.mcr"): dirpath, f = os.path.split(path) p = f.split(".") @@ -416,6 +360,49 @@ Old name: world.iterate_chunk_metadata ##TODO x = y ##TODO y = -temp-1 yield (x, y, join(dirpath, f)) + + def determine_bounds(self): + """Scan the world directory, to fill in + self.{min,max}{col,row} for use later in quadtree.py. + + """ + + logging.info("Scanning chunks") + # find the dimensions of the map, in region files + minx = maxx = miny = maxy = 0 + found_regions = False + for x, y in self.regionfiles: + found_regions = True + minx = min(minx, x) + maxx = max(maxx, x) + miny = min(miny, y) + maxy = max(maxy, y) + if not found_regions: + logging.error("Error: No chunks found!") + sys.exit(1) + logging.debug("Done scanning chunks") + + # turn our region coordinates into chunk coordinates + minx = minx * 32 + miny = miny * 32 + maxx = maxx * 32 + 32 + maxy = maxy * 32 + 32 + + # Translate chunks to our diagonal coordinate system + mincol = maxcol = minrow = maxrow = 0 + for chunkx, chunky in [(minx, miny), (minx, maxy), (maxx, miny), (maxx, maxy)]: + col, row = util.convert_coords(chunkx, chunky) + mincol = min(mincol, col) + maxcol = max(maxcol, col) + minrow = min(minrow, row) + maxrow = max(maxrow, row) + + #logging.debug("map size: (%i, %i) to (%i, %i)" % (mincol, minrow, maxcol, maxrow)) + + self.mincol = mincol + self.maxcol = maxcol + self.minrow = minrow + self.maxrow = maxrow def get_save_dir(): """Returns the path to the local saves directory