Moved html generation to happen before quadtree generation. This way, you can open up the html file immediately and browse the map as it is being generated! This necessitated pulling the zoom-depth determination out into its own function.
This commit is contained in:
17
gmap.py
17
gmap.py
@@ -37,21 +37,20 @@ def main():
|
|||||||
print "processing chunks in background"
|
print "processing chunks in background"
|
||||||
results = world.render_chunks_async(chunks, False, options.procs)
|
results = world.render_chunks_async(chunks, False, options.procs)
|
||||||
|
|
||||||
print "Generating quad tree. This may take a while and has no progress bar right now, so sit tight."
|
print "Writing out html file"
|
||||||
|
|
||||||
if not os.path.exists(destdir):
|
if not os.path.exists(destdir):
|
||||||
os.mkdir(destdir)
|
os.mkdir(destdir)
|
||||||
tiledir = os.path.join(destdir, "tiles");
|
zoom = world.get_quadtree_depth(mincol, maxcol, minrow, maxrow)
|
||||||
if not os.path.exists(tiledir):
|
write_html(destdir, zoom+1)
|
||||||
os.mkdir(tiledir)
|
|
||||||
|
|
||||||
zoom = world.generate_quadtree(results, mincol, maxcol, minrow, maxrow, tiledir)
|
print "Generating quad tree. This may take a while and has no progress bar right now, so sit tight."
|
||||||
|
tiledir = os.path.join(destdir, "tiles");
|
||||||
|
if not os.path.exists(tiledir):
|
||||||
|
os.mkdir(tiledir)
|
||||||
|
world.generate_quadtree(results, mincol, maxcol, minrow, maxrow, tiledir)
|
||||||
|
|
||||||
print "DONE"
|
print "DONE"
|
||||||
|
|
||||||
print "Writing out html file"
|
|
||||||
write_html(destdir, zoom+1)
|
|
||||||
|
|
||||||
def write_html(path, zoomlevel):
|
def write_html(path, zoomlevel):
|
||||||
templatepath = os.path.join(os.path.split(__file__)[0], "template.html")
|
templatepath = os.path.join(os.path.split(__file__)[0], "template.html")
|
||||||
html = open(templatepath, 'r').read()
|
html = open(templatepath, 'r').read()
|
||||||
|
|||||||
29
world.py
29
world.py
@@ -288,15 +288,13 @@ def render_worldtile(chunkmap, colstart, colend, rowstart, rowend, oldhash):
|
|||||||
|
|
||||||
return tileimg, digest
|
return tileimg, digest
|
||||||
|
|
||||||
def generate_quadtree(chunkmap, colstart, colend, rowstart, rowend, prefix):
|
def get_quadtree_depth(colstart, colend, rowstart, rowend):
|
||||||
"""Base call for quadtree_recurse. This sets up the recursion and generates
|
"""Determines the zoom depth of a requested quadtree.
|
||||||
a quadtree given a chunkmap and the ranges.
|
|
||||||
|
|
||||||
This returns the power of 2 tiles wide and high the image is. This is one
|
|
||||||
less than the maximum zoom (level 0 is a single tile, level 1 is 2 tiles
|
|
||||||
wide by 2 tiles high, etc.)
|
|
||||||
|
|
||||||
|
Return value is an integer >= 0. Higher integers mean higher resolution maps.
|
||||||
"""
|
"""
|
||||||
|
# Pulled out of generate_quadtree. Original comment follows:
|
||||||
|
#
|
||||||
# This first call has a special job. No matter the input, we need to
|
# This first call has a special job. No matter the input, we need to
|
||||||
# make sure that each recursive call splits both dimensions evenly
|
# make sure that each recursive call splits both dimensions evenly
|
||||||
# into a power of 2 tiles wide and high.
|
# into a power of 2 tiles wide and high.
|
||||||
@@ -316,6 +314,21 @@ def generate_quadtree(chunkmap, colstart, colend, rowstart, rowend, prefix):
|
|||||||
else:
|
else:
|
||||||
raise Exception("Your map is waaaay to big")
|
raise Exception("Your map is waaaay to big")
|
||||||
|
|
||||||
|
return p
|
||||||
|
|
||||||
|
def generate_quadtree(chunkmap, colstart, colend, rowstart, rowend, prefix):
|
||||||
|
"""Base call for quadtree_recurse. This sets up the recursion and generates
|
||||||
|
a quadtree given a chunkmap and the ranges.
|
||||||
|
|
||||||
|
This returns the power of 2 tiles wide and high the image is. This is one
|
||||||
|
less than the maximum zoom (level 0 is a single tile, level 1 is 2 tiles
|
||||||
|
wide by 2 tiles high, etc.)
|
||||||
|
|
||||||
|
"""
|
||||||
|
p = get_quadtree_depth(colstart, colend, rowstart, rowend);
|
||||||
|
colmid = (colstart + colend) // 2
|
||||||
|
rowmid = (rowstart + rowend) // 2
|
||||||
|
|
||||||
# Modify the lower and upper bounds to be sized correctly
|
# Modify the lower and upper bounds to be sized correctly
|
||||||
colstart = colmid - 2*2**p
|
colstart = colmid - 2*2**p
|
||||||
colend = colmid + 2*2**p
|
colend = colmid + 2*2**p
|
||||||
@@ -327,8 +340,6 @@ def generate_quadtree(chunkmap, colstart, colend, rowstart, rowend, prefix):
|
|||||||
|
|
||||||
quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, "base")
|
quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, "base")
|
||||||
|
|
||||||
return p
|
|
||||||
|
|
||||||
def quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, quadrant):
|
def quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, quadrant):
|
||||||
"""Recursive method that generates a quadtree.
|
"""Recursive method that generates a quadtree.
|
||||||
A single call generates, saves, and returns an image with the range
|
A single call generates, saves, and returns an image with the range
|
||||||
|
|||||||
Reference in New Issue
Block a user