diff --git a/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java b/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java index 0ca124d09..0a5365b99 100644 --- a/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java +++ b/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java @@ -341,9 +341,8 @@ public class LodBuilder int color = generateLodColor(chunk, config, x, y, z); int lightBlock = light & 0b1111; int lightSky = (light >> 4) & 0b1111; - boolean isDefault = ((light >> 8)) == 1; dataToMerge[count] = DataPointUtil.createDataPoint(height-chunk.getMinBuildHeight(), depth-chunk.getMinBuildHeight(), - color, lightSky, lightBlock, generation, isDefault); + color, lightSky, lightBlock, generation); topBlock = false; y = depth - 1; count++; diff --git a/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java b/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java index effee871c..d8c85a5c7 100644 --- a/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java +++ b/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java @@ -89,7 +89,7 @@ public class LodDimensionFileHandler * file handler, older versions (smaller numbers) will be deleted and overwritten, * newer versions (larger numbers) will be ignored and won't be read. */ - public static final int LOD_SAVE_FILE_VERSION = 8; + public static final int LOD_SAVE_FILE_VERSION = 9; /** * Allow saving asynchronously, but never try to save multiple regions diff --git a/src/main/java/com/seibel/lod/core/objects/lod/VerticalLevelContainer.java b/src/main/java/com/seibel/lod/core/objects/lod/VerticalLevelContainer.java index c140e9c24..29fc978c0 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/VerticalLevelContainer.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/VerticalLevelContainer.java @@ -219,6 +219,7 @@ public class VerticalLevelContainer implements LevelContainer inputData.readFully(data); long[] result = new long[x]; bb.asLongBuffer().get(result); + patchVersion9Reorder(result); patchHeightAndDepth(result,-minHeight); return result; } @@ -229,11 +230,27 @@ public class VerticalLevelContainer implements LevelContainer inputData.readFully(data); long[] result = new long[x]; bb.asLongBuffer().get(result); + patchVersion9Reorder(result); patchHeightAndDepth(result, 64 - minHeight); return result; } private long[] readDataVersion8(DataInputStream inputData, int tempMaxVerticalData) throws IOException { + int x = size * size * tempMaxVerticalData; + byte[] data = new byte[x * Long.BYTES]; + short tempMinHeight = Short.reverseBytes(inputData.readShort()); + ByteBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN); + inputData.readFully(data); + long[] result = new long[x]; + bb.asLongBuffer().get(result); + patchVersion9Reorder(result); + if (tempMinHeight != minHeight) { + patchHeightAndDepth(result,tempMinHeight - minHeight); + } + return result; + } + + private long[] readDataVersion9(DataInputStream inputData, int tempMaxVerticalData) throws IOException { int x = size * size * tempMaxVerticalData; byte[] data = new byte[x * Long.BYTES]; short tempMinHeight = Short.reverseBytes(inputData.readShort()); @@ -253,6 +270,12 @@ public class VerticalLevelContainer implements LevelContainer } } + private static void patchVersion9Reorder(long[] data) { + for (int i=0; i>> ALPHA_DOWNSIZE_SHIFT) << ALPHA_SHIFT; - dataPoint |= (red & RED_MASK) << RED_SHIFT; - dataPoint |= (green & GREEN_MASK) << GREEN_SHIFT; - dataPoint |= (blue & BLUE_MASK) << BLUE_SHIFT; - dataPoint |= (height & HEIGHT_MASK) << HEIGHT_SHIFT; - dataPoint |= (depth & DEPTH_MASK) << DEPTH_SHIFT; - dataPoint |= (lightBlock & BLOCK_LIGHT_MASK) << BLOCK_LIGHT_SHIFT; - dataPoint |= (lightSky & SKY_LIGHT_MASK) << SKY_LIGHT_SHIFT; - dataPoint |= (generationMode & GEN_TYPE_MASK) << GEN_TYPE_SHIFT; - if (flag) dataPoint |= FLAG_MASK << FLAG_SHIFT; - dataPoint |= EXISTENCE_MASK << EXISTENCE_SHIFT; - return dataPoint; + return (long) (alpha >>> ALPHA_DOWNSIZE_SHIFT) << ALPHA_SHIFT + | (red & RED_MASK) << RED_SHIFT + | (green & GREEN_MASK) << GREEN_SHIFT + | (blue & BLUE_MASK) << BLUE_SHIFT + | (height & HEIGHT_MASK) << HEIGHT_SHIFT + | (depth & DEPTH_MASK) << DEPTH_SHIFT + | (lightBlock & BLOCK_LIGHT_MASK) << BLOCK_LIGHT_SHIFT + | (lightSky & SKY_LIGHT_MASK) << SKY_LIGHT_SHIFT + | (generationMode & GEN_TYPE_MASK) << GEN_TYPE_SHIFT + | EXISTENCE_MASK << EXISTENCE_SHIFT; } public static long shiftHeightAndDepth(long dataPoint, short offset) { - long height = (dataPoint + (offset << HEIGHT_SHIFT)) & HEIGHT_SHIFTED_MASK; + long height = (dataPoint + ((long) offset << HEIGHT_SHIFT)) & HEIGHT_SHIFTED_MASK; long depth = (dataPoint + (offset << DEPTH_SHIFT)) & DEPTH_SHIFTED_MASK; return dataPoint & ~(HEIGHT_SHIFTED_MASK | DEPTH_SHIFTED_MASK) | height | depth; } + public static long version9Reorder(long dataPoint) { + /* + |a |a |a |a |r |r |r |r | + |r |r |r |r |g |g |g |g | + |g |g |g |g |b |b |b |b | + |b |b |b |b |h |h |h |h | + |h |h |h |h |h |h |d |d | + |d |d |d |d |d |d |d |d | + |bl |bl |bl |bl |sl |sl |sl |sl | + |l |l |f |g |g |g |v |e | + */ + return //((dataPoint >>> 60) & 0xF) << ALPHA_SHIFT + //| ((dataPoint >>> 52) & 0xFF) << RED_SHIFT + //| ((dataPoint >>> 44) & 0xFF) << GREEN_SHIFT + ((dataPoint >>> 36) & 0xFFFFFFF) << BLUE_SHIFT + | ((dataPoint >>> 26) & 0x3FF) << HEIGHT_SHIFT + | ((dataPoint >>> 16) & 0x3FF) << DEPTH_SHIFT + | ((dataPoint >>> 8) & 0xFF) << SKY_LIGHT_SHIFT + | ((dataPoint >>> 2) & 0xFF) << GEN_TYPE_SHIFT + | dataPoint & 0x1; + } + public static short getHeight(long dataPoint) { return (short) ((dataPoint >>> HEIGHT_SHIFT) & HEIGHT_MASK); @@ -189,10 +191,6 @@ public class DataPointUtil return (byte) ((dataPoint >>> BLOCK_LIGHT_SHIFT) & BLOCK_LIGHT_MASK); } - public static boolean getFlag(long dataPoint) - { - return ((dataPoint >>> FLAG_SHIFT) & FLAG_MASK) == 1; - } public static byte getGenerationMode(long dataPoint) { @@ -202,7 +200,7 @@ public class DataPointUtil public static boolean isVoid(long dataPoint) { - return (((dataPoint >>> VOID_SHIFT) & VOID_MASK) == 1); + return (((dataPoint >>> DEPTH_SHIFT) & HEIGHT_DEPTH_MASK) == 0); } public static boolean doesItExist(long dataPoint) @@ -213,7 +211,7 @@ public class DataPointUtil public static int getColor(long dataPoint) { // TODO re-add transparency by replacing the color 255 with what is in comment - return (int) (((dataPoint >>> COLOR_SHIFT) & COLOR_MASK) | ((((dataPoint >>> ALPHA_SHIFT) & ALPHA_MASK) << ALPHA_DOWNSIZE_SHIFT) | 0b1111) << 24); + return (int) (((dataPoint >>> COLOR_SHIFT) & COLOR_MASK) | ((((dataPoint >>> ALPHA_SHIFT) & ALPHA_MASK) << ALPHA_DOWNSIZE_SHIFT) | 0xF) << 24); } /** This is used to convert a dataPoint to string (useful for the print function) */ @@ -656,7 +654,7 @@ public class DataPointUtil //{ // add simplification at the end due to color //} - dataPoint[j] = createDataPoint((int) Math.sqrt(tempAlpha), (int) Math.sqrt(tempRed), (int) Math.sqrt(tempGreen), (int) Math.sqrt(tempBlue), height, depth, tempLightSky, tempLightBlock, genMode, false); + dataPoint[j] = createDataPoint((int) Math.sqrt(tempAlpha), (int) Math.sqrt(tempRed), (int) Math.sqrt(tempGreen), (int) Math.sqrt(tempBlue), height, depth, tempLightSky, tempLightBlock, genMode); } } }