0

More World->RegionSet conversions. still broken

This commit is contained in:
Andrew Chin
2011-12-22 00:23:20 -05:00
parent ffbd019db5
commit 9b06d980af
6 changed files with 50 additions and 28 deletions

View File

@@ -415,6 +415,7 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
# in the region files and caches chunk modified times, and determines the
# chunk bounds (max and min in both dimensions)
w = world.World(worlddir)
rset = w.get_regionsets()[0] # use the default
if north_direction == 'auto':
# TODO get this from the asset manager # north_direction = w.persistentData['north_direction']
options.north_direction = north_direction
@@ -448,9 +449,9 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
}
for rendermode in options.rendermode:
if rendermode == 'normal':
qtree = quadtree.QuadtreeGen(w, destdir, rendermode=rendermode, tiledir='tiles', **qtree_args)
qtree = quadtree.QuadtreeGen(rset, destdir, rendermode=rendermode, tiledir='tiles', **qtree_args)
else:
qtree = quadtree.QuadtreeGen(w, destdir, rendermode=rendermode, **qtree_args)
qtree = quadtree.QuadtreeGen(rset, destdir, rendermode=rendermode, **qtree_args)
q.append(qtree)
# Make sure the quadtrees are the correct depth

View File

@@ -46,7 +46,7 @@ image
# alpha_over extension, BUT this extension may fall back to PIL's
# paste(), which DOES need the workaround.)
def get_lvldata(world, filename, x, y, retries=2):
def get_lvldata(region, filename, x, y, retries=2):
"""Takes a filename and chunkcoords and returns the Level struct, which contains all the
level info"""
@@ -55,7 +55,7 @@ def get_lvldata(world, filename, x, y, retries=2):
raise NoSuchChunk
try:
d = world.load_from_region(filename, x, y)
d = region.get_chunk(x, y)
except Exception, e:
if retries > 0:
# wait a little bit, and try again (up to `retries` times)
@@ -118,6 +118,7 @@ def get_blocklight_array(level):
def get_blockdata_array(level):
"""Returns the ancillary data from the 'Data' byte array. Data is packed
in a similar manner to skylight data"""
print level.keys()
return level['Data']
def get_tileentity_data(level):
@@ -132,15 +133,16 @@ class NoSuchChunk(Exception):
pass
class ChunkRenderer(object):
def __init__(self, chunkcoords, worldobj, rendermode, queue):
def __init__(self, chunkcoords, regionobj, rendermode, queue):
"""Make a new chunk renderer for the given chunk coordinates.
chunkcoors should be a tuple: (chunkX, chunkY)
cachedir is a directory to save the resulting chunk images to
"""
self.queue = queue
self.region = regionobj
self.regionfile = worldobj.get_region_path(*chunkcoords)
self.regionfile = regionobj.get_region_path(*chunkcoords)
#if not os.path.exists(self.regionfile):
# raise ValueError("Could not find regionfile: %s" % self.regionfile)
@@ -158,14 +160,13 @@ class ChunkRenderer(object):
self.chunkX = chunkcoords[0]
self.chunkY = chunkcoords[1]
self.world = worldobj
self.rendermode = rendermode
def _load_level(self):
"""Loads and returns the level structure"""
if not hasattr(self, "_level"):
try:
self._level = get_lvldata(self.world,self.regionfile, self.chunkX, self.chunkY)
self._level = get_lvldata(self.region,self.regionfile, self.chunkX, self.chunkY)
except NoSuchChunk, e:
logging.debug("Skipping non-existant chunk")
raise

View File

@@ -89,10 +89,10 @@ class MapGen(object):
raise ValueError("there must be at least one quadtree to work on")
self.destdir = quadtrees[0].destdir
self.world = quadtrees[0].world
self.regionobj = quadtrees[0].regionobj
self.p = quadtrees[0].p
for i in quadtrees:
if i.destdir != self.destdir or i.world != self.world:
if i.destdir != self.destdir or i.regionobj != self.regionobj:
raise ValueError("all the given quadtrees must have the same destdir and world")
self.quadtrees = quadtrees

View File

