0

Merge remote-tracking branch 'overviewer/rewrite' into rewrite

This commit is contained in:
Andrew Chin
2012-01-01 21:20:54 -05:00

View File

@@ -151,7 +151,7 @@ class TileSet(object):
"""
def __init__(self, regionsetobj, assetmanagerobj, options, outputdir):
def __init__(self, regionsetobj, assetmanagerobj, texturesobj, options, outputdir):
"""Construct a new TileSet object with the given configuration options
dictionary.
@@ -163,6 +163,9 @@ class TileSet(object):
assetmanagerobj is the AssetManager object that represents the
destination directory where we'll put our tiles.
texturesobj is the Textures object to pass into the rendering routine.
This class does nothing with it except pass it through.
outputdir is the absolute path to the tile output directory where the
tiles are saved. It is assumed to exist already.
TODO: This should probably be relative to the asset manager's output
@@ -241,6 +244,7 @@ class TileSet(object):
self.options = options
self.regionset = regionsetobj
self.am = assetmanagerobj
self.textures = texturesobj
# Throughout the class, self.outputdir is an absolute path to the
# directory where we output tiles. It is assumed to exist.
@@ -500,12 +504,14 @@ class TileSet(object):
render-tiles need rendering. Returns a RendertileSet object.
For rendercheck mode 0: only compares chunk mtimes against last render
time of the map
time of the map, and marks tiles as dirty if any chunk has a greater
mtime than the last render time.
For rendercheck mode 1: compares chunk mtimes against the tile mtimes
on disk, and also builds a tileset of every tile
on disk, doing a stat call for each tile.
For rendercheck mode 2: marks every tile, does not check any mtimes.
For rendercheck mode 2: marks every tile in the tileset
unconditionally, does not check any mtimes.
As a side-effect, the scan sets self.max_chunk_mtime to the max of all
the chunks' mtimes
@@ -531,12 +537,13 @@ class TileSet(object):
if rendercheck == 0:
def compare_times(chunkmtime, tileobj):
# Compare chunk mtime to last render time
# Compare chunk mtime to last render time, don't look at tile
# mtime on disk
return chunkmtime > last_rendertime
elif rendercheck == 1:
def compare_times(chunkmtime, tileobj):
# Compare chunk mtime to tile mtime on disk
tile_path = tile.get_filepath(self.full_tiledir, self.imgformat)
tile_path = tileobj.get_filepath(self.full_tiledir, self.imgformat)
try:
tile_mtime = os.stat(tile_path)[stat.ST_MTIME]
except OSError, e:
@@ -545,6 +552,7 @@ class TileSet(object):
# File doesn't exist. Render it.
return True
# Render if chunks are newer than the tile
return chunkmtime > tile_mtime
@@ -602,7 +610,8 @@ class TileSet(object):
tile = RenderTile.compute_path(c, r, depth)
if rendercheck == 2:
# Skip all other checks, mark tiles as dirty unconditionally
# forcerender mode: Skip all other checks, mark tiles
# as dirty unconditionally
dirty.add(tile.path)
continue
@@ -623,7 +632,6 @@ class TileSet(object):
continue
# Check mtimes and conditionally add tile to dirty set
print repr(tile)
if compare_times(chunkmtime, tile):
dirty.add(tile.path)
@@ -744,7 +752,8 @@ class TileSet(object):
imgpath = tile.get_filepath(self.full_tiledir, self.imgformat)
# Calculate which chunks are relevant to this tile
chunks = self._get_chunks_for_tile(tile)
# This is a list of (col, row, chunkx, chunkz, chunk_mtime)
chunks = list(self._get_chunks_for_tile(tile))
region = self.regionobj
@@ -784,15 +793,6 @@ class TileSet(object):
if e.errno != errno.EEXIST:
raise
# Compute the maximum mtime of all the chunks that go into this tile.
# At the end, we'll set the tile's mtime to this value.
max_chunk_mtime = 0
for col,row,chunkx,chunky,region in chunks:
max_chunk_mtime = max(
max_chunk_mtime,
region.get_chunk_timestamp(chunkx, chunky)
)
#logging.debug("writing out worldtile {0}".format(imgpath))
# Compile this image
@@ -803,17 +803,16 @@ class TileSet(object):
rowstart = tile.row
# col colstart will get drawn on the image starting at x coordinates -(384/2)
# row rowstart will get drawn on the image starting at y coordinates -(192/2)
for col, row, chunkx, chunky, region in chunks:
max_chunk_mtime = 0
for col, row, chunkx, chunky, chunk_mtime in chunks:
xpos = -192 + (col-colstart)*192
ypos = -96 + (row-rowstart)*96
if chunk_mtime > max_chunk_mtime:
max_chunk_mtime = chunk_mtime
# draw the chunk!
try:
a = chunk.ChunkRenderer((chunkx, chunky), self.regionobj, rendermode, poi_queue)
a.chunk_render(tileimg, xpos, ypos, None)
except chunk.ChunkCorrupt:
# an error was already printed
pass
# TODO RENDER THE CHUNK
# Save them
if self.imgformat == 'jpg':
@@ -829,20 +828,12 @@ class TileSet(object):
def _get_chunks_for_tile(self, tile):
"""Get chunks that are relevant to the given render-tile
Returns a list of chunks where each item is
(col, row, chunkx, chunky, regionobj)
Returns an iterator over chunks tuples where each item is
(col, row, chunkx, chunkz, mtime)
"""
chunklist = []
get_region = self.regionobj.regionfiles.get
# Cached region object for consecutive iterations
regionx = None
regiony = None
c = None
mcr = None
rowstart = tile.row
rowend = rowstart+4
colstart = tile.col
@@ -858,19 +849,14 @@ class TileSet(object):
if row % 2 != col % 2:
continue
chunkx, chunky = unconvert_coords(col, row)
chunkx, chunkz = unconvert_coords(col, row)
regionx_ = chunkx//32
regiony_ = chunky//32
if regionx_ != regionx or regiony_ != regiony:
regionx = regionx_
regiony = regiony_
_, _, fname, mcr = get_region((regionx, regiony),(None,None,None,None))
# Query for info on the chunk at chunkx, chunkz
mtime = self.regionset.get_chunk_mtime(chunkx, chunkz)
if mtime:
# The chunk exists
yield (col, row, chunkx, chunkz, mtime)
if fname is not None and self.regionobj.chunk_exists(chunkx,chunky):
chunklist.append((col, row, chunkx, chunky, mcr))
return chunklist
def get_dirdepth(outputdir):
"""Returns the current depth of the tree on disk