diff --git a/src/main/java/com/seibel/lod/builders/lodBuilding/LodBuilder.java b/src/main/java/com/seibel/lod/builders/lodBuilding/LodBuilder.java index cc873b13c..bfd07edd8 100644 --- a/src/main/java/com/seibel/lod/builders/lodBuilding/LodBuilder.java +++ b/src/main/java/com/seibel/lod/builders/lodBuilding/LodBuilder.java @@ -214,17 +214,7 @@ public class LodBuilder //lodDim.clear(detailLevel, posX, posZ); if (data != null && data.length != 0) - { - for (int verticalIndex = 0; verticalIndex < lodDim.getMaxVerticalData(detailLevel, posX, posZ); verticalIndex++) - { - lodDim.addData(detailLevel, - posX, - posZ, - verticalIndex, - data[verticalIndex], - false); - } - } + lodDim.addVerticalData(detailLevel, posX, posZ, data,false); } lodDim.updateData(LodUtil.CHUNK_DETAIL_LEVEL, chunk.getPos().x, chunk.getPos().z); } diff --git a/src/main/java/com/seibel/lod/objects/LevelContainer.java b/src/main/java/com/seibel/lod/objects/LevelContainer.java index 018dc396d..bb24a5e80 100644 --- a/src/main/java/com/seibel/lod/objects/LevelContainer.java +++ b/src/main/java/com/seibel/lod/objects/LevelContainer.java @@ -15,6 +15,15 @@ public interface LevelContainer */ boolean addData(long data, int posX, int posZ, int index); + /** + * With this you can add data to the level container + * @param data actual data to add in an array of long[] format. + * @param posX x position in the detail level + * @param posZ z position in the detail level + * @return true if correctly added, false otherwise + */ + boolean addVerticalData(long[] data, int posX, int posZ); + /** * With this you can add data to the level container * @param data actual data to add in an array of long format. diff --git a/src/main/java/com/seibel/lod/objects/LodDimension.java b/src/main/java/com/seibel/lod/objects/LodDimension.java index 58eaad3ab..43c7caaff 100644 --- a/src/main/java/com/seibel/lod/objects/LodDimension.java +++ b/src/main/java/com/seibel/lod/objects/LodDimension.java @@ -470,6 +470,48 @@ public class LodDimension return nodeAdded; } + /** + * Add whole column of LODs to this dimension at the coordinate + * 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) + { + int regionPosX = LevelPosUtil.getRegion(detailLevel, posX); + int regionPosZ = LevelPosUtil.getRegion(detailLevel, posZ); + + // don't continue if the region can't be saved + LodRegion region = getRegion(regionPosX, regionPosZ); + if (region == null) + return false; + + boolean nodeAdded = region.addVerticalData(detailLevel, posX, posZ, data); + + // only save valid LODs to disk + if (!dontSave && fileHandler != null) + { + try + { + // mark the region as dirty, so it will be saved to disk + int xIndex = (regionPosX - center.x) + halfWidth; + int zIndex = (regionPosZ - center.z) + halfWidth; + + isRegionDirty[xIndex][zIndex] = true; + regenRegionBuffer[xIndex][zIndex] = true; + regenDimensionBuffers = true; + } + catch (ArrayIndexOutOfBoundsException e) + { + e.printStackTrace(); + // If this happens, the method was probably + // called when the dimension was changing size. + // Hopefully this shouldn't be an issue. + } + } + + return nodeAdded; + } + /** marks the region at the given region position to have its buffer rebuilt */ public void markRegionBufferToRegen(int xRegion, int zRegion) { diff --git a/src/main/java/com/seibel/lod/objects/LodRegion.java b/src/main/java/com/seibel/lod/objects/LodRegion.java index d608ea163..15c98b45b 100644 --- a/src/main/java/com/seibel/lod/objects/LodRegion.java +++ b/src/main/java/com/seibel/lod/objects/LodRegion.java @@ -105,6 +105,26 @@ public class LodRegion return true; } + /** + * Inserts the vertical data into the region. + *
+ * 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) + { + //position is already relative + //posX = LevelPosUtil.getRegionModule(detailLevel, posX); + //posZ = LevelPosUtil.getRegionModule(detailLevel, posZ); + + // The dataContainer could have null entries if the + // detailLevel changes. + if (this.dataContainer[detailLevel] == null) + this.dataContainer[detailLevel] = new VerticalLevelContainer(detailLevel); + + return this.dataContainer[detailLevel].addVerticalData(data, posX, posZ); + } + /** * Get the dataPoint at the given relative position. * @return the data at the relative pos and detail level, diff --git a/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java b/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java index 87c256f41..41aa64173 100644 --- a/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java +++ b/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java @@ -49,6 +49,16 @@ public class VerticalLevelContainer implements LevelContainer return true; } + public boolean addVerticalData(long[] data, int posX, int posZ) + { + + posX = LevelPosUtil.getRegionModule(detailLevel, posX); + posZ = LevelPosUtil.getRegionModule(detailLevel, posZ); + for (int verticalIndex = 0; verticalIndex < maxVerticalData; verticalIndex++) + dataContainer[posX * size * maxVerticalData + posZ * maxVerticalData + verticalIndex] = data[verticalIndex]; + return true; + } + @Override public boolean addSingleData(long data, int posX, int posZ) {