0

Merge branch 'master' into dtt-master-merge

Conflicts:
	gmap.py
	quadtree.py
This commit is contained in:
Aaron Griffith
2011-03-19 21:15:05 -04:00
3 changed files with 35 additions and 3 deletions

View File

@@ -246,6 +246,15 @@ Options
--night
This option enables --lighting, and renders the world at night.
--web-assets-hook=HOOK
This option lets you specify a script to run after the web assets have been
copied into the output directory, but before any tile rendering takes
place. This is an ideal time to do any custom postprocessing for markers.js
or other web assets.
The script should be executable, and it should accept one argument:
the path to the output directory.
Viewing the Results
-------------------
Within the output directory you will find two things: an index.html file, and a

21
gmap.py
View File

@@ -24,6 +24,7 @@ import os
import os.path
from configParser import ConfigOptionParser
import re
import subprocess
import multiprocessing
import time
import logging
@@ -62,6 +63,7 @@ def main():
parser.add_option("--rendermode", dest="rendermode", help="Specifies the render type: normal (default), lighting, night, or spawn.", type="choice", choices=["normal", "lighting", "night", "spawn"], required=True, default="normal")
parser.add_option("--imgformat", dest="imgformat", help="The image output format to use. Currently supported: png(default), jpg. NOTE: png will always be used as the intermediate image format.", configFileOnly=True )
parser.add_option("--optimize-img", dest="optimizeimg", help="If using png, perform image file size optimizations on the output. Specify 1 for pngcrush, 2 for pngcrush+optipng+advdef. This may double (or more) render times, but will produce up to 30% smaller images. NOTE: requires corresponding programs in $PATH or %PATH%", configFileOnly=True)
parser.add_option("--web-assets-hook", dest="web_assets_hook", help="If provided, run this script after the web assets have been copied, but before actual tile rendering begins. See the README for details.", action="store", metavar="SCRIPT", type="string", configFileOnly=True)
parser.add_option("-q", "--quiet", dest="quiet", action="count", default=0, help="Print less output. You can specify this option multiple times.")
parser.add_option("-v", "--verbose", dest="verbose", action="count", default=0, help="Print more output. You can specify this option multiple times.")
parser.add_option("--skip-js", dest="skipjs", action="store_true", help="Don't output marker.js or regions.js")
@@ -138,7 +140,22 @@ def main():
optimizeimages.check_programs(optimizeimg)
else:
optimizeimg = None
if options.web_assets_hook:
if not os.path.exists(options.web_assets_hook):
parser.error("Provided hook script does not exist!")
def web_assets_hook(quadtree):
if options.web_assets_hook == None:
return
try:
subprocess.check_call((options.web_assets_hook, os.path.abspath(quadtree.destdir)))
except OSError, e:
logging.error("could not call web assets hook: %s" % (e,))
sys.exit(1)
except subprocess.CalledProcessError:
logging.error("web assets hook returned error")
sys.exit(1)
logging.getLogger().setLevel(
logging.getLogger().level + 10*options.quiet)
logging.getLogger().setLevel(
@@ -160,7 +177,7 @@ def main():
# Now generate the tiles
# TODO chunklist
q = quadtree.QuadtreeGen(w, destdir, depth=options.zoom, imgformat=imgformat, optimizeimg=optimizeimg, rendermode=options.rendermode)
q = quadtree.QuadtreeGen(w, destdir, depth=options.zoom, imgformat=imgformat, optimizeimg=optimizeimg, rendermode=options.rendermode, web_assets_hook=web_assets_hook)
q.write_html(options.skipjs)
q.go(options.procs)

View File

@@ -90,7 +90,7 @@ def pool_initializer(quadtree):
child_quadtree = quadtree
class QuadtreeGen(object):
def __init__(self, worldobj, destdir, depth=None, tiledir="tiles", imgformat=None, optimizeimg=None, rendermode="normal"):
def __init__(self, worldobj, destdir, depth=None, tiledir="tiles", imgformat=None, optimizeimg=None, rendermode="normal", web_assets_hook=None):
"""Generates a quadtree from the world given into the
given dest directory
@@ -103,6 +103,7 @@ class QuadtreeGen(object):
assert(imgformat)
self.imgformat = imgformat
self.optimizeimg = optimizeimg
self.web_assets_hook = web_assets_hook
self.lighting = rendermode in ("lighting", "night", "spawn")
self.night = rendermode in ("night", "spawn")
@@ -196,6 +197,8 @@ class QuadtreeGen(object):
output.write(index)
if skipjs:
if self.web_assets_hook:
self.web_assets_hook(self)
return
# since we will only discover PointsOfInterest in chunks that need to be
@@ -224,6 +227,9 @@ class QuadtreeGen(object):
output.write(' // ]},\n')
output.write('];')
if self.web_assets_hook:
self.web_assets_hook(self)
def _get_cur_depth(self):
"""How deep is the quadtree currently in the destdir? This glances in
config.js to see what maxZoom is set to.