Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. private void updateLightMap(Block[][][] blocks){
  2.         lightMap = new byte[chunkSizeXZ][chunkSizeY][chunkSizeXZ];
  3. //      Logger.info("Updating Voxel Lightmap.");
  4.         Queue<Vector3i> litPoints = new LinkedList<Vector3i>();
  5.        
  6.         for (int x = 0; x < chunkSizeXZ; x++) {
  7.             for (int y = 0; y < chunkSizeY; y++) {
  8.                 for (int z = 0; z < chunkSizeXZ; z++) {
  9.                     Block block = blocks[x][y][z];
  10.                     if(block.LightOutput() > 0){
  11.                         //Logger.info("Light Source: " + x + ", " + z);
  12.                         for (Vector3i neighbour : getNeighbours(x, y, z, false)) {
  13.                             litPoints.add(neighbour);
  14.                         }
  15.                         lightMap[x][y][z] = block.LightOutput();
  16.                     }else{
  17.                         if(x == chunkSizeXZ - 1 || z == chunkSizeXZ - 1 || x == 0 || z == 0){
  18.                             litPoints.add(new Vector3i(x, y, z));
  19.                         }
  20.                     }
  21.                 }
  22.             }
  23.         }  
  24.        
  25.         long startTimeLoopPoints = System.nanoTime();
  26.         while(!litPoints.isEmpty()){
  27.             Vector3i point = litPoints.poll();
  28.            
  29.             int x = (int) point.x, y = (int) point.y, z = (int) point.z;
  30.            
  31.             //Logger.info(x + ", " + z);
  32.            
  33.             Vector3i[] neighbours = getNeighbours(x, y, z, false);
  34.            
  35.             byte highestLightLvl = getHighestNeighbourLightLevel(getNeighbours(x, y, z, true));
  36.            
  37.             if(highestLightLvl <= 1) continue;
  38.            
  39.             setLightLvl(x, y, z, (byte)(highestLightLvl - 1));
  40.                        
  41.             //Logger.info("Spaces light level: " + (highestLightLvl - 1));
  42.            
  43.             for (int i = 0; i < neighbours.length; i++) {
  44.                 Vector3i neighbour = neighbours[i];
  45.                 if(getLightLvl(neighbour.x, neighbour.y, neighbour.z) < getHighestNeighbourLightLevel(getNeighbours(x, y, z, true))){
  46.                     litPoints.add(neighbour);
  47.                 }
  48.             }
  49.             //Logger.info("Processed Space " + x + ", " + y + ", " + z);
  50.             //Logger.info("");
  51.         }
  52.         long estimatedTimeLoopPoints = System.nanoTime() - startTimeLoopPoints;
  53.         Logger.debug("Chunk(" + pos + ") -> updateLightMap -> Loop Points -> Execution Time: " + (estimatedTimeLoopPoints / 1000000 / 1000f) + "s");
  54. //      Logger.info("Complete Light Map Algorithm!");
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement