diff --git a/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java b/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java index eac6e0061..5469bcc88 100644 --- a/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBufferBuilder.java @@ -390,8 +390,6 @@ public class LodBufferBuilder }); mainGenThread.execute(thread); - - return; } //===============================// diff --git a/src/main/java/com/seibel/lod/builders/LodBuilder.java b/src/main/java/com/seibel/lod/builders/LodBuilder.java index f88d1ec20..58a3f9e6d 100644 --- a/src/main/java/com/seibel/lod/builders/LodBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBuilder.java @@ -318,7 +318,7 @@ public class LodBuilder //If the lod is at default, then we set this as void data if (height == DEFAULT_HEIGHT) { - dataToMerge[index * verticalData + 0] = DataPointUtil.createVoidDataPoint(generation); + dataToMerge[index * verticalData] = DataPointUtil.createVoidDataPoint(generation); break; } @@ -417,9 +417,7 @@ public class LodBuilder } } if (!voidData) - { break; - } } } return height; @@ -884,14 +882,10 @@ public class LodBuilder } } - if (blockState.getBlock() != Blocks.AIR - && blockState.getBlock() != Blocks.CAVE_AIR - && blockState.getBlock() != Blocks.BARRIER) - { - return true; - } + return blockState.getBlock() != Blocks.AIR + && blockState.getBlock() != Blocks.CAVE_AIR + && blockState.getBlock() != Blocks.BARRIER; } - return false; } } diff --git a/src/main/java/com/seibel/lod/builders/lodTemplates/Box.java b/src/main/java/com/seibel/lod/builders/lodTemplates/Box.java index 3b5601159..e6ccf9328 100644 --- a/src/main/java/com/seibel/lod/builders/lodTemplates/Box.java +++ b/src/main/java/com/seibel/lod/builders/lodTemplates/Box.java @@ -1,5 +1,6 @@ package com.seibel.lod.builders.lodTemplates; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -164,10 +165,7 @@ public class Box { for (int i = 0; i < box.length; i++) { - for (int j = 0; j < box[i].length; j++) - { - box[i][j] = 0; - } + Arrays.fill(box[i], 0); } for (Direction direction : DIRECTIONS) @@ -175,8 +173,7 @@ public class Box colorMap.get(direction)[0] = 0; } - for(int i = 0; i < order.length; i++) - order[i] = DataPointUtil.EMPTY_DATA; + Arrays.fill(order, DataPointUtil.EMPTY_DATA); for (Direction direction : ADJ_DIRECTIONS) { if(isCulled(direction)){ @@ -274,66 +271,64 @@ public class Box height = DataPointUtil.getHeight(singleAdjDataPoint); depth = DataPointUtil.getDepth(singleAdjDataPoint); - if (depth > maxY) - {//the adj data is higher than the current data - //we continue since there could be some other data that intersect the current - continue; - } else if (height < minY) - {//the adj data is lower than the current data - //we break since all the other data will be lower + if (depth <= maxY) { + if (height < minY) + {//the adj data is lower than the current data + //we break since all the other data will be lower - if (firstFace) - { - adjHeightAndDepth.get(direction)[0][0] = getMaxY(); - adjHeightAndDepth.get(direction)[0][1] = getMinY(); - } else - { - adjHeightAndDepth.get(direction)[faceToDraw][1] = getMinY(); - } - faceToDraw++; - toFinish = false; - break; - } else if (depth <= minY && height >= maxY) - {//the adj data contains the current - //we do not draw the face - adjHeightAndDepth.get(direction)[0][0] = VOID_FACE; - adjHeightAndDepth.get(direction)[0][1] = VOID_FACE; - break; - } else if (depth <= minY && height < maxY) - {//the adj data intersect the lower part of the current data - //if this is the only face we use the maxY and break - //if there was other face we finish the last one and break - if (firstFace) - { - adjHeightAndDepth.get(direction)[0][0] = getMaxY(); - adjHeightAndDepth.get(direction)[0][1] = height; - } else - { + if (firstFace) + { + adjHeightAndDepth.get(direction)[0][0] = getMaxY(); + adjHeightAndDepth.get(direction)[0][1] = getMinY(); + } else + { + adjHeightAndDepth.get(direction)[faceToDraw][1] = getMinY(); + } + faceToDraw++; + toFinish = false; + break; + } else if (depth <= minY && height >= maxY) + {//the adj data contains the current + //we do not draw the face + adjHeightAndDepth.get(direction)[0][0] = VOID_FACE; + adjHeightAndDepth.get(direction)[0][1] = VOID_FACE; + break; + } else if (depth <= minY)//&& height < maxY + {//the adj data intersect the lower part of the current data + //if this is the only face we use the maxY and break + //if there was other face we finish the last one and break + if (firstFace) + { + adjHeightAndDepth.get(direction)[0][0] = getMaxY(); + adjHeightAndDepth.get(direction)[0][1] = height; + } else + { + adjHeightAndDepth.get(direction)[faceToDraw][1] = height; + } + toFinish = false; + faceToDraw++; + break; + } else if (height >= maxY)//depth > minY && + {//the adj data intersect the higher part of the current data + //we start the creation of a new face + adjHeightAndDepth.get(direction)[faceToDraw][0] = depth; + firstFace = false; + toFinish = true; + } else {//if (depth > minY && height < maxY) + //the adj data is contained in the current data + if (firstFace) + { + adjHeightAndDepth.get(direction)[0][0] = getMaxY(); + } adjHeightAndDepth.get(direction)[faceToDraw][1] = height; + faceToDraw++; + adjHeightAndDepth.get(direction)[faceToDraw][0] = depth; + firstFace = false; + toFinish = true; } - toFinish = false; - faceToDraw++; - break; - } else if (depth > minY && height >= maxY) - {//the adj data intersect the higher part of the current data - //we start the creation of a new face - adjHeightAndDepth.get(direction)[faceToDraw][0] = depth; - firstFace = false; - toFinish = true; - continue; - } else if (depth > minY && height < maxY) - {//the adj data is contained in the current data - if (firstFace) - { - adjHeightAndDepth.get(direction)[0][0] = getMaxY(); - } - adjHeightAndDepth.get(direction)[faceToDraw][1] = height; - faceToDraw++; - adjHeightAndDepth.get(direction)[faceToDraw][0] = depth; - firstFace = false; - toFinish = true; - continue; - } + } //else {//the adj data is higher than the current data + //we continue since there could be some other data that intersect the current + //} } if (toFinish) { @@ -401,10 +396,7 @@ public class Box { if (direction == Direction.UP || direction == Direction.DOWN) { - if (adjIndex == 0) - return true; - else - return false; + return adjIndex == 0; } return !(adjHeightAndDepth.get(direction)[adjIndex][0] == VOID_FACE && adjHeightAndDepth.get(direction)[adjIndex][1] == VOID_FACE); diff --git a/src/main/java/com/seibel/lod/builders/worldGeneration/LodNodeGenWorker.java b/src/main/java/com/seibel/lod/builders/worldGeneration/LodNodeGenWorker.java index 29d3edc00..97c339317 100644 --- a/src/main/java/com/seibel/lod/builders/worldGeneration/LodNodeGenWorker.java +++ b/src/main/java/com/seibel/lod/builders/worldGeneration/LodNodeGenWorker.java @@ -224,9 +224,9 @@ public class LodNodeGenWorker implements IWorker // System.out.println(endTime - startTime); }// if in range - else{ + //else{ - } + //} } catch (Exception e) { @@ -584,16 +584,11 @@ public class LodNodeGenWorker implements IWorker private BlockClusterFeatureConfig cloneBlockClusterFeatureConfig(BlockClusterFeatureConfig config) { WeightedBlockStateProvider provider = new WeightedBlockStateProvider(); - for(Entry state : ((WeightedBlockStateProvider) config.stateProvider).weightedList.entries) - provider.weightedList.entries.add(state); + provider.weightedList.entries.addAll(((WeightedBlockStateProvider) config.stateProvider).weightedList.entries); - HashSet whitelist = new HashSet<>(); - for(Block block : config.whitelist) - whitelist.add(block); + HashSet whitelist = new HashSet<>(config.whitelist); - HashSet blacklist = new HashSet<>(); - for(BlockState state : config.blacklist) - blacklist.add(state); + HashSet blacklist = new HashSet<>(config.blacklist); BlockClusterFeatureConfig.Builder builder = new BlockClusterFeatureConfig.Builder(provider, config.blockPlacer); diff --git a/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java b/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java index 654df4b1b..b9531d511 100644 --- a/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java +++ b/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java @@ -286,16 +286,16 @@ public class LodDimensionFileHandler ex.printStackTrace(); } // check if this file can be written to by the file handler - if (fileVersion <= LOD_SAVE_FILE_VERSION) - { - // we are good to continue and overwrite the old file - } else // if(fileVersion > LOD_SAVE_FILE_VERSION) - { + if (fileVersion > LOD_SAVE_FILE_VERSION) { // the file we are reading is a newer version, // don't write anything, we don't want to accidently // delete anything the user may want. return; - } + } // if(fileVersion > LOD_SAVE_FILE_VERSION) + //else { + // we are good to continue and overwrite the old file + //} + } // the old file is good, now create a new save file diff --git a/src/main/java/com/seibel/lod/objects/SingleLevelContainer.java b/src/main/java/com/seibel/lod/objects/SingleLevelContainer.java index 390bb0fe9..c631b2515 100644 --- a/src/main/java/com/seibel/lod/objects/SingleLevelContainer.java +++ b/src/main/java/com/seibel/lod/objects/SingleLevelContainer.java @@ -137,7 +137,7 @@ public class SingleLevelContainer implements LevelContainer { int index = 0; int tempIndex; - byte[] tempData = new byte[1 + (size * size * 8)]; + byte[] tempData = ThreadMapUtil.getSaveContainer(1 + (size * size * 8)); tempData[index] = detailLevel; index++; for (int x = 0; x < size; x++) diff --git a/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java b/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java index 2457a76a7..edd759d3c 100644 --- a/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java +++ b/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java @@ -152,7 +152,7 @@ public class VerticalLevelContainer implements LevelContainer { int index = 0; int tempIndex; - byte[] tempData = new byte[2 + (size * size * maxVerticalData * 8)]; + byte[] tempData = ThreadMapUtil.getSaveContainer(2 + (size * size * maxVerticalData * 8)); tempData[index] = detailLevel; index++; tempData[index] = (byte) maxVerticalData; diff --git a/src/main/java/com/seibel/lod/util/ThreadMapUtil.java b/src/main/java/com/seibel/lod/util/ThreadMapUtil.java index 89518539a..dffa44190 100644 --- a/src/main/java/com/seibel/lod/util/ThreadMapUtil.java +++ b/src/main/java/com/seibel/lod/util/ThreadMapUtil.java @@ -19,7 +19,7 @@ public class ThreadMapUtil public static final ConcurrentMap threadAdjData = new ConcurrentHashMap<>(); - + public static final ConcurrentMap saveContainer = new ConcurrentHashMap<>(); public static final ConcurrentMap projectionShortMap = new ConcurrentHashMap<>(); public static final ConcurrentMap heightAndDepthMap = new ConcurrentHashMap<>(); public static final ConcurrentMap singleDataToMergeMap = new ConcurrentHashMap<>(); @@ -101,6 +101,14 @@ public class ThreadMapUtil return heightAndDepthMap.get(Thread.currentThread().getName()); } + public static byte[] getSaveContainer(int size){ + if(!saveContainer.containsKey(Thread.currentThread().getName()) || (saveContainer.get(Thread.currentThread().getName()) == null) || (saveContainer.get(Thread.currentThread().getName()).length != size)) + { + saveContainer.put(Thread.currentThread().getName(), new byte[size]); + } + return saveContainer.get(Thread.currentThread().getName()); + } + public static long[] getSingleAddDataToMerge(int size){ if(!singleDataToMergeMap.containsKey(Thread.currentThread().getName()) || (singleDataToMergeMap.get(Thread.currentThread().getName()) == null) || (singleDataToMergeMap.get(Thread.currentThread().getName()).length != size)) {