Created the single level container
This commit is contained in:
@@ -126,7 +126,7 @@ public class LodBuilder
|
||||
generateLodNodeFromChunk(lodDim, chunk, new LodBuilderConfig(generationMode));
|
||||
} catch (IllegalArgumentException | NullPointerException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
//e.printStackTrace();
|
||||
// if the world changes while LODs are being generated
|
||||
// they will throw errors as they try to access things that no longer
|
||||
// exist.
|
||||
@@ -200,7 +200,7 @@ public class LodBuilder
|
||||
posX = LevelPosUtil.convert((byte) 0, chunk.getPos().x * 16 + startX, detail.detailLevel);
|
||||
posZ = LevelPosUtil.convert((byte) 0, chunk.getPos().z * 16 + startZ, detail.detailLevel);
|
||||
boolean isServer = config.distanceGenerationMode == DistanceGenerationMode.SERVER;
|
||||
data = DataPointUtil.createDataPoint(height, depth, ColorUtil.getRed(color), ColorUtil.getGreen(color), ColorUtil.getBlue(color));
|
||||
data = DataPointUtil.createDataPoint(height, depth, color, 0 , 0);
|
||||
lodDim.addData(detailLevel,
|
||||
posX,
|
||||
posZ,
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.seibel.lod.enums.DistanceGenerationMode;
|
||||
import com.seibel.lod.objects.VerticalLevelContainer;
|
||||
import com.seibel.lod.objects.SingleLevelContainer;
|
||||
import com.seibel.lod.objects.LodDimension;
|
||||
import com.seibel.lod.objects.LodRegion;
|
||||
import com.seibel.lod.objects.RegionPos;
|
||||
@@ -200,7 +200,7 @@ public class LodDimensionFileHandler
|
||||
data = bufferedReader.readLine();
|
||||
|
||||
bufferedReader.close();
|
||||
region.addLevel(new VerticalLevelContainer(data));
|
||||
region.addLevel(new SingleLevelContainer(data));
|
||||
} catch (Exception e)
|
||||
{
|
||||
// the buffered reader encountered a
|
||||
@@ -331,7 +331,7 @@ public class LodDimensionFileHandler
|
||||
fw.write(LOD_FILE_VERSION_PREFIX + " " + LOD_SAVE_FILE_VERSION + "\n");
|
||||
|
||||
// add each LodChunk to the file
|
||||
fw.write(region.getLevel(detailLevel).toString());
|
||||
fw.write(region.getLevel(detailLevel).toDataString());
|
||||
fw.close();
|
||||
|
||||
// overwrite the old file with the new one
|
||||
|
||||
@@ -3,15 +3,19 @@ package com.seibel.lod.objects;
|
||||
import com.seibel.lod.util.LevelPosUtil;
|
||||
import com.seibel.lod.util.LodUtil;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public interface LevelContainer
|
||||
{
|
||||
public static final char VERTICAL_DATA_DELIMITER = '\t';
|
||||
public static final char DATA_DELIMITER = '\n';
|
||||
public static final char DATA_DELIMITER = ',';
|
||||
public static final ConcurrentMap<String,long[]> threadAddDataMap = new ConcurrentHashMap();
|
||||
public static final ConcurrentMap<String,long[]> threadGetDataMap = new ConcurrentHashMap();
|
||||
|
||||
/**With this you can add data to the level container
|
||||
*
|
||||
* @param data actual data to add in a array of long format.
|
||||
* @param detailLevel just to check that it's correct
|
||||
* @param posX x position in the detail level
|
||||
* @param posZ z position in the detail level
|
||||
* @return true if correctly added, false otherwise
|
||||
@@ -20,7 +24,6 @@ public interface LevelContainer
|
||||
|
||||
/**With this you can get data from the level container
|
||||
*
|
||||
* @param detailLevel just to check that it's correct
|
||||
* @param posX x position in the detail level
|
||||
* @param posZ z position in the detail level
|
||||
* @return the data in long array format
|
||||
@@ -28,7 +31,6 @@ public interface LevelContainer
|
||||
public long[] getData(int posX, int posZ);
|
||||
|
||||
/**
|
||||
* @param detailLevel just to check that it's correct
|
||||
* @param posX x position in the detail level
|
||||
* @param posZ z position in the detail level
|
||||
* @return true only if the data exist
|
||||
@@ -49,7 +51,6 @@ public interface LevelContainer
|
||||
/**
|
||||
*
|
||||
* @param lowerLevelContainer lower level where we extract the data
|
||||
* @param detailLevel detail level to update
|
||||
* @param posX x position in the detail level to update
|
||||
* @param posZ z position in the detail level to update
|
||||
*/
|
||||
|
||||
@@ -446,7 +446,14 @@ public class LodDimension
|
||||
LodRegion region = getRegion(regionPosX, regionPosZ);
|
||||
if (region == null)
|
||||
return false;
|
||||
boolean nodeAdded = region.addData(detailLevel, posX, posZ, lodDataPoint, serverQuality);
|
||||
;
|
||||
if(!LevelContainer.threadAddDataMap.containsKey(Thread.currentThread().getName()) || (LevelContainer.threadAddDataMap.get(Thread.currentThread().getName()) == null))
|
||||
{
|
||||
LevelContainer.threadAddDataMap.put(Thread.currentThread().getName(), new long[10]);
|
||||
}
|
||||
long[] dataArray = LevelContainer.threadAddDataMap.get(Thread.currentThread().getName());
|
||||
dataArray[0] = lodDataPoint;
|
||||
boolean nodeAdded = region.addData(detailLevel, posX, posZ, dataArray, serverQuality);
|
||||
// only save valid LODs to disk
|
||||
if (!dontSave && fileHandler != null)
|
||||
{
|
||||
@@ -533,7 +540,7 @@ public class LodDimension
|
||||
return 0;
|
||||
}
|
||||
|
||||
return region.getData(detailLevel, posX, posZ);
|
||||
return region.getData(detailLevel, posX, posZ)[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ public class LodRegion
|
||||
private LevelContainer[] dataContainer;
|
||||
|
||||
|
||||
private DistanceGenerationMode generationMode;
|
||||
|
||||
public final int regionPosX;
|
||||
public final int regionPosZ;
|
||||
|
||||
@@ -41,26 +43,32 @@ public class LodRegion
|
||||
dataContainer = new LevelContainer[POSSIBLE_LOD];
|
||||
}
|
||||
|
||||
public LodRegion(byte minDetailLevel, RegionPos regionPos, boolean twoDimension)
|
||||
public LodRegion(byte minDetailLevel, RegionPos regionPos, DistanceGenerationMode generationMode)
|
||||
{
|
||||
this.minDetailLevel = minDetailLevel;
|
||||
this.regionPosX = regionPos.x;
|
||||
this.regionPosZ = regionPos.z;
|
||||
|
||||
this.generationMode = generationMode;
|
||||
dataContainer = new LevelContainer[POSSIBLE_LOD];
|
||||
|
||||
|
||||
//Initialize all the different matrices
|
||||
for (byte lod = minDetailLevel; lod <= LodUtil.REGION_DETAIL_LEVEL; lod++)
|
||||
{
|
||||
if(twoDimension){
|
||||
dataContainer[lod] = new SingleLevelContainer(lod);
|
||||
/*if(twoDimension){
|
||||
dataContainer[lod] = new SingleLevelContainer(lod);
|
||||
}else{
|
||||
dataContainer[lod] = new VerticalLevelContainer(lod);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public DistanceGenerationMode getGenerationMode()
|
||||
{
|
||||
return generationMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method can be used to insert data into the LodRegion
|
||||
*
|
||||
@@ -287,6 +295,8 @@ public class LodRegion
|
||||
if(detailLevel < minDetailLevel) return false;
|
||||
posX = LevelPosUtil.getRegionModule(detailLevel, posX);
|
||||
posZ = LevelPosUtil.getRegionModule(detailLevel, posZ);
|
||||
if(dataContainer == null || dataContainer[detailLevel] == null)
|
||||
return false;
|
||||
return dataContainer[detailLevel].doesItExist(posX, posZ);
|
||||
}
|
||||
|
||||
@@ -361,12 +371,10 @@ public class LodRegion
|
||||
{
|
||||
if (detailLevel < minDetailLevel)
|
||||
{
|
||||
for (byte tempLod = (byte) (minDetailLevel - 1); tempLod >= minDetailLevel ; tempLod--)
|
||||
for (byte tempLod = (byte) (minDetailLevel - 1); tempLod >= detailLevel ; tempLod--)
|
||||
{
|
||||
int size = (short) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - tempLod);
|
||||
if(dataContainer[tempLod + 1] == null)
|
||||
{
|
||||
/* TODO this can become either Single or Vertical*/
|
||||
dataContainer[tempLod + 1] = new SingleLevelContainer((byte) (tempLod + 1));
|
||||
}
|
||||
dataContainer[tempLod] = dataContainer[tempLod+1].expand();
|
||||
|
||||
@@ -9,23 +9,19 @@ import com.seibel.lod.util.LodUtil;
|
||||
public class SingleLevelContainer implements LevelContainer
|
||||
{
|
||||
public final byte detailLevel;
|
||||
public final int size;
|
||||
|
||||
public final long[][] data;
|
||||
|
||||
public SingleLevelContainer(byte detailLevel)
|
||||
{
|
||||
this.detailLevel = detailLevel;
|
||||
int size = 1 << (LodUtil.REGION_DETAIL_LEVEL - detailLevel);
|
||||
size = 1 << (LodUtil.REGION_DETAIL_LEVEL - detailLevel);
|
||||
data = new long[size][size];
|
||||
}
|
||||
|
||||
public SingleLevelContainer(byte detailLevel, long[][] data)
|
||||
{
|
||||
this.detailLevel = detailLevel;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean addData(long[] newData, int posX, int posZ){
|
||||
|
||||
posX = LevelPosUtil.getRegionModule(detailLevel, posX);
|
||||
posZ = LevelPosUtil.getRegionModule(detailLevel, posZ);
|
||||
data[posX][posZ] = newData[0];
|
||||
@@ -39,10 +35,18 @@ public class SingleLevelContainer implements LevelContainer
|
||||
return true;
|
||||
}
|
||||
public long[] getData(int posX, int posZ){
|
||||
|
||||
if(!LevelContainer.threadGetDataMap.containsKey(Thread.currentThread().getName()) || (LevelContainer.threadGetDataMap.get(Thread.currentThread().getName()) == null))
|
||||
{
|
||||
LevelContainer.threadGetDataMap.put(Thread.currentThread().getName(), new long[1]);
|
||||
}
|
||||
long[] dataArray = LevelContainer.threadGetDataMap.get(Thread.currentThread().getName());
|
||||
|
||||
posX = LevelPosUtil.getRegionModule(detailLevel, posX);
|
||||
posZ = LevelPosUtil.getRegionModule(detailLevel, posZ);
|
||||
//Improve this using a thread map to long[]
|
||||
return new long[]{data[posX][posZ]};
|
||||
dataArray[0] = data[posX][posZ];
|
||||
return dataArray;
|
||||
}
|
||||
private long getSingleData(int posX, int posZ){
|
||||
posX = LevelPosUtil.getRegionModule(detailLevel, posX);
|
||||
@@ -67,8 +71,8 @@ public class SingleLevelContainer implements LevelContainer
|
||||
|
||||
|
||||
index = inputString.indexOf(DATA_DELIMITER, 0);
|
||||
this.detailLevel = (byte) Integer.parseInt(inputString.substring(0, index));
|
||||
int size = (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel);
|
||||
detailLevel = (byte) Integer.parseInt(inputString.substring(0, index));
|
||||
size = (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel);
|
||||
|
||||
this.data = new long[size][size];
|
||||
for (int x = 0; x < size; x++)
|
||||
@@ -162,12 +166,6 @@ public class SingleLevelContainer implements LevelContainer
|
||||
}
|
||||
|
||||
public String toDataString()
|
||||
{
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int size = (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel);
|
||||
@@ -184,4 +182,12 @@ public class SingleLevelContainer implements LevelContainer
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(detailLevel);
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,16 +41,16 @@ public class DataPointUtil
|
||||
return dataPoint;
|
||||
}
|
||||
|
||||
public static long createDataPoint(int height, int depth, int color)
|
||||
public static long createDataPoint(int height, int depth, int color, int lightValue, int generationMode)
|
||||
{
|
||||
int alpha = (color >> 24) & 0xFF000000;
|
||||
int red = (color >> 16) & 0x00FF0000;
|
||||
int green = (color >> 8) & 0x0000FF00;
|
||||
int blue = color & 0x000000FF;
|
||||
return createDataPoint(height, depth, alpha, red, green, blue);
|
||||
int alpha = ColorUtil.getAlpha(color);
|
||||
int red = ColorUtil.getRed(color);
|
||||
int green = ColorUtil.getGreen(color);
|
||||
int blue = ColorUtil.getBlue(color);
|
||||
return createDataPoint(alpha, red, green, blue, height, depth, lightValue, generationMode);
|
||||
}
|
||||
|
||||
public static long createDataPoint(int height, int depth, int alpha, int red, int green, int blue, int lightValue, int generationMode)
|
||||
public static long createDataPoint(int alpha, int red, int green, int blue, int height, int depth, int lightValue, int generationMode)
|
||||
{
|
||||
long dataPoint = 0;
|
||||
dataPoint += (alpha & ALPHA_MASK) << ALPHA_SHIFT;
|
||||
@@ -146,5 +146,4 @@ public class DataPointUtil
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
VerticalLevelContainer
|
||||
}
|
||||
Reference in New Issue
Block a user