Start commenting and refactoring SingleLevelContainer
This commit is contained in:
@@ -4,7 +4,7 @@ public interface LevelContainer
|
||||
{
|
||||
public static final char VERTICAL_DATA_DELIMITER = '\t';
|
||||
public static final char DATA_DELIMITER = ' ';
|
||||
|
||||
|
||||
/**With this you can add data to the level container
|
||||
*
|
||||
* @param data actual data to add in a array of long format.
|
||||
@@ -14,7 +14,7 @@ public interface LevelContainer
|
||||
* @return true if correctly added, false otherwise
|
||||
*/
|
||||
public 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 a array of long format.
|
||||
@@ -23,7 +23,7 @@ public interface LevelContainer
|
||||
* @return true if correctly added, false otherwise
|
||||
*/
|
||||
public boolean addSingleData(long data, int posX, int posZ);
|
||||
|
||||
|
||||
/**With this you can get data from the level container
|
||||
*
|
||||
* @param posX x position in the detail level
|
||||
@@ -31,7 +31,7 @@ public interface LevelContainer
|
||||
* @return the data in long array format
|
||||
*/
|
||||
public long getData(int posX, int posZ, int index);
|
||||
|
||||
|
||||
/**With this you can get data from the level container
|
||||
*
|
||||
* @param posX x position in the detail level
|
||||
@@ -39,30 +39,31 @@ public interface LevelContainer
|
||||
* @return the data in long array format
|
||||
*/
|
||||
public long getSingleData(int posX, int posZ);
|
||||
|
||||
|
||||
/**
|
||||
* @param posX x position in the detail level
|
||||
* @param posZ z position in the detail level
|
||||
* @return true only if the data exist
|
||||
*/
|
||||
public boolean doesItExist(int posX, int posZ);
|
||||
|
||||
|
||||
/**
|
||||
* @return return the deatilLevel of this level container
|
||||
*/
|
||||
public byte getDetailLevel();
|
||||
|
||||
|
||||
|
||||
|
||||
public int getMaxVerticalData();
|
||||
|
||||
|
||||
/** Clears the dataPoint at the given array index */
|
||||
public void clear(int posX, int posZ);
|
||||
|
||||
|
||||
/**This return a level container with detail level lower than the current level.
|
||||
* The new level container may use information of this level.
|
||||
* @return the new level container
|
||||
*/
|
||||
public LevelContainer expand();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param lowerLevelContainer lower level where we extract the data
|
||||
@@ -70,20 +71,20 @@ public interface LevelContainer
|
||||
* @param posZ z position in the detail level to update
|
||||
*/
|
||||
public void updateData(LevelContainer lowerLevelContainer, int posX, int posZ);
|
||||
|
||||
|
||||
/**
|
||||
* This will give the data to save in the file
|
||||
* @return data as a String
|
||||
*/
|
||||
public byte[] toDataString();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This will give the data to save in the file
|
||||
* @return data as a String
|
||||
*/
|
||||
public int getMaxNumberOfLods();
|
||||
|
||||
|
||||
/**
|
||||
* This will give the data to save in the file
|
||||
* @return data as a String
|
||||
|
||||
@@ -7,20 +7,79 @@ import com.seibel.lod.util.LevelPosUtil;
|
||||
import com.seibel.lod.util.LodUtil;
|
||||
import com.seibel.lod.util.ThreadMapUtil;
|
||||
|
||||
/**
|
||||
* This object holds the LOD data for a single dataPoint.
|
||||
*
|
||||
* @author Leonardo Amato
|
||||
* @version 9-28-2021
|
||||
*/
|
||||
public class SingleLevelContainer implements LevelContainer
|
||||
{
|
||||
/** The detailLevel of this LevelContainer */
|
||||
public final byte detailLevel;
|
||||
public final int size;
|
||||
/** How many dataPoints wide is this LevelContainer? */
|
||||
public final int dataWidthCount;
|
||||
|
||||
/** This holds all the dataPoints for this LevelContainer */
|
||||
public final long[][] dataContainer;
|
||||
|
||||
public SingleLevelContainer(byte detailLevel)
|
||||
|
||||
|
||||
/** Constructor */
|
||||
public SingleLevelContainer(byte newDetailLevel)
|
||||
{
|
||||
this.detailLevel = detailLevel;
|
||||
size = 1 << (LodUtil.REGION_DETAIL_LEVEL - detailLevel);
|
||||
dataContainer = new long[size][size];
|
||||
this.detailLevel = newDetailLevel;
|
||||
|
||||
// equivalent to 2^(...)
|
||||
dataWidthCount = 1 << (LodUtil.REGION_DETAIL_LEVEL - newDetailLevel);
|
||||
dataContainer = new long[dataWidthCount][dataWidthCount];
|
||||
}
|
||||
|
||||
/** */
|
||||
public SingleLevelContainer(byte[] inputData)
|
||||
{
|
||||
int tempIndex;
|
||||
int index = 0;
|
||||
long newData;
|
||||
detailLevel = inputData[index];
|
||||
index++;
|
||||
dataWidthCount = (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel);
|
||||
this.dataContainer = new long[dataWidthCount][dataWidthCount];
|
||||
|
||||
for (int x = 0; x < dataWidthCount; x++)
|
||||
{
|
||||
for (int z = 0; z < dataWidthCount; z++)
|
||||
{
|
||||
newData = 0;
|
||||
if (inputData[index] == 0)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
else if (inputData[index] == 3)
|
||||
{
|
||||
newData = 3;
|
||||
index++;
|
||||
}
|
||||
else if (index + 7 >= inputData.length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (tempIndex = 0; tempIndex < 8; tempIndex++)
|
||||
newData += (((long) inputData[index + tempIndex]) & 0xff) << (8 * tempIndex);
|
||||
index = index + 8;
|
||||
}
|
||||
|
||||
dataContainer[x][z] = newData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void clear(int posX, int posZ)
|
||||
{
|
||||
@@ -52,7 +111,7 @@ public class SingleLevelContainer implements LevelContainer
|
||||
{
|
||||
posX = LevelPosUtil.getRegionModule(detailLevel, posX);
|
||||
posZ = LevelPosUtil.getRegionModule(detailLevel, posZ);
|
||||
//Improve this using a thread map to long[]
|
||||
// TODO Improve this using a thread map to long[]
|
||||
return dataContainer[posX][posZ];
|
||||
}
|
||||
|
||||
@@ -61,7 +120,7 @@ public class SingleLevelContainer implements LevelContainer
|
||||
{
|
||||
posX = LevelPosUtil.getRegionModule(detailLevel, posX);
|
||||
posZ = LevelPosUtil.getRegionModule(detailLevel, posZ);
|
||||
//Improve this using a thread map to long[]
|
||||
// TODO Improve this using a thread map to long[]
|
||||
return dataContainer[posX][posZ];
|
||||
}
|
||||
|
||||
@@ -77,39 +136,7 @@ public class SingleLevelContainer implements LevelContainer
|
||||
return new SingleLevelContainer((byte) (getDetailLevel() - 1));
|
||||
}
|
||||
|
||||
public SingleLevelContainer(byte[] inputData)
|
||||
{
|
||||
int tempIndex;
|
||||
int index = 0;
|
||||
long newData;
|
||||
detailLevel = inputData[index];
|
||||
index++;
|
||||
size = (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel);
|
||||
this.dataContainer = new long[size][size];
|
||||
for (int x = 0; x < size; x++)
|
||||
{
|
||||
for (int z = 0; z < size; z++)
|
||||
{
|
||||
newData = 0;
|
||||
if (inputData[index] == 0)
|
||||
index++;
|
||||
else if (inputData[index] == 3)
|
||||
{
|
||||
newData = 3;
|
||||
index++;
|
||||
} else if (index + 7 >= inputData.length)
|
||||
break;
|
||||
else
|
||||
{
|
||||
for (tempIndex = 0; tempIndex < 8; tempIndex++)
|
||||
newData += (((long) inputData[index + tempIndex]) & 0xff) << (8 * tempIndex);
|
||||
index = index + 8;
|
||||
}
|
||||
dataContainer[x][z] = newData;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** TODO could this be renamed mergeData? */
|
||||
@Override
|
||||
@@ -156,13 +183,13 @@ public class SingleLevelContainer implements LevelContainer
|
||||
{
|
||||
int index = 0;
|
||||
int tempIndex;
|
||||
byte[] tempData = ThreadMapUtil.getFreshSaveContainer(1 + (size * size * 8));
|
||||
byte[] tempData = ThreadMapUtil.getFreshSaveContainer(1 + (dataWidthCount * dataWidthCount * 8));
|
||||
|
||||
tempData[index] = detailLevel;
|
||||
index++;
|
||||
for (int x = 0; x < size; x++)
|
||||
for (int x = 0; x < dataWidthCount; x++)
|
||||
{
|
||||
for (int z = 0; z < size; z++)
|
||||
for (int z = 0; z < dataWidthCount; z++)
|
||||
{
|
||||
if (dataContainer[x][z] == 0)
|
||||
{
|
||||
@@ -195,7 +222,7 @@ public class SingleLevelContainer implements LevelContainer
|
||||
@Override
|
||||
public int getMaxNumberOfLods()
|
||||
{
|
||||
return size * size * getMaxVerticalData();
|
||||
return dataWidthCount * dataWidthCount * getMaxVerticalData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user