More World->RegionSet conversions. still broken
This commit is contained in:
@@ -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
|
# in the region files and caches chunk modified times, and determines the
|
||||||
# chunk bounds (max and min in both dimensions)
|
# chunk bounds (max and min in both dimensions)
|
||||||
w = world.World(worlddir)
|
w = world.World(worlddir)
|
||||||
|
rset = w.get_regionsets()[0] # use the default
|
||||||
if north_direction == 'auto':
|
if north_direction == 'auto':
|
||||||
# TODO get this from the asset manager # north_direction = w.persistentData['north_direction']
|
# TODO get this from the asset manager # north_direction = w.persistentData['north_direction']
|
||||||
options.north_direction = 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:
|
for rendermode in options.rendermode:
|
||||||
if rendermode == 'normal':
|
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:
|
else:
|
||||||
qtree = quadtree.QuadtreeGen(w, destdir, rendermode=rendermode, **qtree_args)
|
qtree = quadtree.QuadtreeGen(rset, destdir, rendermode=rendermode, **qtree_args)
|
||||||
q.append(qtree)
|
q.append(qtree)
|
||||||
|
|
||||||
# Make sure the quadtrees are the correct depth
|
# Make sure the quadtrees are the correct depth
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ image
|
|||||||
# alpha_over extension, BUT this extension may fall back to PIL's
|
# alpha_over extension, BUT this extension may fall back to PIL's
|
||||||
# paste(), which DOES need the workaround.)
|
# 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
|
"""Takes a filename and chunkcoords and returns the Level struct, which contains all the
|
||||||
level info"""
|
level info"""
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ def get_lvldata(world, filename, x, y, retries=2):
|
|||||||
raise NoSuchChunk
|
raise NoSuchChunk
|
||||||
|
|
||||||
try:
|
try:
|
||||||
d = world.load_from_region(filename, x, y)
|
d = region.get_chunk(x, y)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
if retries > 0:
|
if retries > 0:
|
||||||
# wait a little bit, and try again (up to `retries` times)
|
# 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):
|
def get_blockdata_array(level):
|
||||||
"""Returns the ancillary data from the 'Data' byte array. Data is packed
|
"""Returns the ancillary data from the 'Data' byte array. Data is packed
|
||||||
in a similar manner to skylight data"""
|
in a similar manner to skylight data"""
|
||||||
|
print level.keys()
|
||||||
return level['Data']
|
return level['Data']
|
||||||
|
|
||||||
def get_tileentity_data(level):
|
def get_tileentity_data(level):
|
||||||
@@ -132,15 +133,16 @@ class NoSuchChunk(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class ChunkRenderer(object):
|
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.
|
"""Make a new chunk renderer for the given chunk coordinates.
|
||||||
chunkcoors should be a tuple: (chunkX, chunkY)
|
chunkcoors should be a tuple: (chunkX, chunkY)
|
||||||
|
|
||||||
cachedir is a directory to save the resulting chunk images to
|
cachedir is a directory to save the resulting chunk images to
|
||||||
"""
|
"""
|
||||||
self.queue = queue
|
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):
|
#if not os.path.exists(self.regionfile):
|
||||||
# raise ValueError("Could not find regionfile: %s" % self.regionfile)
|
# raise ValueError("Could not find regionfile: %s" % self.regionfile)
|
||||||
|
|
||||||
@@ -158,14 +160,13 @@ class ChunkRenderer(object):
|
|||||||
self.chunkX = chunkcoords[0]
|
self.chunkX = chunkcoords[0]
|
||||||
self.chunkY = chunkcoords[1]
|
self.chunkY = chunkcoords[1]
|
||||||
|
|
||||||
self.world = worldobj
|
|
||||||
self.rendermode = rendermode
|
self.rendermode = rendermode
|
||||||
|
|
||||||
def _load_level(self):
|
def _load_level(self):
|
||||||
"""Loads and returns the level structure"""
|
"""Loads and returns the level structure"""
|
||||||
if not hasattr(self, "_level"):
|
if not hasattr(self, "_level"):
|
||||||
try:
|
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:
|
except NoSuchChunk, e:
|
||||||
logging.debug("Skipping non-existant chunk")
|
logging.debug("Skipping non-existant chunk")
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ class MapGen(object):
|
|||||||
raise ValueError("there must be at least one quadtree to work on")
|
raise ValueError("there must be at least one quadtree to work on")
|
||||||
|
|
||||||
self.destdir = quadtrees[0].destdir
|
self.destdir = quadtrees[0].destdir
|
||||||
self.world = quadtrees[0].world
|
self.regionobj = quadtrees[0].regionobj
|
||||||
self.p = quadtrees[0].p
|
self.p = quadtrees[0].p
|
||||||
for i in quadtrees:
|
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")
|
raise ValueError("all the given quadtrees must have the same destdir and world")
|
||||||
|
|
||||||
self.quadtrees = quadtrees
|
self.quadtrees = quadtrees
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ class QuadtreeGen(object):
|
|||||||
chunklist = []
|
chunklist = []
|
||||||
|
|
||||||
unconvert_coords = util.unconvert_coords
|
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
|
# Cached region object for consecutive iterations
|
||||||
regionx = None
|
regionx = None
|
||||||
@@ -268,7 +268,7 @@ class QuadtreeGen(object):
|
|||||||
regiony = regiony_
|
regiony = regiony_
|
||||||
_, _, fname, mcr = get_region((regionx, regiony),(None,None,None,None))
|
_, _, 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))
|
chunklist.append((col, row, chunkx, chunky, mcr))
|
||||||
|
|
||||||
return chunklist
|
return chunklist
|
||||||
@@ -393,14 +393,14 @@ class QuadtreeGen(object):
|
|||||||
# The poi_q (point of interest queue) is a multiprocessing Queue
|
# The poi_q (point of interest queue) is a multiprocessing Queue
|
||||||
# object, and it gets stashed in the world object by the constructor to
|
# object, and it gets stashed in the world object by the constructor to
|
||||||
# RenderNode so we can find it right here.
|
# 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)
|
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)
|
chunks = self.get_chunks_for_tile(tile)
|
||||||
|
|
||||||
world = self.world
|
region = self.regionobj
|
||||||
|
|
||||||
tile_mtime = None
|
tile_mtime = None
|
||||||
if check_tile:
|
if check_tile:
|
||||||
@@ -500,7 +500,7 @@ class QuadtreeGen(object):
|
|||||||
|
|
||||||
# draw the chunk!
|
# draw the chunk!
|
||||||
try:
|
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)
|
a.chunk_render(tileimg, xpos, ypos, None)
|
||||||
except chunk.ChunkCorrupt:
|
except chunk.ChunkCorrupt:
|
||||||
# an error was already printed
|
# an error was already printed
|
||||||
@@ -543,7 +543,7 @@ class QuadtreeGen(object):
|
|||||||
#
|
#
|
||||||
# IDEA: check last render time against mtime of the region to short
|
# IDEA: check last render time against mtime of the region to short
|
||||||
# circuit checking mtimes of all chunks in a region
|
# 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
|
chunkcount += 1
|
||||||
#if chunkcount % 10000 == 0:
|
#if chunkcount % 10000 == 0:
|
||||||
# logging.info(" %s chunks scanned", chunkcount)
|
# logging.info(" %s chunks scanned", chunkcount)
|
||||||
|
|||||||
@@ -72,13 +72,15 @@ def pool_initializer(rendernode):
|
|||||||
|
|
||||||
# load biome data in each process, if needed
|
# load biome data in each process, if needed
|
||||||
for qtree in rendernode.quadtrees:
|
for qtree in rendernode.quadtrees:
|
||||||
if qtree.world.useBiomeData:
|
## TODO biome stuffs
|
||||||
# make sure we've at least *tried* to load the color arrays in this process...
|
pass
|
||||||
textures.prepareBiomeData(qtree.world.worlddir)
|
#if qtree.world.useBiomeData:
|
||||||
if not textures.grasscolor or not textures.foliagecolor:
|
# # make sure we've at least *tried* to load the color arrays in this process...
|
||||||
raise Exception("Can't find grasscolor.png or foliagecolor.png")
|
# textures.prepareBiomeData(qtree.world.worlddir)
|
||||||
# only load biome data once
|
# if not textures.grasscolor or not textures.foliagecolor:
|
||||||
break
|
# raise Exception("Can't find grasscolor.png or foliagecolor.png")
|
||||||
|
# # only load biome data once
|
||||||
|
# break
|
||||||
|
|
||||||
|
|
||||||
class RenderNode(object):
|
class RenderNode(object):
|
||||||
@@ -110,12 +112,12 @@ class RenderNode(object):
|
|||||||
|
|
||||||
#bind an index value to the quadtree so we can find it again
|
#bind an index value to the quadtree so we can find it again
|
||||||
#and figure out which worlds are where
|
#and figure out which worlds are where
|
||||||
self.worlds = []
|
self.regionsets = []
|
||||||
for i, q in enumerate(quadtrees):
|
for i, q in enumerate(quadtrees):
|
||||||
q._render_index = i
|
q._render_index = i
|
||||||
i += 1
|
i += 1
|
||||||
if q.world not in self.worlds:
|
if q.regionobj not in self.regionsets:
|
||||||
self.worlds.append(q.world)
|
self.regionsets.append(q.regionobj)
|
||||||
|
|
||||||
# queue for receiving interesting events from the renderer
|
# queue for receiving interesting events from the renderer
|
||||||
# (like the discovery of signs!)
|
# (like the discovery of signs!)
|
||||||
@@ -127,7 +129,7 @@ class RenderNode(object):
|
|||||||
# is to ease debugging and profiling by keeping everything in one
|
# is to ease debugging and profiling by keeping everything in one
|
||||||
# process/thread)
|
# process/thread)
|
||||||
manager = multiprocessing.Manager()
|
manager = multiprocessing.Manager()
|
||||||
for world in self.worlds:
|
for world in self.regionsets:
|
||||||
world.poi_q = manager.Queue()
|
world.poi_q = manager.Queue()
|
||||||
|
|
||||||
self._last_print_count = 0
|
self._last_print_count = 0
|
||||||
|
|||||||
@@ -282,7 +282,25 @@ its x, z coordinates. The coordinates are chunk coordinates.
|
|||||||
regioninfo = self.regions[regionfile]
|
regioninfo = self.regions[regionfile]
|
||||||
if regioninfo is None:
|
if regioninfo is None:
|
||||||
return 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):
|
def iterate_chunks(self):
|
||||||
"""Returns an iterator over all chunk metadata in this world. Iterates over tuples
|
"""Returns an iterator over all chunk metadata in this world. Iterates over tuples
|
||||||
|
|||||||
Reference in New Issue
Block a user