From 43f3854068f3108749df1a2b92d4f5e52fd4bad5 Mon Sep 17 00:00:00 2001 From: cola98765 Date: Sun, 19 Sep 2021 11:41:29 +0200 Subject: [PATCH] some fixes to new mergeMultiData --- .../com/seibel/lod/util/DataPointUtil.java | 45 ++++++++++--------- .../com/seibel/lod/util/ThreadMapUtil.java | 6 +-- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/seibel/lod/util/DataPointUtil.java b/src/main/java/com/seibel/lod/util/DataPointUtil.java index cb3e38f64..5a32dc46f 100644 --- a/src/main/java/com/seibel/lod/util/DataPointUtil.java +++ b/src/main/java/com/seibel/lod/util/DataPointUtil.java @@ -279,8 +279,8 @@ public class DataPointUtil public static long[] mergeMultiData(long[][] dataToMerge) { //new code - short[] projection = ThreadMapUtil.getProjectionShort((WORLD_HEIGHT + 1 ) >>> 4); - int[][] heightAndDepth = ThreadMapUtil.getHeightAndDepth(WORLD_HEIGHT + 1); + short[] projection = ThreadMapUtil.getProjectionShort((WORLD_HEIGHT + 1) / 16); + short[][] heightAndDepth = ThreadMapUtil.getHeightAndDepth((WORLD_HEIGHT / 2) + 1); long[] singleDataToMerge = ThreadMapUtil.getSingleAddDataToMerge(dataToMerge.length); int genMode = DistanceGenerationMode.SERVER.complexity; boolean allEmpty = true; @@ -289,8 +289,8 @@ public class DataPointUtil for(int k=0; k < projection.length; k++) projection[k] = 0; - int depth = 0; - int height = 0; + short depth = 0; + short height = 0; //We collect the indexes of the data, ordered by the depth for (int index = 0; index < dataToMerge.length; index++) { @@ -307,7 +307,7 @@ public class DataPointUtil depth = getDepth(singleData); height = getHeight(singleData); for (int y = depth; y <= height; y++) - projection[y >>> 4] |= 1L << (y & 0xf); + projection[y / 16] |= 1 << (y & 0xf); } } } @@ -325,18 +325,23 @@ public class DataPointUtil int ii = 0; while (i < projection.length) { - while (i < projection.length && projection[i] != 0) i++; - if (i == projection.length) - break; //we reached end of WORLD_HEIGHT and it's nothing more here - while (((projection[i] >>> ii) & 1) == 0) ii++; - depth = i * 16 + ii; - - while (ii<15 && ((projection[i] >>> ii) & 1) == 1) ii++; - if (ii==15) //if end is outside of this int + if (ii >= 15) { ii = 0; i++; - while (i < projection.length && ~(projection[i]) != 0) i++; //check for big solid blocks + } + while (i < projection.length && projection[i] == 0) i++; + if (i == projection.length) + break; //we reached end of WORLD_HEIGHT and it's nothing more here + while (((projection[i] >>> ii) & 1) == 0) ii++; + depth = (short)( i * 16 + ii); + + while (ii<15 && ((projection[i] >>> ii) & 1) == 1) ii++; + if (ii>=15) //if end is outside of this int + { + ii = 0; + i++; + while (i < projection.length && ~(projection[i]) == 0) i++; //check for big solid blocks if (i == projection.length) //solid to WORLD_HEIGHT { heightAndDepth[count][0] = depth; @@ -345,7 +350,7 @@ public class DataPointUtil } while (((projection[i] >>> ii) & 1) == 1) ii++; } - height = i * 16 + ii; + height = (short)(i * 16 + ii); heightAndDepth[count][0] = depth; heightAndDepth[count][1] = height; @@ -353,7 +358,7 @@ public class DataPointUtil } //old code /*boolean[] projection = ThreadMapUtil.getProjection(WORLD_HEIGHT + 1); - int[][] heightAndDepth = ThreadMapUtil.getHeightAndDepth(WORLD_HEIGHT + 1); + short[][] heightAndDepth = ThreadMapUtil.getHeightAndDepth((WORLD_HEIGHT / 2) + 1); long[] singleDataToMerge = ThreadMapUtil.getSingleAddDataToMerge(dataToMerge.length); int genMode = DistanceGenerationMode.SERVER.complexity; boolean allEmpty = true; @@ -362,8 +367,8 @@ public class DataPointUtil for(int k=0; k < projection.length; k++) projection[k] = false; - int depth = 0; - int height = 0; + short depth = 0; + short height = 0; //We collect the indexes of the data, ordered by the depth for (int index = 0; index < dataToMerge.length; index++) { @@ -406,10 +411,10 @@ public class DataPointUtil { i++; } - depth = i; + depth = (short) i; while (i < projection.length && projection[i]) { - height = i; + height = (short) i; i++; } if(!(i < projection.length)) diff --git a/src/main/java/com/seibel/lod/util/ThreadMapUtil.java b/src/main/java/com/seibel/lod/util/ThreadMapUtil.java index 44dc66db9..d66007338 100644 --- a/src/main/java/com/seibel/lod/util/ThreadMapUtil.java +++ b/src/main/java/com/seibel/lod/util/ThreadMapUtil.java @@ -22,7 +22,7 @@ public class ThreadMapUtil public static final ConcurrentMap projectionMap = new ConcurrentHashMap<>(); public static final ConcurrentMap projectionShortMap = new ConcurrentHashMap<>(); - public static final ConcurrentMap heightAndDepthMap = new ConcurrentHashMap<>(); + public static final ConcurrentMap heightAndDepthMap = new ConcurrentHashMap<>(); public static final ConcurrentMap singleDataToMergeMap = new ConcurrentHashMap<>(); @@ -134,10 +134,10 @@ public class ThreadMapUtil return projectionShortMap.get(Thread.currentThread().getName()); } - public static int[][] getHeightAndDepth(int size){ + public static short[][] getHeightAndDepth(int size){ if(!heightAndDepthMap.containsKey(Thread.currentThread().getName()) || (heightAndDepthMap.get(Thread.currentThread().getName()) == null) || (heightAndDepthMap.get(Thread.currentThread().getName()).length != size)) { - heightAndDepthMap.put(Thread.currentThread().getName(), new int[size][2]); + heightAndDepthMap.put(Thread.currentThread().getName(), new short[size][2]); } return heightAndDepthMap.get(Thread.currentThread().getName()); }