@@ -236,7 +236,7 @@ class QuadtreeGen(object):
chunklist = []
unconvert_coords = util.unconvert_coords
get_region = self.world.get_regionsets()[0].regionfiles.get
get_region = self.regionobj.regionfiles.get
# Cached region object for consecutive iterations
regionx = None
@@ -268,7 +268,7 @@ class QuadtreeGen(object):
regiony = regiony_
_, _, fname, mcr = get_region((regionx, regiony),(None,None,None,None))
if fname is not None and mcr.chunkExists(chunkx,chunky):
if fname is not None and self.regionobj.chunk_exists(chunkx,chunky):
chunklist.append((col, row, chunkx, chunky, mcr))
return chunklist
@@ -393,14 +393,14 @@ class QuadtreeGen(object):
# The poi_q (point of interest queue) is a multiprocessing Queue
# object, and it gets stashed in the world object by the constructor to
# RenderNode so we can find it right here.
poi_queue = self.world.poi_q
poi_queue = self.regionobj.poi_q
imgpath = tile.get_filepath(self.full_tiledir, self.imgformat)
# Calculate which chunks are relevant to this tile
chunks = self.get_chunks_for_tile(tile)
world = self.world
region = self.regionobj
tile_mtime = None
if check_tile:
@@ -500,7 +500,7 @@ class QuadtreeGen(object):
# draw the chunk!
try:
a = chunk.ChunkRenderer((chunkx, chunky), world, rendermode, poi_queue)
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
@@ -543,7 +543,7 @@ class QuadtreeGen(object):
#
# IDEA: check last render time against mtime of the region to short
# circuit checking mtimes of all chunks in a region
for chunkx, chunky, chunkmtime in self.world.get_regionsets()[0].iterate_chunks():
for chunkx, chunky, chunkmtime in self.regionobj.iterate_chunks():
chunkcount += 1
#if chunkcount % 10000 == 0:
# logging.info(" %s chunks scanned", chunkcount)

View File

@@ -72,13 +72,15 @@ def pool_initializer(rendernode):
# load biome data in each process, if needed
for qtree in rendernode.quadtrees:
if qtree.world.useBiomeData:
# make sure we've at least *tried* to load the color arrays in this process...
textures.prepareBiomeData(qtree.world.worlddir)
if not textures.grasscolor or not textures.foliagecolor:
raise Exception("Can't find grasscolor.png or foliagecolor.png")
# only load biome data once
break
## TODO biome stuffs
pass
#if qtree.world.useBiomeData:
# # make sure we've at least *tried* to load the color arrays in this process...
# textures.prepareBiomeData(qtree.world.worlddir)
# if not textures.grasscolor or not textures.foliagecolor:
# raise Exception("Can't find grasscolor.png or foliagecolor.png")
# # only load biome data once
# break
class RenderNode(object):
@@ -110,12 +112,12 @@ class RenderNode(object):
#bind an index value to the quadtree so we can find it again
#and figure out which worlds are where
self.worlds = []
self.regionsets = []
for i, q in enumerate(quadtrees):
q._render_index = i
i += 1
if q.world not in self.worlds:
self.worlds.append(q.world)
if q.regionobj not in self.regionsets:
self.regionsets.append(q.regionobj)
# queue for receiving interesting events from the renderer
# (like the discovery of signs!)
@@ -127,7 +129,7 @@ class RenderNode(object):
# is to ease debugging and profiling by keeping everything in one
# process/thread)
manager = multiprocessing.Manager()
for world in self.worlds:
for world in self.regionsets:
world.poi_q = manager.Queue()
self._last_print_count = 0

View File

@@ -282,7 +282,25 @@ its x, z coordinates. The coordinates are chunk coordinates.
regioninfo = self.regions[regionfile]
if regioninfo is None:
return None
return regioninfo[0].load_chunk(x,z)
data = regioninfo[0].load_chunk(x,z)
level = chunk_data[1]['Level']
chunk_data = level
chunk_data['Blocks'] = numpy.array(numpy.rot90(numpy.frombuffer(
level['Blocks'], dtype=numpy.uint8).reshape((16,16,128)),
self._get_north_rotations()))
chunk_data['Data'] = numpy.array(numpy.rot90(numpy.frombuffer(
level['Data'], dtype=numpy.uint8).reshape((16,16,64)),
self._get_north_rotations()))
chunk_data['SkyLight'] = numpy.array(numpy.rot90(numpy.frombuffer(
level['SkyLight'], dtype=numpy.uint8).reshape((16,16,64)),
self._get_north_rotations()))
chunk_data['BlockLight'] = numpy.array(numpy.rot90(numpy.frombuffer(
level['BlockLight'], dtype=numpy.uint8).reshape((16,16,64)),
self._get_north_rotations()))
## TODO some clever caching stuff
return chunk_data
def iterate_chunks(self):
"""Returns an iterator over all chunk metadata in this world. Iterates over tuples