0

moved iteration code to its own function

This commit is contained in:
Andrew Brown
2010-10-12 00:45:40 -04:00
parent a4c0e786a1
commit 8b7eddf2bf

View File

@@ -64,6 +64,21 @@ def get_blockdata_array(level):
in a similar manner to skylight data"""
return numpy.frombuffer(level['Data'], dtype=numpy.uint8).reshape((16,16,64))
def iterate_chunkblocks(xoff,yoff):
"""Iterates over the 16x16x128 blocks of a chunk in rendering order.
Yields (x,y,z,imgx,imgy)
x,y,z is the block coordinate in the chunk
imgx,imgy is the image offset in the chunk image where that block should go
"""
for x in xrange(15,-1,-1):
for y in xrange(16):
imgx = xoff + x*12 + y*12
imgy = yoff - x*6 + y*6 + 128*12 + 16*12//2
for z in xrange(128):
yield x,y,z,imgx,imgy
imgy -= 12
# This set holds blocks ids that can be seen through, for occlusion calculations
transparent_blocks = set([0, 6, 8, 9, 18, 20, 37, 38, 39, 40, 44, 50, 51, 52, 53,
59, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 81, 83, 85])
@@ -260,12 +275,7 @@ class ChunkRenderer(object):
if not img:
img = Image.new("RGBA", (384, 1728), (38,92,255,0))
for x in xrange(15,-1,-1):
for y in xrange(16):
imgx = xoff + x*12 + y*12
imgy = yoff - x*6 + y*6 + 128*12 + 16*12//2
for z in xrange(128):
try:
for x,y,z,imgx,imgy in iterate_chunkblocks(xoff,yoff):
blockid = blocks[x,y,z]
# the following blocks don't have textures that can be pre-computed from the blockid
@@ -354,11 +364,6 @@ class ChunkRenderer(object):
if y != 0 and blocks[x,y-1,z] == 0:
draw.line(((imgx,imgy+6+increment), (imgx+12,imgy+increment)), fill=(0,0,0), width=1)
finally:
# Do this no mater how the above block exits
imgy -= 12
return img