class TestLightmaps(unittest.TestCase): def setUp(self): self.c = Chunk(0, 0) def test_trivial(self): pass def test_boring_skylight_values(self): # Fill it as if we were the boring generator. for x, z in XZ: self.c.set_block((x, 0, z), 1) self.c.regenerate() # Make sure that all of the blocks at the bottom of the ambient # lightmap are set to 15 (fully illuminated). # Note that skylight of a solid block is 0, the important value # is the skylight of the transluscent (usually air) block above it. for x, z in XZ: self.assertEqual(self.c.get_skylight((x, 0, z)), 0xf) test_boring_skylight_values.todo = "Skylight maths is still broken" def test_skylight_spread(self): # Fill it as if we were the boring generator. for x, z in XZ: self.c.set_block((x, 0, z), 1) # Put a false floor up to block the light. for x, z in product(xrange(1, 15), repeat=2): self.c.set_block((x, 2, z), 1) self.c.regenerate() # Test that a gradient emerges. for x, z in XZ: flipx = x if x > 7 else 15 - x flipz = z if z > 7 else 15 - z target = max(flipx, flipz) self.assertEqual(self.c.get_skylight((x, 1, z)), target, "%d, %d" % (x, z)) test_skylight_spread.todo = "Skylight maths is still broken" def test_skylight_arch(self): """ Indirect illumination should work. """ # Floor. for x, z in XZ: self.c.set_block((x, 0, z), 1) # Arch of bedrock, with an empty spot in the middle, which will be our # indirect spot. for x, y, z in product(xrange(2), xrange(1, 3), xrange(3)): self.c.set_block((x, y, z), 1) self.c.set_block((1, 1, 1), 0) # Illuminate and make sure that our indirect spot has just a little # bit of illumination. self.c.regenerate() self.assertEqual(self.c.get_skylight((1, 1, 1)), 14) test_skylight_arch.todo = "Skylight maths is still broken" def test_skylight_arch_leaves(self): """ Indirect illumination with dimming should work. """ # Floor. for x, z in XZ: self.c.set_block((x, 0, z), 1) # Arch of bedrock, with an empty spot in the middle, which will be our # indirect spot. for x, y, z in product(xrange(2), xrange(1, 3), xrange(3)): self.c.set_block((x, y, z), 1) self.c.set_block((1, 1, 1), 0) # Leaves in front of the spot should cause a dimming of 1. self.c.set_block((2, 1, 1), 18) # Illuminate and make sure that our indirect spot has just a little # bit of illumination. self.c.regenerate() self.assertEqual(self.c.get_skylight((1, 1, 1)), 13) test_skylight_arch_leaves.todo = "Skylight maths is still broken" def test_skylight_arch_leaves_occluded(self): """ Indirect illumination with dimming through occluded blocks only should work. """ # Floor. for x, z in XZ: self.c.set_block((x, 0, z), 1) # Arch of bedrock, with an empty spot in the middle, which will be our # indirect spot. for x, y, z in product(xrange(3), xrange(1, 3), xrange(3)): self.c.set_block((x, y, z), 1) self.c.set_block((1, 1, 1), 0) # Leaves in front of the spot should cause a dimming of 1, but since # the leaves themselves are occluded, the total dimming should be 2. self.c.set_block((2, 1, 1), 18) # Illuminate and make sure that our indirect spot has just a little # bit of illumination. self.c.regenerate() self.assertEqual(self.c.get_skylight((1, 1, 1)), 12) test_skylight_arch_leaves_occluded.todo = "Skylight maths is still broken" def test_incremental_solid(self): """ Regeneration isn't necessary to correctly light solid blocks. """ # Initialize tables and enable set_block(). self.c.regenerate() self.c.populated = True # Any solid block with no dimming works. I choose dirt. self.c.set_block((0, 0, 0), blocks["dirt"].slot) self.assertEqual(self.c.get_skylight((0, 0, 0)), 0) test_incremental_solid.todo = "Skylight maths is still broken" def test_incremental_air(self): """ Regeneration isn't necessary to correctly light dug blocks, which leave behind air. """ # Any solid block with no dimming works. I choose dirt. self.c.set_block((0, 0, 0), blocks["dirt"].slot) # Initialize tables and enable set_block(). self.c.regenerate() self.c.populated = True self.c.set_block((0, 0, 0), blocks["air"].slot) self.assertEqual(self.c.get_skylight((0, 0, 0)), 15)
class TestLightmaps(unittest.TestCase): def setUp(self): self.c = Chunk(0, 0) def test_trivial(self): pass def test_boring_skylight_values(self): # Fill it as if we were the boring generator. for x, z in product(xrange(16), repeat=2): self.c.set_block((x, 0, z), 1) self.c.regenerate() # Make sure that all of the blocks at the bottom of the ambient # lightmap are set to 15 (fully illuminated). # Note that skylight of a solid block is 0, the important value # is the skylight of the transluscent (usually air) block above it. for x, z in product(xrange(16), repeat=2): self.assertEqual(self.c.get_skylight((x, 0, z)), 0xf) def test_skylight_spread(self): # Fill it as if we were the boring generator. for x, z in product(xrange(16), repeat=2): self.c.set_block((x, 0, z), 1) # Put a false floor up to block the light. for x, z in product(xrange(1, 15), repeat=2): self.c.set_block((x, 2, z), 1) self.c.regenerate() # Test that a gradient emerges. for x, z in product(xrange(16), repeat=2): flipx = x if x > 7 else 15 - x flipz = z if z > 7 else 15 - z target = max(flipx, flipz) self.assertEqual(self.c.get_skylight((x, 1, z)), target, "%d, %d" % (x, z)) def test_skylight_arch(self): """ Indirect illumination should work. """ # Floor. for x, z in product(xrange(16), repeat=2): self.c.set_block((x, 0, z), 1) # Arch of bedrock, with an empty spot in the middle, which will be our # indirect spot. for x, y, z in product(xrange(2), xrange(1, 3), xrange(3)): self.c.set_block((x, y, z), 1) self.c.set_block((1, 1, 1), 0) # Illuminate and make sure that our indirect spot has just a little # bit of illumination. self.c.regenerate() self.assertEqual(self.c.get_skylight((1, 1, 1)), 14) def test_skylight_arch_leaves(self): """ Indirect illumination with dimming should work. """ # Floor. for x, z in product(xrange(16), repeat=2): self.c.set_block((x, 0, z), 1) # Arch of bedrock, with an empty spot in the middle, which will be our # indirect spot. for x, y, z in product(xrange(2), xrange(1, 3), xrange(3)): self.c.set_block((x, y, z), 1) self.c.set_block((1, 1, 1), 0) # Leaves in front of the spot should cause a dimming of 1. self.c.set_block((2, 1, 1), 18) # Illuminate and make sure that our indirect spot has just a little # bit of illumination. self.c.regenerate() self.assertEqual(self.c.get_skylight((1, 1, 1)), 13) def test_skylight_arch_leaves_occluded(self): """ Indirect illumination with dimming through occluded blocks only should work. """ # Floor. for x, z in product(xrange(16), repeat=2): self.c.set_block((x, 0, z), 1) # Arch of bedrock, with an empty spot in the middle, which will be our # indirect spot. for x, y, z in product(xrange(3), xrange(1, 3), xrange(3)): self.c.set_block((x, y, z), 1) self.c.set_block((1, 1, 1), 0) # Leaves in front of the spot should cause a dimming of 1, but since # the leaves themselves are occluded, the total dimming should be 2. self.c.set_block((2, 1, 1), 18) # Illuminate and make sure that our indirect spot has just a little # bit of illumination. self.c.regenerate() self.assertEqual(self.c.get_skylight((1, 1, 1)), 12) def test_incremental_solid(self): """ Regeneration isn't necessary to correctly light solid blocks. """ # Initialize tables and enable set_block(). self.c.regenerate() self.c.populated = True # Any solid block with no dimming works. I choose dirt. self.c.set_block((0, 0, 0), blocks["dirt"].slot) self.assertEqual(self.c.get_skylight((0, 0, 0)), 0) def test_incremental_air(self): """ Regeneration isn't necessary to correctly light dug blocks, which leave behind air. """ # Any solid block with no dimming works. I choose dirt. self.c.set_block((0, 0, 0), blocks["dirt"].slot) # Initialize tables and enable set_block(). self.c.regenerate() self.c.populated = True self.c.set_block((0, 0, 0), blocks["air"].slot) self.assertEqual(self.c.get_skylight((0, 0, 0)), 15)