0

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.
This commit is contained in:
Andrew Brown
2012-01-01 19:55:08 -05:00
parent b1d5dee84d
commit b2da6d5b0a

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 """Construct a new TileSet object with the given configuration options
dictionary. dictionary.
@@ -163,6 +163,9 @@ class TileSet(object):
assetmanagerobj is the AssetManager object that represents the assetmanagerobj is the AssetManager object that represents the
destination directory where we'll put our tiles. 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 outputdir is the absolute path to the tile output directory where the
tiles are saved. It is assumed to exist already. tiles are saved. It is assumed to exist already.
TODO: This should probably be relative to the asset manager's output TODO: This should probably be relative to the asset manager's output
@@ -241,6 +244,7 @@ class TileSet(object):
self.options = options self.options = options
self.regionset = regionsetobj self.regionset = regionsetobj
self.am = assetmanagerobj self.am = assetmanagerobj
self.textures = texturesobj
# Throughout the class, self.outputdir is an absolute path to the # Throughout the class, self.outputdir is an absolute path to the
# directory where we output tiles. It is assumed to exist. # 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) imgpath = tile.get_filepath(self.full_tiledir, self.imgformat)
# Calculate which chunks are relevant to this tile # 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 region = self.regionobj
@@ -784,15 +789,6 @@ class TileSet(object):
if e.errno != errno.EEXIST: if e.errno != errno.EEXIST:
raise 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)) #logging.debug("writing out worldtile {0}".format(imgpath))
# Compile this image # Compile this image
@@ -803,17 +799,16 @@ class TileSet(object):
rowstart = tile.row rowstart = tile.row
# col colstart will get drawn on the image starting at x coordinates -(384/2) # 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) # 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 xpos = -192 + (col-colstart)*192
ypos = -96 + (row-rowstart)*96 ypos = -96 + (row-rowstart)*96
if chunk_mtime > max_chunk_mtime:
max_chunk_mtime = chunk_mtime
# draw the chunk! # draw the chunk!
try: # TODO RENDER THE CHUNK
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
# Save them # Save them
if self.imgformat == 'jpg': if self.imgformat == 'jpg':
@@ -829,20 +824,12 @@ class TileSet(object):
def _get_chunks_for_tile(self, tile): def _get_chunks_for_tile(self, tile):
"""Get chunks that are relevant to the given render-tile """Get chunks that are relevant to the given render-tile
Returns a list of chunks where each item is Returns an iterator over chunks tuples where each item is
(col, row, chunkx, chunky, regionobj) (col, row, chunkx, chunkz, mtime)
""" """
chunklist = [] chunklist = []
get_region = self.regionobj.regionfiles.get
# Cached region object for consecutive iterations
regionx = None
regiony = None
c = None
mcr = None
rowstart = tile.row rowstart = tile.row
rowend = rowstart+4 rowend = rowstart+4
colstart = tile.col colstart = tile.col
@@ -858,19 +845,14 @@ class TileSet(object):
if row % 2 != col % 2: if row % 2 != col % 2:
continue continue
chunkx, chunky = unconvert_coords(col, row) chunkx, chunkz = unconvert_coords(col, row)
regionx_ = chunkx//32 # Query for info on the chunk at chunkx, chunkz
regiony_ = chunky//32 mtime = self.regionset.get_chunk_mtime(chunkx, chunkz)
if regionx_ != regionx or regiony_ != regiony: if mtime:
regionx = regionx_ # The chunk exists
regiony = regiony_ yield (col, row, chunkx, chunkz, mtime)
_, _, 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))
return chunklist
def get_dirdepth(outputdir): def get_dirdepth(outputdir):
"""Returns the current depth of the tree on disk """Returns the current depth of the tree on disk