From b2da6d5b0a53a2cd28be578454134d300425fd71 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sun, 1 Jan 2012 19:55:08 -0500 Subject: [PATCH 1/2] TileSet updated for new RegionSet API Except for a couple outstanding TODOs, TileSet is ready for action. One of them is necessary: the call to the c renderer is not in yet. --- overviewer_core/tileset.py | 60 +++++++++++++------------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/overviewer_core/tileset.py b/overviewer_core/tileset.py index be2eecc..21556f9 100644 --- a/overviewer_core/tileset.py +++ b/overviewer_core/tileset.py @@ -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. @@ -744,7 +748,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 +789,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 +799,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 +824,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 +845,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)) - - if fname is not None and self.regionobj.chunk_exists(chunkx,chunky): - chunklist.append((col, row, chunkx, chunky, mcr)) + # 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) - return chunklist def get_dirdepth(outputdir): """Returns the current depth of the tree on disk From c866f2512b6e8741a24756774ce9503435c5cd25 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sun, 1 Jan 2012 20:08:25 -0500 Subject: [PATCH 2/2] fixed typos, clarified comments in tileset.py --- overviewer_core/tileset.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/overviewer_core/tileset.py b/overviewer_core/tileset.py index 21556f9..0e4c4d0 100644 --- a/overviewer_core/tileset.py +++ b/overviewer_core/tileset.py @@ -504,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 @@ -535,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: @@ -549,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 @@ -606,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 @@ -627,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)