diff --git a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java index f8836c0dd..f7bfdc8e1 100644 --- a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java +++ b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java @@ -30,6 +30,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.locks.ReentrantLock; +import com.seibel.lod.core.objects.lod.DataPoint; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL30; @@ -287,7 +288,7 @@ public class LodBufferBuilderFactory int maxVerticalData = DetailDistanceUtil.getMaxVerticalData((byte) 0); //we get or create the map that will contain the adj data - Map adjData = ThreadMapUtil.getAdjDataArray(maxVerticalData); + Map adjData = ThreadMapUtil.getAdjDataArray(maxVerticalData); //previous setToRender cache if (setsToRender[xR][zR] == null) @@ -347,7 +348,7 @@ public class LodBufferBuilderFactory xAdj = posX + Box.DIRECTION_NORMAL_MAP.get(lodDirection).x; zAdj = posZ + Box.DIRECTION_NORMAL_MAP.get(lodDirection).z; - long data; + DataPoint data; chunkXdist = LevelPosUtil.getChunkPos(detailLevel, xAdj) - playerChunkPos.getX(); chunkZdist = LevelPosUtil.getChunkPos(detailLevel, zAdj) - playerChunkPos.getZ(); adjPosInPlayerChunk = (chunkXdist == 0 && chunkZdist == 0); @@ -376,7 +377,7 @@ public class LodBufferBuilderFactory adjData.get(lodDirection)[0] = DataPointUtil.EMPTY_DATA; if ((isThisPositionGoingToBeRendered(detailLevel, xAdj, zAdj, playerChunkPos, vanillaRenderedChunks, gameChunkRenderDistance) || (posNotInPlayerChunk && adjPosInPlayerChunk)) - && !DataPointUtil.isVoid(data)) + && DataPointUtil.doesItExist(data) && !DataPointUtil.isVoid(data)) { adjShadeDisabled[Box.DIRECTION_INDEX.get(lodDirection)] = DataPointUtil.getAlpha(data) < 255; } @@ -386,7 +387,7 @@ public class LodBufferBuilderFactory // We render every vertical lod present in this position // We only stop when we find a block that is void or non-existing block - long data; + DataPoint data; for (int verticalIndex = 0; verticalIndex < lodDim.getMaxVerticalData(detailLevel, posX, posZ); verticalIndex++) { @@ -407,7 +408,7 @@ public class LodBufferBuilderFactory data = lodDim.getData(detailLevel, posX, posZ, verticalIndex); //If the data is not renderable (Void or non-existing) we stop since there is no data left in this position - if (DataPointUtil.isVoid(data) || !DataPointUtil.doesItExist(data)) + if (!DataPointUtil.doesItExist(data) || DataPointUtil.isVoid(data)) break; //We send the call to create the vertices diff --git a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/AbstractLodTemplate.java b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/AbstractLodTemplate.java index 41239212e..44a549079 100644 --- a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/AbstractLodTemplate.java +++ b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/AbstractLodTemplate.java @@ -24,6 +24,7 @@ import java.util.Map; import com.seibel.lod.core.enums.LodDirection; import com.seibel.lod.core.enums.rendering.DebugMode; import com.seibel.lod.core.objects.Box; +import com.seibel.lod.core.objects.lod.DataPoint; import com.seibel.lod.core.objects.opengl.LodBufferBuilder; import com.seibel.lod.core.util.ColorUtil; import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper; @@ -37,7 +38,7 @@ import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper; public abstract class AbstractLodTemplate { /** Uploads the given LOD to the buffer. */ - public abstract void addLodToBuffer(LodBufferBuilder buffer, AbstractBlockPosWrapper bufferCenterBlockPos, long data, Map adjData, + public abstract void addLodToBuffer(LodBufferBuilder buffer, AbstractBlockPosWrapper bufferCenterBlockPos, DataPoint data, Map adjData, byte detailLevel, int posX, int posZ, Box box, DebugMode debugging, boolean[] adjShadeDisabled); /** add the given position and color to the buffer */ diff --git a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/CubicLodTemplate.java b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/CubicLodTemplate.java index 6d48c38e0..124500966 100644 --- a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/CubicLodTemplate.java +++ b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/CubicLodTemplate.java @@ -24,6 +24,7 @@ import java.util.Map; import com.seibel.lod.core.enums.LodDirection; import com.seibel.lod.core.enums.rendering.DebugMode; import com.seibel.lod.core.objects.Box; +import com.seibel.lod.core.objects.lod.DataPoint; import com.seibel.lod.core.objects.opengl.LodBufferBuilder; import com.seibel.lod.core.util.ColorUtil; import com.seibel.lod.core.util.DataPointUtil; @@ -44,7 +45,7 @@ public class CubicLodTemplate extends AbstractLodTemplate } @Override - public void addLodToBuffer(LodBufferBuilder buffer, AbstractBlockPosWrapper bufferCenterBlockPos, long data, Map adjData, + public void addLodToBuffer(LodBufferBuilder buffer, AbstractBlockPosWrapper bufferCenterBlockPos, DataPoint data, Map adjData, byte detailLevel, int posX, int posZ, Box box, DebugMode debugging, boolean[] adjShadeDisabled) { if (box == null) @@ -80,7 +81,7 @@ public class CubicLodTemplate extends AbstractLodTemplate int height, int depth, int width, double xOffset, double yOffset, double zOffset, AbstractBlockPosWrapper bufferCenterBlockPos, - Map adjData, + Map adjData, int color, int skyLight, int blockLight, diff --git a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/DynamicLodTemplate.java b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/DynamicLodTemplate.java index e53fd85d2..a9f70e551 100644 --- a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/DynamicLodTemplate.java +++ b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/DynamicLodTemplate.java @@ -25,6 +25,7 @@ import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.enums.LodDirection; import com.seibel.lod.core.enums.rendering.DebugMode; import com.seibel.lod.core.objects.Box; +import com.seibel.lod.core.objects.lod.DataPoint; import com.seibel.lod.core.objects.opengl.LodBufferBuilder; import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper; @@ -39,7 +40,7 @@ import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper; public class DynamicLodTemplate extends AbstractLodTemplate { @Override - public void addLodToBuffer(LodBufferBuilder buffer, AbstractBlockPosWrapper bufferCenterBlockPos, long data, Map adjData, + public void addLodToBuffer(LodBufferBuilder buffer, AbstractBlockPosWrapper bufferCenterBlockPos, DataPoint data, Map adjData, byte detailLevel, int posX, int posZ, Box box, DebugMode debugging, boolean[] adjShadeDisabled) { ClientApi.LOGGER.error(DynamicLodTemplate.class.getSimpleName() + " is not implemented!"); diff --git a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/TriangularLodTemplate.java b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/TriangularLodTemplate.java index ffe8c2679..c1869d312 100644 --- a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/TriangularLodTemplate.java +++ b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/lodTemplates/TriangularLodTemplate.java @@ -25,6 +25,7 @@ import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.enums.LodDirection; import com.seibel.lod.core.enums.rendering.DebugMode; import com.seibel.lod.core.objects.Box; +import com.seibel.lod.core.objects.lod.DataPoint; import com.seibel.lod.core.objects.opengl.LodBufferBuilder; import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper; @@ -37,7 +38,7 @@ import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper; public class TriangularLodTemplate extends AbstractLodTemplate { @Override - public void addLodToBuffer(LodBufferBuilder buffer, AbstractBlockPosWrapper bufferCenterBlockPos, long data, Map adjData, + public void addLodToBuffer(LodBufferBuilder buffer, AbstractBlockPosWrapper bufferCenterBlockPos, DataPoint data, Map adjData, byte detailLevel, int posX, int posZ, Box box, DebugMode debugging, boolean[] adjShadeDisabled) { ClientApi.LOGGER.error(DynamicLodTemplate.class.getSimpleName() + " is not implemented!"); 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 671abcadc..22bfbd9a1 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 @@ -24,6 +24,7 @@ import java.util.concurrent.Executors; import com.seibel.lod.core.enums.config.DistanceGenerationMode; import com.seibel.lod.core.enums.config.HorizontalResolution; +import com.seibel.lod.core.objects.lod.DataPoint; import com.seibel.lod.core.objects.lod.LodDimension; import com.seibel.lod.core.objects.lod.LodRegion; import com.seibel.lod.core.objects.lod.LodWorld; @@ -195,8 +196,8 @@ import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper; startX = detail.startX[i]; startZ = detail.startZ[i]; - long[] data; - long[] dataToMergeVertical = createVerticalDataToMerge(detail, chunk, config, startX, startZ); + DataPoint[] data; + DataPoint[] dataToMergeVertical = createVerticalDataToMerge(detail, chunk, config, startX, startZ); data = DataPointUtil.mergeMultiData(dataToMergeVertical, DataPointUtil.WORLD_HEIGHT / 2 + 1, DetailDistanceUtil.getMaxVerticalData(detailLevel)); @@ -212,12 +213,12 @@ import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper; } /** creates a vertical DataPoint */ - private long[] createVerticalDataToMerge(HorizontalResolution detail, IChunkWrapper chunk, LodBuilderConfig config, int startX, int startZ) + private DataPoint[] createVerticalDataToMerge(HorizontalResolution detail, IChunkWrapper chunk, LodBuilderConfig config, int startX, int startZ) { // equivalent to 2^detailLevel int size = 1 << detail.detailLevel; - long[] dataToMerge = ThreadMapUtil.getBuilderVerticalArray(detail.detailLevel); + DataPoint[] dataToMerge = ThreadMapUtil.getBuilderVerticalArray(detail.detailLevel); int verticalData = DataPointUtil.WORLD_HEIGHT / 2 + 1; AbstractChunkPosWrapper chunkPos = chunk.getPos(); 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 f8e5e1f1e..44117feae 100644 --- a/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java +++ b/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java @@ -21,7 +21,6 @@ package com.seibel.lod.core.handlers; import java.io.*; import java.nio.file.Files; -import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.concurrent.ExecutorService; @@ -78,7 +77,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 = 7; + public static final int LOD_SAVE_FILE_VERSION = 8; /** * Allow saving asynchronously, but never try to save multiple regions @@ -208,14 +207,14 @@ public class LodDimensionFileHandler break; } - else if (fileVersion == 6) + else if (fileVersion < LOD_SAVE_FILE_VERSION) { //this is old, but readable version byte[] data = ThreadMapUtil.getSaveContainer(tempDetailLevel); inputStream.read(data); inputStream.close(); // add the data to our region - region.addLevelContainer(new VerticalLevelContainer(data, 6)); + region.addLevelContainer(new VerticalLevelContainer(data, fileVersion)); } else { // this file is a readable version, diff --git a/src/main/java/com/seibel/lod/core/objects/Box.java b/src/main/java/com/seibel/lod/core/objects/Box.java index 5fa31e795..9af37bda1 100644 --- a/src/main/java/com/seibel/lod/core/objects/Box.java +++ b/src/main/java/com/seibel/lod/core/objects/Box.java @@ -25,6 +25,7 @@ import java.util.Map; import com.seibel.lod.core.enums.LodDirection; import com.seibel.lod.core.enums.rendering.DebugMode; +import com.seibel.lod.core.objects.lod.DataPoint; import com.seibel.lod.core.objects.math.Vec3i; import com.seibel.lod.core.util.ColorUtil; import com.seibel.lod.core.util.DataPointUtil; @@ -339,13 +340,13 @@ public class Box * This method create all the shared face culling based on the adjacent data * @param adjData data adjacent to the column we are going to render */ - public void setAdjData(Map adjData) + public void setAdjData(Map adjData) { int height; int depth; int minY = getMinY(); int maxY = getMaxY(); - long singleAdjDataPoint; + DataPoint singleAdjDataPoint; /* TODO implement attached vertical face culling //Up direction case @@ -367,8 +368,8 @@ public class Box if (isCulled(lodDirection)) continue; - long[] dataPoint = adjData.get(lodDirection); - if (dataPoint == null || DataPointUtil.isVoid(dataPoint[0])) + DataPoint[] dataPoint = adjData.get(lodDirection); + if (DataPointUtil.isVoid(dataPoint[0])) { adjHeight.get(lodDirection)[0] = maxY; adjDepth.get(lodDirection)[0] = minY; diff --git a/src/main/java/com/seibel/lod/core/objects/lod/DataPoint.java b/src/main/java/com/seibel/lod/core/objects/lod/DataPoint.java new file mode 100644 index 000000000..4ce109f3a --- /dev/null +++ b/src/main/java/com/seibel/lod/core/objects/lod/DataPoint.java @@ -0,0 +1,39 @@ +package com.seibel.lod.core.objects.lod; + +public class DataPoint +{ + public int color; + // |a |a |a |a |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 | + public int data; + // |h |h |h |h |h |h |h |h | + // |h |h |h |h |d |d |d |d | + // |d |d |d |d |d |d |d |d | + // |bl |bl |bl |bl |sl |sl |sl |sl | + public byte flags; + // |l |l |f |g |g |g |v |e | + + + public DataPoint() + { + color = 0; + data = 0; + flags = 0; + } + + public DataPoint(int newColor, int newData, byte newFlags) + { + color = newColor; + data = newData; + flags = newFlags; + } + + public void clear() + { + color = 0; + data = 0; + flags = 0; + } +} diff --git a/src/main/java/com/seibel/lod/core/objects/lod/LevelContainer.java b/src/main/java/com/seibel/lod/core/objects/lod/LevelContainer.java index b314fbcf7..2fb2c553d 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/LevelContainer.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/LevelContainer.java @@ -32,7 +32,7 @@ public interface LevelContainer * @param index z position in the detail level * @return true if correctly added, false otherwise */ - boolean addData(long data, int posX, int posZ, int index); + boolean addData(DataPoint data, int posX, int posZ, int index); /** * With this you can add data to the level container @@ -41,7 +41,7 @@ public interface LevelContainer * @param posZ z position in the detail level * @return true if correctly added, false otherwise */ - boolean addVerticalData(long[] data, int posX, int posZ); + boolean addVerticalData(DataPoint[] data, int posX, int posZ); /** * With this you can add data to the level container @@ -50,7 +50,7 @@ public interface LevelContainer * @param posZ z position in the detail level * @return true if correctly added, false otherwise */ - boolean addSingleData(long data, int posX, int posZ); + boolean addSingleData(DataPoint data, int posX, int posZ); /** * With this you can get data from the level container @@ -58,7 +58,7 @@ public interface LevelContainer * @param posZ z position in the detail level * @return the data in long array format */ - long getData(int posX, int posZ, int index); + DataPoint getData(int posX, int posZ, int index); /** * With this you can get data from the level container @@ -66,7 +66,7 @@ public interface LevelContainer * @param posZ z position in the detail level * @return the data in long array format */ - long getSingleData(int posX, int posZ); + DataPoint getSingleData(int posX, int posZ); /** * @param posX x position in the detail level diff --git a/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java b/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java index 06c8fd921..994075b84 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java @@ -445,7 +445,7 @@ public class LodDimension * stored in the LOD. If an LOD already exists at the given * coordinate it will be overwritten. */ - public Boolean addData(byte detailLevel, int posX, int posZ, int verticalIndex, long data, boolean dontSave) + public Boolean addData(byte detailLevel, int posX, int posZ, int verticalIndex, DataPoint data, boolean dontSave) { int regionPosX = LevelPosUtil.getRegion(detailLevel, posX); int regionPosZ = LevelPosUtil.getRegion(detailLevel, posZ); @@ -487,7 +487,7 @@ public class LodDimension * stored in the LOD. If an LOD already exists at the given * coordinate it will be overwritten. */ - public Boolean addVerticalData(byte detailLevel, int posX, int posZ, long[] data, boolean dontSave) + public Boolean addVerticalData(byte detailLevel, int posX, int posZ, DataPoint[] data, boolean dontSave) { int regionPosX = LevelPosUtil.getRegion(detailLevel, posX); int regionPosZ = LevelPosUtil.getRegion(detailLevel, posZ); @@ -566,7 +566,7 @@ public class LodDimension byte detailLevel; int posX; int posZ; - long data; + DataPoint data; int numbChunksWide = (width) * 32; int circleLimit = Integer.MAX_VALUE; @@ -618,7 +618,7 @@ public class LodDimension //we will generate the position only if the current generation complexity is lower than the target one. //an un-generated area will always have 0 generation - if (DataPointUtil.getGenerationMode(data) < complexity) + if (data != null && DataPointUtil.getGenerationMode(data) < complexity) { posToGenerate.addPosToGenerate(detailLevel, posX, posZ); if (maxDataToGenerate >= 0) @@ -712,7 +712,7 @@ public class LodDimension * Returns null if the LodChunk doesn't exist or * is outside the loaded area. */ - public long getData(byte detailLevel, int posX, int posZ, int verticalIndex) + public DataPoint getData(byte detailLevel, int posX, int posZ, int verticalIndex) { if (detailLevel > LodUtil.REGION_DETAIL_LEVEL) throw new IllegalArgumentException("getLodFromCoordinates given a level of \"" + detailLevel + "\" when \"" + LodUtil.REGION_DETAIL_LEVEL + "\" is the max."); @@ -732,7 +732,7 @@ public class LodDimension * Returns null if the LodChunk doesn't exist or * is outside the loaded area. */ - public long getSingleData(byte detailLevel, int posX, int posZ) + public DataPoint getSingleData(byte detailLevel, int posX, int posZ) { if (detailLevel > LodUtil.REGION_DETAIL_LEVEL) throw new IllegalArgumentException("getLodFromCoordinates given a level of \"" + detailLevel + "\" when \"" + LodUtil.REGION_DETAIL_LEVEL + "\" is the max."); diff --git a/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java b/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java index 7acd6b8cf..a97ce2325 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java @@ -154,7 +154,7 @@ public class LodRegion * TODO this will always return true unless it has * @return true if the data was added successfully */ - public boolean addData(byte detailLevel, int posX, int posZ, int verticalIndex, long data) + public boolean addData(byte detailLevel, int posX, int posZ, int verticalIndex, DataPoint data) { posX = LevelPosUtil.getRegionModule(detailLevel, posX); posZ = LevelPosUtil.getRegionModule(detailLevel, posZ); @@ -177,7 +177,7 @@ public class LodRegion * TODO this will always return true unless it has * @return true if the data was added successfully */ - public boolean addVerticalData(byte detailLevel, int posX, int posZ, long[] data) + public boolean addVerticalData(byte detailLevel, int posX, int posZ, DataPoint[] data) { //position is already relative //posX = LevelPosUtil.getRegionModule(detailLevel, posX); @@ -196,7 +196,7 @@ public class LodRegion * @return the data at the relative pos and detail level, * 0 if the data doesn't exist. */ - public long getData(byte detailLevel, int posX, int posZ, int verticalIndex) + public DataPoint getData(byte detailLevel, int posX, int posZ, int verticalIndex) { return dataContainer[detailLevel].getData(posX, posZ, verticalIndex); } @@ -206,7 +206,7 @@ public class LodRegion * @return the data at the relative pos and detail level, * 0 if the data doesn't exist. */ - public long getSingleData(byte detailLevel, int posX, int posZ) + public DataPoint getSingleData(byte detailLevel, int posX, int posZ) { return dataContainer[detailLevel].getSingleData(posX, posZ); } 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 f813a9a86..8db247481 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 @@ -37,14 +37,14 @@ public class VerticalLevelContainer implements LevelContainer public final int size; public final int maxVerticalData; - public final long[] dataContainer; + public final DataPoint[] dataContainer; public VerticalLevelContainer(byte detailLevel) { this.detailLevel = detailLevel; size = 1 << (LodUtil.REGION_DETAIL_LEVEL - detailLevel); maxVerticalData = DetailDistanceUtil.getMaxVerticalData(detailLevel); - dataContainer = new long[size * size * DetailDistanceUtil.getMaxVerticalData(detailLevel)]; + dataContainer = new DataPoint[size * size * DetailDistanceUtil.getMaxVerticalData(detailLevel)]; } @Override @@ -65,7 +65,7 @@ public class VerticalLevelContainer implements LevelContainer } @Override - public boolean addData(long data, int posX, int posZ, int verticalIndex) + public boolean addData(DataPoint data, int posX, int posZ, int verticalIndex) { posX = LevelPosUtil.getRegionModule(detailLevel, posX); posZ = LevelPosUtil.getRegionModule(detailLevel, posZ); @@ -74,7 +74,7 @@ public class VerticalLevelContainer implements LevelContainer } @Override - public boolean addVerticalData(long[] data, int posX, int posZ) + public boolean addVerticalData(DataPoint[] data, int posX, int posZ) { posX = LevelPosUtil.getRegionModule(detailLevel, posX); posZ = LevelPosUtil.getRegionModule(detailLevel, posZ); @@ -84,13 +84,13 @@ public class VerticalLevelContainer implements LevelContainer } @Override - public boolean addSingleData(long data, int posX, int posZ) + public boolean addSingleData(DataPoint data, int posX, int posZ) { return addData(data, posX, posZ, 0); } @Override - public long getData(int posX, int posZ, int verticalIndex) + public DataPoint getData(int posX, int posZ, int verticalIndex) { posX = LevelPosUtil.getRegionModule(detailLevel, posX); posZ = LevelPosUtil.getRegionModule(detailLevel, posZ); @@ -98,7 +98,7 @@ public class VerticalLevelContainer implements LevelContainer } @Override - public long getSingleData(int posX, int posZ) + public DataPoint getSingleData(int posX, int posZ) { return getData(posX, posZ, 0); } @@ -127,56 +127,98 @@ public class VerticalLevelContainer implements LevelContainer int tempMaxVerticalData; int tempIndex; int index = 0; - long newData; detailLevel = inputData[index]; index++; tempMaxVerticalData = inputData[index] & 0b01111111; index++; size = 1 << (LodUtil.REGION_DETAIL_LEVEL - detailLevel); int x = size * size * tempMaxVerticalData; - long[] tempDataContainer = new long[x]; + DataPoint[] tempDataContainer = new DataPoint[x]; if (version == 6) { + long oldData; for (int i = 0; i < x; i++) { - newData = 0; + oldData = 0; for (tempIndex = 0; tempIndex < 8; tempIndex++) - newData += (((long) inputData[index + tempIndex]) & 0xff) << (8 * tempIndex); + oldData += (((long) inputData[index + tempIndex]) & 0xff) << (8 * tempIndex); index += 8; - - newData = DataPointUtil.createDataPoint( - DataPointUtil.getAlpha(newData), - DataPointUtil.getRed(newData), - DataPointUtil.getGreen(newData), - DataPointUtil.getBlue(newData), - DataPointUtil.getHeight(newData) - DataPointUtil.VERTICAL_OFFSET, - DataPointUtil.getDepth(newData) - DataPointUtil.VERTICAL_OFFSET, - DataPointUtil.getLightSky(newData), - DataPointUtil.getLightBlock(newData), - DataPointUtil.getGenerationMode(newData), - DataPointUtil.getFlag(newData) + /* + |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 | + */ + DataPoint newData = DataPointUtil.createDataPoint( + (int)((oldData >> 60) << 4) + 15, + (int)(oldData >> 52) & 0xFF, + (int)(oldData >> 44) & 0xFF, + (int)(oldData >> 36) & 0xFF, + (int)(oldData >> 26) & 0x3FF - DataPointUtil.VERTICAL_OFFSET, + (int)(oldData >> 16) & 0x3FF - DataPointUtil.VERTICAL_OFFSET, + (int)(oldData >> 8) & 0xF, + (int)(oldData >> 12) & 0xF, + (int)(oldData >> 5) & 0x1, + ((oldData >> 5) & 0x1) == 1 ); tempDataContainer[i] = newData; } } - else //if (version == 7) + else if (version == 7) { + long oldData; for (int i = 0; i < x; i++) { - newData = 0; + oldData = 0; for (tempIndex = 0; tempIndex < 8; tempIndex++) - newData += (((long) inputData[index + tempIndex]) & 0xff) << (8 * tempIndex); + oldData += (((long) inputData[index + tempIndex]) & 0xff) << (8 * tempIndex); index += 8; + DataPoint newData = DataPointUtil.createDataPoint( + (int)((oldData >> 60) << 4) + 15, + (int)(oldData >> 52) & 0xFF, + (int)(oldData >> 44) & 0xFF, + (int)(oldData >> 36) & 0xFF, + (int)(oldData >> 26) & 0x3FF - DataPointUtil.VERTICAL_OFFSET - 64, + (int)(oldData >> 16) & 0x3FF - DataPointUtil.VERTICAL_OFFSET - 64, + (int)(oldData >> 8) & 0xF, + (int)(oldData >> 12) & 0xF, + (int)(oldData >> 5) & 0x1, + ((oldData >> 5) & 0x1) == 1 + ); tempDataContainer[i] = newData; } } + else //if (version == 8) + { + int color; + int data; + for (int i = 0; i < x; i++) + { + byte flags = inputData[index]; + index++; + data = 0; + color = 0; + for (tempIndex = 0; tempIndex < 8; tempIndex++) + { + data += (((int) inputData[index + tempIndex]) & 0xff) << (8 * tempIndex); + color += (((int) inputData[index + tempIndex + 4]) & 0xff) << (8 * tempIndex); + } + index += 8; + + tempDataContainer[i] = new DataPoint(color, data, flags); + } + } if (tempMaxVerticalData > DetailDistanceUtil.getMaxVerticalData(detailLevel)) { int tempMaxVerticalData2 = DetailDistanceUtil.getMaxVerticalData(detailLevel); - long[] dataToMerge = new long[tempMaxVerticalData]; - long[] tempDataContainer2 = new long[size * size * tempMaxVerticalData2]; + DataPoint[] dataToMerge = new DataPoint[tempMaxVerticalData]; + DataPoint[] tempDataContainer2 = new DataPoint[size * size * tempMaxVerticalData2]; for (int i = 0; i < size * size; i++) { System.arraycopy(tempDataContainer, i * tempMaxVerticalData, dataToMerge, 0, tempMaxVerticalData); @@ -203,12 +245,12 @@ public class VerticalLevelContainer implements LevelContainer public void updateData(LevelContainer lowerLevelContainer, int posX, int posZ) { //We reset the array - long[] dataToMerge = ThreadMapUtil.getVerticalUpdateArray(detailLevel); + DataPoint[] dataToMerge = ThreadMapUtil.getVerticalUpdateArray(detailLevel); int lowerMaxVertical = dataToMerge.length / 4; int childPosX; int childPosZ; - long[] data; + DataPoint[] data; posX = LevelPosUtil.getRegionModule(detailLevel, posX); posZ = LevelPosUtil.getRegionModule(detailLevel, posZ); for (int x = 0; x <= 1; x++) @@ -232,7 +274,7 @@ public class VerticalLevelContainer implements LevelContainer int index = 0; int x = size * size; int tempIndex; - long current; + DataPoint current; boolean allGenerated = true; byte[] tempData = ThreadMapUtil.getSaveContainer(detailLevel); @@ -246,11 +288,19 @@ public class VerticalLevelContainer implements LevelContainer for (j = 0; j < maxVerticalData; j++) { current = dataContainer[i * maxVerticalData + j]; - for (tempIndex = 0; tempIndex < 8; tempIndex++) - tempData[index + tempIndex] = (byte) (current >>> (8 * tempIndex)); + if (current != null) + { + tempData[index] = current.flags; + index++; + for (tempIndex = 0; tempIndex < 4; tempIndex++) + { + tempData[index + tempIndex] = (byte) (current.data >>> (8 * tempIndex)); + tempData[index + tempIndex + 4] = (byte) (current.color >>> (8 * tempIndex)); + } + } index += 8; } - if(!DataPointUtil.doesItExist(dataContainer[i])) + if(dataContainer[i] == null || !DataPointUtil.doesItExist(dataContainer[i])) allGenerated = false; } if (allGenerated) diff --git a/src/main/java/com/seibel/lod/core/util/DataPointUtil.java b/src/main/java/com/seibel/lod/core/util/DataPointUtil.java index 81b11c287..e39707ce7 100644 --- a/src/main/java/com/seibel/lod/core/util/DataPointUtil.java +++ b/src/main/java/com/seibel/lod/core/util/DataPointUtil.java @@ -22,6 +22,7 @@ package com.seibel.lod.core.util; import static com.seibel.lod.core.builders.bufferBuilding.LodBufferBuilderFactory.skyLightPlayer; import com.seibel.lod.core.enums.config.DistanceGenerationMode; +import com.seibel.lod.core.objects.lod.DataPoint; /** * @@ -57,9 +58,9 @@ public class DataPointUtil //To be used in the future for negative value //public final static int MIN_DEPTH = -64; //public final static int MIN_HEIGHT = -64; - public final static int EMPTY_DATA = 0; - public static final short VERTICAL_OFFSET = -64; - public static int WORLD_HEIGHT = 1024; + public final static DataPoint EMPTY_DATA = new DataPoint(); + public static final short VERTICAL_OFFSET = -2048; + public static int WORLD_HEIGHT = 4096; public final static int ALPHA_DOWNSIZE_SHIFT = 4; @@ -68,155 +69,145 @@ public class DataPointUtil //public final static int RED_COLOR_SHIFT = 16; //public final static int ALPHA_COLOR_SHIFT = 24; - public final static int BLUE_SHIFT = 36; - public final static int GREEN_SHIFT = BLUE_SHIFT + 8; - public final static int RED_SHIFT = BLUE_SHIFT + 16; - public final static int ALPHA_SHIFT = BLUE_SHIFT + 24; + public final static byte BLUE_SHIFT = 0; + public final static byte GREEN_SHIFT = 8; + public final static byte RED_SHIFT = 16; + public final static byte ALPHA_SHIFT = 24; - public final static int COLOR_SHIFT = 36; + //public final static byte COLOR_SHIFT = 36; - public final static int HEIGHT_SHIFT = 26; - public final static int DEPTH_SHIFT = 16; - public final static int BLOCK_LIGHT_SHIFT = 12; - public final static int SKY_LIGHT_SHIFT = 8; - //public final static int LIGHTS_SHIFT = SKY_LIGHT_SHIFT; - //public final static int VERTICAL_INDEX_SHIFT = 6; - public final static int FLAG_SHIFT = 5; - public final static int GEN_TYPE_SHIFT = 2; - public final static int VOID_SHIFT = 1; - public final static int EXISTENCE_SHIFT = 0; + public final static byte HEIGHT_SHIFT = 20; + public final static byte DEPTH_SHIFT = 8; + public final static byte BLOCK_LIGHT_SHIFT = 4; + public final static byte SKY_LIGHT_SHIFT = 0; + //public final static byte LIGHTS_SHIFT = SKY_LIGHT_SHIFT; + //public final static byte VERTICAL_INDEX_SHIFT = 6; + public final static byte FLAG_SHIFT = 5; + public final static byte GEN_TYPE_SHIFT = 2; + public final static byte VOID_SHIFT = 1; + public final static byte EXISTENCE_SHIFT = 0; - public final static long ALPHA_MASK = 0b1111; - public final static long RED_MASK = 0b1111_1111; - public final static long GREEN_MASK = 0b1111_1111; - public final static long BLUE_MASK = 0b1111_1111; - public final static long COLOR_MASK = 0b11111111_11111111_11111111; - public final static long HEIGHT_MASK = 0b11_1111_1111; - public final static long DEPTH_MASK = 0b11_1111_1111; - //public final static long LIGHTS_MASK = 0b1111_1111; - public final static long BLOCK_LIGHT_MASK = 0b1111; - public final static long SKY_LIGHT_MASK = 0b1111; - //public final static long VERTICAL_INDEX_MASK = 0b11; - public final static long FLAG_MASK = 0b1; - public final static long GEN_TYPE_MASK = 0b111; - public final static long VOID_MASK = 1; - public final static long EXISTENCE_MASK = 1; + public final static int ALPHA_MASK = 0xFF; + public final static int RED_MASK = 0xFF; + public final static int GREEN_MASK = 0xFF; + public final static int BLUE_MASK = 0xFF; + public final static int COLOR_MASK = 0xFFFFFFFF; + public final static int HEIGHT_MASK = 0xFFF; + public final static int DEPTH_MASK = 0xFFF; + public final static int LIGHTS_MASK = 0xFF; + public final static int BLOCK_LIGHT_MASK = 0xF; + public final static int SKY_LIGHT_MASK = 0xF; + public final static int VERTICAL_INDEX_MASK = 0x3; + public final static byte FLAG_MASK = 0x1; + public final static byte GEN_TYPE_MASK = 0x7; + public final static byte VOID_MASK = 1; + public final static byte EXISTENCE_MASK = 1; - public static long createVoidDataPoint(int generationMode) + public static DataPoint createVoidDataPoint(int generationMode) { - long dataPoint = 0; - dataPoint += (generationMode & GEN_TYPE_MASK) << GEN_TYPE_SHIFT; - dataPoint += VOID_MASK << VOID_SHIFT; - dataPoint += EXISTENCE_MASK << EXISTENCE_SHIFT; - return dataPoint; + byte flags = (byte) ((generationMode & GEN_TYPE_MASK) << GEN_TYPE_SHIFT); + flags += VOID_MASK << VOID_SHIFT; + flags += EXISTENCE_MASK << EXISTENCE_SHIFT; + return new DataPoint(0, 0, flags); } - public static long createDataPoint(int height, int depth, int color, int lightSky, int lightBlock, int generationMode, boolean flag) + public static DataPoint createDataPoint(int height, int depth, int color, int lightSky, int lightBlock, int generationMode, boolean flag) + { + int data = (height & HEIGHT_MASK) << HEIGHT_SHIFT; + data += (depth & DEPTH_MASK) << DEPTH_SHIFT; + data += (lightBlock & BLOCK_LIGHT_MASK) << BLOCK_LIGHT_SHIFT; + data += (lightSky & SKY_LIGHT_MASK) << SKY_LIGHT_SHIFT; + byte flags = (byte) ((generationMode & GEN_TYPE_MASK) << GEN_TYPE_SHIFT); + if (flag) flags += FLAG_MASK << FLAG_SHIFT; + flags += EXISTENCE_MASK << EXISTENCE_SHIFT; + return new DataPoint(color, data, flags); + } + + public static DataPoint createDataPoint(int alpha, int red, int green, int blue, int height, int depth, int lightSky, int lightBlock, int generationMode, boolean flag) { return createDataPoint( - ColorUtil.getAlpha(color), - ColorUtil.getRed(color), - ColorUtil.getGreen(color), - ColorUtil.getBlue(color), - height, depth, lightSky, lightBlock, generationMode, flag); + height, depth, + (alpha << ALPHA_SHIFT) | (red << RED_SHIFT) | (green << GREEN_SHIFT) | blue, + lightSky, lightBlock, generationMode, flag); } - public static long createDataPoint(int alpha, int red, int green, int blue, int height, int depth, int lightSky, int lightBlock, int generationMode, boolean flag) + public static short getHeight(DataPoint dataPoint) { - long dataPoint = 0; - dataPoint += (long) (alpha >>> 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 (short) ((dataPoint.data >>> HEIGHT_SHIFT) & HEIGHT_MASK); } - public static short getHeight(long dataPoint) + public static short getDepth(DataPoint dataPoint) { - return (short) ((dataPoint >>> HEIGHT_SHIFT) & HEIGHT_MASK); + return (short) ((dataPoint.data >>> DEPTH_SHIFT) & DEPTH_MASK); } - public static short getDepth(long dataPoint) + public static short getAlpha(DataPoint dataPoint) { - return (short) ((dataPoint >>> DEPTH_SHIFT) & DEPTH_MASK); + return (short) ((dataPoint.color >>> ALPHA_SHIFT) & ALPHA_MASK); } - public static short getAlpha(long dataPoint) + public static short getRed(DataPoint dataPoint) { - return (short) ((((dataPoint >>> ALPHA_SHIFT) & ALPHA_MASK) << ALPHA_DOWNSIZE_SHIFT) | 0b1111); + return (short) ((dataPoint.color >>> RED_SHIFT) & RED_MASK); } - public static short getRed(long dataPoint) + public static short getGreen(DataPoint dataPoint) { - return (short) ((dataPoint >>> RED_SHIFT) & RED_MASK); + return (short) ((dataPoint.color >>> GREEN_SHIFT) & GREEN_MASK); } - public static short getGreen(long dataPoint) + public static short getBlue(DataPoint dataPoint) { - return (short) ((dataPoint >>> GREEN_SHIFT) & GREEN_MASK); + return (short) ((dataPoint.color >>> BLUE_SHIFT) & BLUE_MASK); } - public static short getBlue(long dataPoint) + public static byte getLightSky(DataPoint dataPoint) { - return (short) ((dataPoint >>> BLUE_SHIFT) & BLUE_MASK); + return (byte) ((dataPoint.data >>> SKY_LIGHT_SHIFT) & SKY_LIGHT_MASK); } - public static byte getLightSky(long dataPoint) + public static byte getLightSkyAlt(DataPoint dataPoint) { - return (byte) ((dataPoint >>> SKY_LIGHT_SHIFT) & SKY_LIGHT_MASK); - } - - public static byte getLightSkyAlt(long dataPoint) - { - if (skyLightPlayer == 0 && ((dataPoint >>> FLAG_SHIFT) & FLAG_MASK) == 1) + if (skyLightPlayer == 0 && ((dataPoint.flags >>> FLAG_SHIFT) & FLAG_MASK) == 1) return 0; else - return (byte) ((dataPoint >>> SKY_LIGHT_SHIFT) & SKY_LIGHT_MASK); + return (byte) ((dataPoint.data >>> SKY_LIGHT_SHIFT) & SKY_LIGHT_MASK); } - public static byte getLightBlock(long dataPoint) + public static byte getLightBlock(DataPoint dataPoint) { - return (byte) ((dataPoint >>> BLOCK_LIGHT_SHIFT) & BLOCK_LIGHT_MASK); + return (byte) ((dataPoint.data >>> BLOCK_LIGHT_SHIFT) & BLOCK_LIGHT_MASK); } - public static boolean getFlag(long dataPoint) + public static boolean getFlag(DataPoint dataPoint) { - return ((dataPoint >>> FLAG_SHIFT) & FLAG_MASK) == 1; + return ((dataPoint.flags >>> FLAG_SHIFT) & FLAG_MASK) == 1; } - public static byte getGenerationMode(long dataPoint) + public static byte getGenerationMode(DataPoint dataPoint) { - return (byte) ((dataPoint >>> GEN_TYPE_SHIFT) & GEN_TYPE_MASK); + return (byte) ((dataPoint.flags >>> GEN_TYPE_SHIFT) & GEN_TYPE_MASK); } - - public static boolean isVoid(long dataPoint) + public static boolean isVoid(DataPoint dataPoint) { - return (((dataPoint >>> VOID_SHIFT) & VOID_MASK) == 1); + return (((dataPoint.flags >>> VOID_SHIFT) & VOID_MASK) == 1); } - public static boolean doesItExist(long dataPoint) + public static boolean doesItExist(DataPoint dataPoint) { - return (((dataPoint >>> EXISTENCE_SHIFT) & EXISTENCE_MASK) == 1); + return (dataPoint != null) && (((dataPoint.flags >>> EXISTENCE_SHIFT) & EXISTENCE_MASK) == 1); } - public static int getColor(long dataPoint) + public static int getColor(DataPoint dataPoint) { - return (int) (((dataPoint >>> COLOR_SHIFT) & COLOR_MASK) | (/*((dataPoint >>> (ALPHA_SHIFT - ALPHA_DOWNSIZE_SHIFT)) | 0b1111)*/255 << 24)); + return dataPoint.color; } /** This is used to convert a dataPoint to string (useful for the print function) */ @SuppressWarnings("unused") - public static String toString(long dataPoint) + public static String toString(DataPoint dataPoint) { return getHeight(dataPoint) + " " + getDepth(dataPoint) + " " + @@ -263,20 +254,20 @@ public class DataPointUtil * @param maxVerticalData max vertical size of the merged data * @return one column of correctly parsed data */ - public static long[] mergeMultiData(long[] dataToMerge, int inputVerticalData, int maxVerticalData) + public static DataPoint[] mergeMultiData(DataPoint[] dataToMerge, int inputVerticalData, int maxVerticalData) { int size = dataToMerge.length / inputVerticalData; // We initialize the arrays that are going to be used short[] heightAndDepth = ThreadMapUtil.getHeightAndDepth((WORLD_HEIGHT / 2 + 1) * 2); - long[] dataPoint = ThreadMapUtil.getVerticalDataArray(DetailDistanceUtil.getMaxVerticalData(0)); + DataPoint[] dataPoint = ThreadMapUtil.getVerticalDataArray(DetailDistanceUtil.getMaxVerticalData(0)); int genMode = DistanceGenerationMode.FULL.complexity; boolean allEmpty = true; boolean allVoid = true; boolean allDefault; - long singleData; + DataPoint singleData; short depth; @@ -291,7 +282,7 @@ public class DataPointUtil for (dataIndex = 0; dataIndex < inputVerticalData; dataIndex++) { singleData = dataToMerge[index * inputVerticalData + dataIndex]; - if (doesItExist(singleData)) + if (singleData != null && doesItExist(singleData)) { genMode = Math.min(genMode, getGenerationMode(singleData)); allEmpty = false; @@ -451,7 +442,7 @@ public class DataPointUtil allEmpty = true; allVoid = true; allDefault = true; - long data = 0; + DataPoint data = EMPTY_DATA; for (int index = 0; index < size; index++) { @@ -460,7 +451,6 @@ public class DataPointUtil singleData = dataToMerge[index * inputVerticalData + dataIndex]; if (doesItExist(singleData) && !isVoid(singleData)) { - if ((depth <= getDepth(singleData) && getDepth(singleData) <= height) || (depth <= getHeight(singleData) && getHeight(singleData) <= height)) { @@ -474,7 +464,10 @@ public class DataPointUtil if (!doesItExist(data)) { singleData = dataToMerge[index * inputVerticalData]; - data = createVoidDataPoint(getGenerationMode(singleData)); + if (doesItExist(singleData)) + data = createVoidDataPoint(getGenerationMode(singleData)); + else + data = createVoidDataPoint(0); } if (doesItExist(data)) diff --git a/src/main/java/com/seibel/lod/core/util/ThreadMapUtil.java b/src/main/java/com/seibel/lod/core/util/ThreadMapUtil.java index cc179dffb..daf4a7785 100644 --- a/src/main/java/com/seibel/lod/core/util/ThreadMapUtil.java +++ b/src/main/java/com/seibel/lod/core/util/ThreadMapUtil.java @@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentMap; import com.seibel.lod.core.enums.LodDirection; import com.seibel.lod.core.objects.Box; +import com.seibel.lod.core.objects.lod.DataPoint; /** * Holds data used by specific threads so @@ -38,15 +39,15 @@ import com.seibel.lod.core.objects.Box; */ public class ThreadMapUtil { - public static final ConcurrentMap threadSingleUpdateMap = new ConcurrentHashMap<>(); - public static final ConcurrentMap threadBuilderArrayMap = new ConcurrentHashMap<>(); - public static final ConcurrentMap threadBuilderVerticalArrayMap = new ConcurrentHashMap<>(); - public static final ConcurrentMap threadVerticalAddDataMap = new ConcurrentHashMap<>(); + public static final ConcurrentMap threadSingleUpdateMap = new ConcurrentHashMap<>(); + public static final ConcurrentMap threadBuilderArrayMap = new ConcurrentHashMap<>(); + public static final ConcurrentMap threadBuilderVerticalArrayMap = new ConcurrentHashMap<>(); + public static final ConcurrentMap threadVerticalAddDataMap = new ConcurrentHashMap<>(); public static final ConcurrentMap saveContainer = new ConcurrentHashMap<>(); public static final ConcurrentMap projectionArrayMap = new ConcurrentHashMap<>(); public static final ConcurrentMap heightAndDepthMap = new ConcurrentHashMap<>(); - public static final ConcurrentMap singleDataToMergeMap = new ConcurrentHashMap<>(); - public static final ConcurrentMap verticalUpdate = new ConcurrentHashMap<>(); + public static final ConcurrentMap singleDataToMergeMap = new ConcurrentHashMap<>(); + public static final ConcurrentMap verticalUpdate = new ConcurrentHashMap<>(); //________________________// @@ -54,7 +55,7 @@ public class ThreadMapUtil //________________________// public static final ConcurrentMap adjShadeDisabled = new ConcurrentHashMap<>(); - public static final ConcurrentMap> adjDataMap = new ConcurrentHashMap<>(); + public static final ConcurrentMap> adjDataMap = new ConcurrentHashMap<>(); public static final ConcurrentMap boxMap = new ConcurrentHashMap<>(); @@ -72,7 +73,7 @@ public class ThreadMapUtil } /** returns the array NOT cleared every time */ - public static Map getAdjDataArray(int verticalData) + public static Map getAdjDataArray(int verticalData) { if (!adjDataMap.containsKey(Thread.currentThread().getName()) || (adjDataMap.get(Thread.currentThread().getName()) == null) @@ -80,10 +81,10 @@ public class ThreadMapUtil || (adjDataMap.get(Thread.currentThread().getName()).get(LodDirection.NORTH).length != verticalData)) { adjDataMap.put(Thread.currentThread().getName(), new HashMap<>()); - adjDataMap.get(Thread.currentThread().getName()).put(LodDirection.UP, new long[1]); - adjDataMap.get(Thread.currentThread().getName()).put(LodDirection.DOWN, new long[1]); + adjDataMap.get(Thread.currentThread().getName()).put(LodDirection.UP, new DataPoint[1]); + adjDataMap.get(Thread.currentThread().getName()).put(LodDirection.DOWN, new DataPoint[1]); for (LodDirection lodDirection : Box.ADJ_DIRECTIONS) - adjDataMap.get(Thread.currentThread().getName()).put(lodDirection, new long[verticalData]); + adjDataMap.get(Thread.currentThread().getName()).put(lodDirection, new DataPoint[verticalData]); } else { @@ -119,20 +120,20 @@ public class ThreadMapUtil /** returns the array filled with 0's */ - public static long[] getBuilderVerticalArray(int detailLevel) + public static DataPoint[] getBuilderVerticalArray(int detailLevel) { if (!threadBuilderVerticalArrayMap.containsKey(Thread.currentThread().getName()) || (threadBuilderVerticalArrayMap.get(Thread.currentThread().getName()) == null)) { - long[][] array = new long[5][]; + DataPoint[][] array = new DataPoint[5][]; int size; for (int i = 0; i < 5; i++) { size = 1 << i; - array[i] = new long[size * size * (DataPointUtil.WORLD_HEIGHT / 2 + 1)]; + array[i] = new DataPoint[size * size * (DataPointUtil.WORLD_HEIGHT / 2 + 1)]; } threadBuilderVerticalArrayMap.put(Thread.currentThread().getName(), array); } - Arrays.fill(threadBuilderVerticalArrayMap.get(Thread.currentThread().getName())[detailLevel], 0); + Arrays.fill(threadBuilderVerticalArrayMap.get(Thread.currentThread().getName())[detailLevel], DataPointUtil.EMPTY_DATA); return threadBuilderVerticalArrayMap.get(Thread.currentThread().getName())[detailLevel]; } @@ -145,7 +146,7 @@ public class ThreadMapUtil int size = 1; for (int i = LodUtil.DETAIL_OPTIONS - 1; i >= 0; i--) { - array[i] = new byte[2 + 8 * size * size * DetailDistanceUtil.getMaxVerticalData(i)]; + array[i] = new byte[2 + 9 * size * size * DetailDistanceUtil.getMaxVerticalData(i)]; size = size << 1; } saveContainer.put(Thread.currentThread().getName(), array); @@ -156,15 +157,15 @@ public class ThreadMapUtil /** returns the array filled with 0's */ - public static long[] getVerticalDataArray(int arrayLength) + public static DataPoint[] getVerticalDataArray(int arrayLength) { if (!threadVerticalAddDataMap.containsKey(Thread.currentThread().getName()) || (threadVerticalAddDataMap.get(Thread.currentThread().getName()) == null)) { - threadVerticalAddDataMap.put(Thread.currentThread().getName(), new long[arrayLength]); + threadVerticalAddDataMap.put(Thread.currentThread().getName(), new DataPoint[arrayLength]); } else { - Arrays.fill(threadVerticalAddDataMap.get(Thread.currentThread().getName()), 0); + Arrays.fill(threadVerticalAddDataMap.get(Thread.currentThread().getName()), DataPointUtil.EMPTY_DATA); } return threadVerticalAddDataMap.get(Thread.currentThread().getName()); } @@ -183,18 +184,18 @@ public class ThreadMapUtil /** returns the array filled with 0's */ - public static long[] getVerticalUpdateArray(int detailLevel) + public static DataPoint[] getVerticalUpdateArray(int detailLevel) { if (!verticalUpdate.containsKey(Thread.currentThread().getName()) || (verticalUpdate.get(Thread.currentThread().getName()) == null)) { - long[][] array = new long[LodUtil.DETAIL_OPTIONS][]; + DataPoint[][] array = new DataPoint[LodUtil.DETAIL_OPTIONS][]; for (int i = 1; i < LodUtil.DETAIL_OPTIONS; i++) - array[i] = new long[DetailDistanceUtil.getMaxVerticalData(i - 1) * 4]; + array[i] = new DataPoint[DetailDistanceUtil.getMaxVerticalData(i - 1) * 4]; verticalUpdate.put(Thread.currentThread().getName(), array); } else { - Arrays.fill(verticalUpdate.get(Thread.currentThread().getName())[detailLevel], 0); + Arrays.fill(verticalUpdate.get(Thread.currentThread().getName())[detailLevel], DataPointUtil.EMPTY_DATA); } return verticalUpdate.get(Thread.currentThread().getName())[detailLevel]; }