Start of the new rewrite code flow. TileSet still needs work
This commit is contained in:
@@ -127,6 +127,7 @@ else:
|
||||
from optparse import OptionParser
|
||||
from overviewer_core import optimizeimages, world, quadtree
|
||||
from overviewer_core import googlemap, rendernode
|
||||
from overviewer_core import configParser, tileset, assetmanager, dispatcher
|
||||
|
||||
# definitions of built-in custom modes
|
||||
# usually because what used to be a mode became an option
|
||||
@@ -383,6 +384,45 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
|
||||
logging.error(str(e))
|
||||
doExit(code=1, consoleMsg=False)
|
||||
|
||||
# look at our settings.py file
|
||||
mw_parser = configParser.MultiWorldParser("settings.py")
|
||||
mw_parser.parse()
|
||||
mw_parser.validate()
|
||||
|
||||
# create our asset manager... ASSMAN
|
||||
assetMrg = assetmanager.AssetManager(destdir)
|
||||
|
||||
render_things = mw_parser.get_render_things()
|
||||
tilesets = []
|
||||
for render_name in render_things:
|
||||
render = render_things[render_name]
|
||||
logging.debug("Found the following render thing: %r", render)
|
||||
|
||||
w = world.World(render['world_path'])
|
||||
|
||||
# if no dimension has been specified, just use the first one
|
||||
# TODO support the case where a different dimension is specified
|
||||
rset = w.get_regionset(2)
|
||||
logging.debug("Using RegionSet %r", rset)
|
||||
|
||||
# create our TileSet from this RegionSet
|
||||
tileset_dir = os.path.abspath(os.path.join(destdir, render_name))
|
||||
print "tileset_dir: %r" % tileset_dir
|
||||
if not os.path.exists(tileset_dir):
|
||||
os.mkdir(tileset_dir)
|
||||
tset = tileset.TileSet(rset, assetMrg, render, tileset_dir)
|
||||
tilesets.append(tset)
|
||||
|
||||
|
||||
# non-multiprocessing dispatcher
|
||||
dispatch = dispatcher.Dispatcher()
|
||||
def print_status(*args):
|
||||
logging.info("Status callback: %r", args)
|
||||
dispatch.render_all(tilesets, print_status)
|
||||
|
||||
|
||||
sys.exit("early abort")
|
||||
|
||||
# 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)
|
||||
|
||||
@@ -247,7 +247,16 @@ class MultiWorldParser(object):
|
||||
# anything that's not 'render' or 'custom_rendermode' is a default
|
||||
del glob['render']
|
||||
del glob['custom_rendermodes']
|
||||
self.defaults = glob
|
||||
|
||||
# seed with the Overviewer defaults, then update with the user defaults
|
||||
self.defaults = dict()
|
||||
for key in settingsDefinition.render:
|
||||
option = settingsDefinition.render[key]
|
||||
if option.has_key("default"):
|
||||
self.defaults[key] = option.get("default")
|
||||
|
||||
self.defaults.update(glob)
|
||||
|
||||
|
||||
import pprint
|
||||
pprint.pprint(glob, indent=2)
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
from settingsValidators import *
|
||||
|
||||
|
||||
# note that all defaults go thought the validator
|
||||
|
||||
render = {
|
||||
"world_path": dict(required=True, validator=validateWorldPath),
|
||||
"rendermode": dict(required=False, validator=validateRenderMode),
|
||||
@@ -21,11 +23,13 @@ render = {
|
||||
"render-range": dict(required=False, validator=validateRenderRange),
|
||||
"force-render": dict(required=False, validator=bool),
|
||||
"stochastic-render": dict(required=False, validator=validateStochastic),
|
||||
"imgformat": dict(required=False, validator=validateImgFormat),
|
||||
"imgformat": dict(required=False, validator=validateImgFormat, default="png"),
|
||||
"imgquality": dict(required=False, validator=validateImgQuality),
|
||||
"bg-color": dict(required=False, validator=validateBGColor),
|
||||
"optimize-img": dict(required=False, validator=validateOptImg),
|
||||
"no-markers": dict(required=False, validator=bool),
|
||||
"texture-path": dict(required=False, validator=validateTexturePath),
|
||||
"rendercheck": dict(required=False, validator=int, default=0),
|
||||
"rerender_prob": dict(required=False, validator=float, default=0),
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ def validateWorldPath(path):
|
||||
raise ValidationException("%r does not exist" % path)
|
||||
if not os.path.isdir(path):
|
||||
raise ValidationException("%r is not a directory" % path)
|
||||
except ValidationException, e
|
||||
except ValidationException, e:
|
||||
# TODO assume this is the name of a world and try
|
||||
# to find it
|
||||
raise e
|
||||
@@ -64,10 +64,8 @@ def validateBGColor(color):
|
||||
def validateOptImg(opt):
|
||||
return bool(opt)
|
||||
|
||||
def valiateTexturePath(path):
|
||||
def validateTexturePath(path):
|
||||
# Expand user dir in directories strings
|
||||
path = os.path.expanduser(path)
|
||||
# TODO assert this path exists?
|
||||
if options.web_assets_path:
|
||||
options.web_assets_path = os.path.expanduser(options.web_assets_path)
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@ import os
|
||||
import os.path
|
||||
import shutil
|
||||
import random
|
||||
import functools
|
||||
import time
|
||||
from collections import namedtuple
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from .util import iterate_base4, convert_coords
|
||||
from .util import iterate_base4, convert_coords, unconvert_coords
|
||||
from .optimizeimages import optimize_image
|
||||
|
||||
"""
|
||||
@@ -276,8 +278,8 @@ class TileSet(object):
|
||||
# Y has 4 times as many chunks as tiles, then halved since this is
|
||||
# a radius
|
||||
yradius = 2*2**p
|
||||
if xradius >= bounds.maxcol and -xradius <= bounds.mincol and \
|
||||
yradius >= bounds.maxrow and -yradius <= bounds.minrow:
|
||||
if xradius >= self.bounds.maxcol and -xradius <= self.bounds.mincol and \
|
||||
yradius >= self.bounds.maxrow and -yradius <= self.bounds.minrow:
|
||||
break
|
||||
|
||||
if p >= 15:
|
||||
@@ -417,15 +419,15 @@ class TileSet(object):
|
||||
logging.critical("Could not determine existing tile tree depth. Does it exist?")
|
||||
raise
|
||||
|
||||
if self.treedepth != cur_depth:
|
||||
if self.treedepth != curdepth:
|
||||
if self.treedepth > curdepth:
|
||||
logging.warning("Your map seems to have expanded beyond its previous bounds.")
|
||||
logging.warning( "Doing some tile re-arrangements... just a sec...")
|
||||
for _ in xrange(self.p-curdepth):
|
||||
for _ in xrange(self.treedepth-curdepth):
|
||||
self._increase_depth()
|
||||
elif self.p < curdepth:
|
||||
elif self.treedepth < curdepth:
|
||||
logging.warning("Your map seems to have shrunk. Did you delete some chunks? No problem. Re-arranging tiles, just a sec...")
|
||||
for _ in xrange(curdepth - self.p):
|
||||
for _ in xrange(curdepth - self.treedepth):
|
||||
self._decrease_depth()
|
||||
|
||||
def _increase_depth(self):
|
||||
@@ -559,7 +561,7 @@ class TileSet(object):
|
||||
max_chunk_mtime = chunkmtime
|
||||
|
||||
# Convert to diagonal coordinates
|
||||
chunkcol, chunkrow = util.convert_coords(chunkx, chunkz)
|
||||
chunkcol, chunkrow = convert_coords(chunkx, chunkz)
|
||||
|
||||
# find tile coordinates. Remember tiles are identified by the
|
||||
# address of the chunk in their upper left corner.
|
||||
@@ -832,7 +834,6 @@ class TileSet(object):
|
||||
|
||||
chunklist = []
|
||||
|
||||
unconvert_coords = util.unconvert_coords
|
||||
get_region = self.regionobj.regionfiles.get
|
||||
|
||||
# Cached region object for consecutive iterations
|
||||
|
||||
@@ -83,7 +83,6 @@ class World(object):
|
||||
|
||||
for root, dirs, files in os.walk(self.worlddir):
|
||||
# any .mcr files in this directory?
|
||||
print "looking in", root
|
||||
mcrs = filter(lambda x: x.endswith(".mcr"), files)
|
||||
if mcrs:
|
||||
# construct a regionset object for this
|
||||
@@ -123,7 +122,8 @@ class World(object):
|
||||
|
||||
def get_regionsets(self):
|
||||
return self.regionsets
|
||||
|
||||
def get_regionset(self, index):
|
||||
return self.regionsets[index]
|
||||
|
||||
|
||||
|
||||
@@ -217,6 +217,9 @@ but may be several per invocation of the Overviewer in the case of multi-world.
|
||||
self.empty_chunk = [None,None]
|
||||
logging.debug("Done scanning regions")
|
||||
|
||||
def __repr__(self):
|
||||
return "<RegionSet regiondir=%r>" % self.regiondir
|
||||
|
||||
def get_region_path(self, chunkX, chunkY):
|
||||
"""Returns the path to the region that contains chunk (chunkX, chunkY)
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user