Merge remote-tracking branch 'upstream/master'
This commit is contained in:
169
chunk.py
169
chunk.py
@@ -365,140 +365,67 @@ class ChunkRenderer(object):
|
||||
return self._up_left_blocks
|
||||
up_left_blocks = property(_load_up_left_blocks)
|
||||
|
||||
def generate_pseudo_ancildata(self,x,y,z,blockid):
|
||||
def generate_pseudo_ancildata(self,x,y,z,blockid, north_position = 0 ):
|
||||
""" Generates a pseudo ancillary data for blocks that depend of
|
||||
what are surrounded and don't have ancillary data"""
|
||||
what are surrounded and don't have ancillary data
|
||||
|
||||
This uses a binary number of 4 digits to encode the info.
|
||||
The encode is:
|
||||
|
||||
Bit: 1 2 3 4
|
||||
Side: x y -x -y
|
||||
Values: bit = 0 -> The corresponding side block has different blockid
|
||||
bit = 1 -> The corresponding side block has same blockid
|
||||
Example: if the bit1 is 1 that means that there is a block with
|
||||
blockid in the side of the +x direction.
|
||||
|
||||
You can rotate the pseudo data multiplying by 2 and
|
||||
if it is > 15 subtracting 15 and adding 1. (moving bits
|
||||
in the left direction is like rotate 90 degree in anticlockwise
|
||||
direction). In this way can be used for maps with other
|
||||
north orientation.
|
||||
|
||||
North position can have the values 0, 1, 2, 3, corresponding to
|
||||
north in bottom-left, bottom-right, top-right and top-left of
|
||||
the screen.
|
||||
|
||||
The rotation feature is not used anywhere yet.
|
||||
"""
|
||||
|
||||
blocks = self.blocks
|
||||
up_left_blocks = self.up_left_blocks
|
||||
up_right_blocks = self.up_right_blocks
|
||||
left_blocks = self.left_blocks
|
||||
right_blocks = self.right_blocks
|
||||
|
||||
if ( # The block is surrounded by 0 blocks with same blockid
|
||||
(up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and
|
||||
(left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and
|
||||
(right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and
|
||||
(up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid)
|
||||
): return 1
|
||||
|
||||
# Now 3 in line, they should be more common:
|
||||
|
||||
elif ( # The block is surrounded by 2 blocks with same blockid, along x axis
|
||||
(up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and
|
||||
(left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and
|
||||
(right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and
|
||||
(up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid)
|
||||
): return 2
|
||||
pseudo_data = 0
|
||||
|
||||
elif ( # The block is surrounded by 2 blocks with same blockid, along y axis
|
||||
(up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and
|
||||
(left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and
|
||||
(right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and
|
||||
(up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid)
|
||||
): return 3
|
||||
# first check if we are in the border of a chunk, next check for chunks adjacent to this
|
||||
# and finally check for a block with same blockid. I we aren't in the border of a chunk,
|
||||
# check for the block having the sme blockid.
|
||||
|
||||
# Now 3 in corner:
|
||||
if (up_right_blocks != None and up_right_blocks[0,y,z] == blockid) if x == 15 else blocks[x+1,y,z] == blockid:
|
||||
pseudo_data = pseudo_data | 0b1000
|
||||
|
||||
elif ( # The block is surrounded by 2 blocks with same blockid, in a -y to x corner
|
||||
(up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and
|
||||
(left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and
|
||||
(right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and
|
||||
(up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid)
|
||||
): return 4
|
||||
if (right_blocks != None and right_blocks[x,0,z] == blockid) if y == 15 else blocks[x,y + 1,z] == blockid:
|
||||
pseudo_data = pseudo_data | 0b0100
|
||||
|
||||
if (left_blocks != None and left_blocks[15,y,z] == blockid) if x == 0 else blocks[x - 1,y,z] == blockid:
|
||||
pseudo_data = pseudo_data | 0b0010
|
||||
|
||||
if (up_left_blocks != None and up_left_blocks[x,15,z] == blockid) if y == 0 else blocks[x,y - 1,z] == blockid:
|
||||
pseudo_data = pseudo_data | 0b0001
|
||||
|
||||
elif ( # The block is surrounded by 2 blocks with same blockid, in a -y to -x corner
|
||||
(up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and
|
||||
(left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and
|
||||
(right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and
|
||||
(up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid)
|
||||
): return 5
|
||||
# rotate the bits for other north orientations
|
||||
while north_position > 0:
|
||||
pseudo_data *= 2
|
||||
if pseudo_data > 15:
|
||||
pseudo_data -= 16
|
||||
pseudo_data +=1
|
||||
north_position -= 1
|
||||
|
||||
return pseudo_data
|
||||
|
||||
elif ( # The block is surrounded by 2 blocks with same blockid, in a y to -x corner
|
||||
(up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and
|
||||
(left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and
|
||||
(right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and
|
||||
(up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid)
|
||||
): return 6
|
||||
|
||||
elif ( # The block is surrounded by 2 blocks with same blockid, in a y to x corner
|
||||
(up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and
|
||||
(left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and
|
||||
(right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and
|
||||
(up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid)
|
||||
): return 7
|
||||
|
||||
# Now 1 in dead end:
|
||||
|
||||
elif ( # The block is surrounded by 1 blocks with same blockid, in +x
|
||||
(up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and
|
||||
(left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and
|
||||
(right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and
|
||||
(up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid)
|
||||
): return 8
|
||||
|
||||
elif ( # The block is surrounded by 1 blocks with same blockid, in -y
|
||||
(up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and
|
||||
(left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and
|
||||
(right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and
|
||||
(up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid)
|
||||
): return 9
|
||||
|
||||
elif ( # The block is surrounded by 1 blocks with same blockid, in -x
|
||||
(up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and
|
||||
(left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and
|
||||
(right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and
|
||||
(up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid)
|
||||
): return 10
|
||||
|
||||
elif ( # The block is surrounded by 1 blocks with same blockid, in +y
|
||||
(up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and
|
||||
(left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and
|
||||
(right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and
|
||||
(up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid)
|
||||
): return 11
|
||||
|
||||
# Now surrounded by 3 identical blocks:
|
||||
|
||||
elif ( # The block is surrounded by 3 blocks with same blockid, in postiions -x, -y, +x
|
||||
(up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and
|
||||
(left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and
|
||||
(right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and
|
||||
(up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid)
|
||||
): return 12
|
||||
|
||||
elif ( # The block is surrounded by 3 blocks with same blockid, in postiions +y, -y, -x
|
||||
(up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and
|
||||
(left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and
|
||||
(right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and
|
||||
(up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid)
|
||||
): return 13
|
||||
|
||||
elif ( # The block is surrounded by 3 blocks with same blockid, in postiions -x, +y, +x
|
||||
(up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and
|
||||
(left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and
|
||||
(right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and
|
||||
(up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid)
|
||||
): return 14
|
||||
|
||||
elif ( # The block is surrounded by 3 blocks with same blockid, in postiions +y, -y, +x
|
||||
(up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and
|
||||
(left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and
|
||||
(right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and
|
||||
(up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid)
|
||||
): return 15
|
||||
|
||||
# Block completely sourrounded by 4 blocks:
|
||||
|
||||
elif ( # The block is surrounded completely
|
||||
(up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and
|
||||
(left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and
|
||||
(right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and
|
||||
(up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid)
|
||||
): return 16
|
||||
|
||||
else: return None
|
||||
|
||||
def _hash_blockarray(self):
|
||||
"""Finds a hash of the block array"""
|
||||
if hasattr(self, "_digest"):
|
||||
|
||||
Reference in New Issue
Block a user