0

Optimization: Chunk.py checks in adjacents chunks to render or not blocks.

This commit is contained in:
Alejandro Aguilera
2010-12-13 23:17:56 +01:00
parent e70bafb453
commit 07383f6d5d

View File

@@ -483,6 +483,9 @@ class ChunkRenderer(object):
depth.""" depth."""
blocks = self.blocks blocks = self.blocks
left_blocks = self.left_blocks
right_blocks = self.right_blocks
if cave: if cave:
# Cave mode. Actually go through and 0 out all blocks that are not in a # Cave mode. Actually go through and 0 out all blocks that are not in a
# cave, so that it only renders caves. # cave, so that it only renders caves.
@@ -590,18 +593,27 @@ class ChunkRenderer(object):
blocks[x,y,z+1] not in transparent_blocks blocks[x,y,z+1] not in transparent_blocks
): ):
continue continue
elif ( elif (left_blocks == None or (right_blocks == None)):
# Normal block or not cave mode, check sides for # Normal block or not cave mode, check sides for
# transparentcy or render unconditionally if it's # transparentcy or render if it's a border chunk.
# on a shown face
if (
x != 0 and y != 15 and z != 127 and x != 0 and y != 15 and z != 127 and
blocks[x-1,y,z] not in transparent_blocks and blocks[x-1,y,z] not in transparent_blocks and
blocks[x,y+1,z] not in transparent_blocks and blocks[x,y+1,z] not in transparent_blocks and
blocks[x,y,z+1] not in transparent_blocks blocks[x,y,z+1] not in transparent_blocks
): ):
# Don't render if all sides aren't transparent and continue
# we're not on the edge elif (
continue # If it's a interior chunk check for transparent blocks
# in the adjacent chunks.
z != 127 and
(left_blocks[15,y,z] if x == 0 else blocks[x - 1,y,z]) not in transparent_blocks and
(right_blocks[x,0,z] if y == 15 else blocks[x,y + 1,z]) not in transparent_blocks and
blocks[x,y,z+1] not in transparent_blocks
# Don't render if all sides aren't transparent
):
continue
# Draw the actual block on the image. For cave images, # Draw the actual block on the image. For cave images,
# tint the block with a color proportional to its depth # tint the block with a color proportional to its depth