Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void updateLightMap(Block[][][] blocks){
- lightMap = new byte[chunkSizeXZ][chunkSizeY][chunkSizeXZ];
- // Logger.info("Updating Voxel Lightmap.");
- Queue<Vector3i> litPoints = new LinkedList<Vector3i>();
- for (int x = 0; x < chunkSizeXZ; x++) {
- for (int y = 0; y < chunkSizeY; y++) {
- for (int z = 0; z < chunkSizeXZ; z++) {
- Block block = blocks[x][y][z];
- if(block.LightOutput() > 0){
- //Logger.info("Light Source: " + x + ", " + z);
- for (Vector3i neighbour : getNeighbours(x, y, z, false)) {
- litPoints.add(neighbour);
- }
- lightMap[x][y][z] = block.LightOutput();
- }else{
- if(x == chunkSizeXZ - 1 || z == chunkSizeXZ - 1 || x == 0 || z == 0){
- litPoints.add(new Vector3i(x, y, z));
- }
- }
- }
- }
- }
- long startTimeLoopPoints = System.nanoTime();
- while(!litPoints.isEmpty()){
- Vector3i point = litPoints.poll();
- int x = (int) point.x, y = (int) point.y, z = (int) point.z;
- //Logger.info(x + ", " + z);
- Vector3i[] neighbours = getNeighbours(x, y, z, false);
- byte highestLightLvl = getHighestNeighbourLightLevel(getNeighbours(x, y, z, true));
- if(highestLightLvl <= 1) continue;
- setLightLvl(x, y, z, (byte)(highestLightLvl - 1));
- //Logger.info("Spaces light level: " + (highestLightLvl - 1));
- for (int i = 0; i < neighbours.length; i++) {
- Vector3i neighbour = neighbours[i];
- if(getLightLvl(neighbour.x, neighbour.y, neighbour.z) < getHighestNeighbourLightLevel(getNeighbours(x, y, z, true))){
- litPoints.add(neighbour);
- }
- }
- //Logger.info("Processed Space " + x + ", " + y + ", " + z);
- //Logger.info("");
- }
- long estimatedTimeLoopPoints = System.nanoTime() - startTimeLoopPoints;
- Logger.debug("Chunk(" + pos + ") -> updateLightMap -> Loop Points -> Execution Time: " + (estimatedTimeLoopPoints / 1000000 / 1000f) + "s");
- // Logger.info("Complete Light Map Algorithm!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement