new generation system fixed
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.sun.glass.ui.Window;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.seibel.lod.builders.worldGeneration.LodNodeGenWorker;
|
||||
@@ -209,12 +210,8 @@ public class LodBufferBuilder
|
||||
int chunkZ = chunkPos.posZ + startChunkPos.z;
|
||||
|
||||
// skip any chunks that Minecraft is going to render
|
||||
if (isCoordInCenterArea(pos.convert((byte) 3).posX, pos.convert((byte) 3).posZ, (numbChunksWide / 2))
|
||||
&& renderer.vanillaRenderedChunks.contains(new ChunkPos(chunkX, chunkZ)))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
if (!(isCoordInCenterArea(pos.convert((byte) 3).posX, pos.convert((byte) 3).posZ, (numbChunksWide / 2))
|
||||
&& renderer.vanillaRenderedChunks.contains(new ChunkPos(chunkX, chunkZ))) && lodDim.doesDataExist(pos))
|
||||
{
|
||||
// set where this square will be drawn in the world
|
||||
double xOffset = (LodUtil.CHUNK_WIDTH * chunkPos.posX) + // offset by the number of LOD blocks
|
||||
@@ -235,13 +232,13 @@ public class LodBufferBuilder
|
||||
|
||||
|
||||
List<LevelPos> posListToGenerate = new ArrayList<>();
|
||||
//posListToGenerate.addAll(lodDim.getDataToGenerate( playerBlockPosRounded.getX(), playerBlockPosRounded.getZ(), 0, 10000000, (byte) DistanceGenerationMode.SURFACE.complexity, (byte) 9, 8));
|
||||
posListToGenerate.addAll(lodDim.getDataToGenerate( playerBlockPosRounded.getX(), playerBlockPosRounded.getZ(), 0, 10000000, (byte) DistanceGenerationMode.SURFACE.complexity, (byte) 0, 16));
|
||||
|
||||
posListToGenerate.addAll(lodDim.getDataToGenerate( playerBlockPosRounded.getX(), playerBlockPosRounded.getZ(), 0, 10000000, (byte) DistanceGenerationMode.SURFACE.complexity, (byte) 0, 12 - posListToGenerate.size()));
|
||||
|
||||
for(LevelPos levelPos : posListToGenerate){
|
||||
LevelPos chunkLevelPos = levelPos.convert((byte) 3);
|
||||
int chunkX = chunkLevelPos.posX;
|
||||
int chunkZ = chunkLevelPos.posZ;
|
||||
int chunkX = chunkLevelPos.posX / 2;
|
||||
int chunkZ = chunkLevelPos.posZ / 2;
|
||||
|
||||
// generate a new chunk if no chunk currently exists
|
||||
// and we aren't waiting on any other chunks to generate
|
||||
@@ -338,19 +335,19 @@ public class LodBufferBuilder
|
||||
}
|
||||
}
|
||||
// start chunk generation
|
||||
|
||||
for (ChunkPos chunkPos : chunksToGen)
|
||||
{
|
||||
// don't add null chunkPos (which shouldn't happen anyway)
|
||||
// or add more to the generation queue
|
||||
if (chunkPos == null || numberOfChunksWaitingToGenerate.get() >= maxChunkGenRequests)
|
||||
break;
|
||||
|
||||
continue;
|
||||
|
||||
// TODO add a list of locations we are waiting to generate so we don't add the
|
||||
// same position to the queue multiple times
|
||||
|
||||
numberOfChunksWaitingToGenerate.addAndGet(1);
|
||||
|
||||
LodNodeGenWorker genWorker = new LodNodeGenWorker(chunkPos, DistanceGenerationMode.SURFACE, LodDetail.HALF, renderer, LodQuadTreeNodeBuilder, this, lodDim, serverWorld);
|
||||
LodNodeGenWorker genWorker = new LodNodeGenWorker(chunkPos, DistanceGenerationMode.SURFACE, LodDetail.FULL, renderer, LodQuadTreeNodeBuilder, this, lodDim, serverWorld);
|
||||
WorldWorkerManager.addWorker(genWorker);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.seibel.lod.builders;
|
||||
import java.awt.Color;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.seibel.lod.enums.DistanceGenerationMode;
|
||||
import com.seibel.lod.enums.LodDetail;
|
||||
@@ -143,18 +144,26 @@ public class LodBuilder
|
||||
if (chunk == null)
|
||||
throw new IllegalArgumentException("generateLodFromChunk given a null chunk");
|
||||
|
||||
boolean check = false;
|
||||
|
||||
int startX;
|
||||
int startZ;
|
||||
int endX;
|
||||
int endZ;
|
||||
Color color;
|
||||
short height;
|
||||
short depth;
|
||||
LevelPos levelPos;
|
||||
LodDataPoint data = null;
|
||||
|
||||
for (int i = 0; i < detail.dataPointLengthCount * detail.dataPointLengthCount; i++)
|
||||
{
|
||||
int startX = detail.startX[i];
|
||||
int startZ = detail.startZ[i];
|
||||
int endX = detail.endX[i];
|
||||
int endZ = detail.endZ[i];
|
||||
startX = detail.startX[i];
|
||||
startZ = detail.startZ[i];
|
||||
endX = detail.endX[i];
|
||||
endZ = detail.endZ[i];
|
||||
|
||||
Color color = generateLodColorForArea(chunk, config, startX, startZ, endX, endZ);
|
||||
|
||||
short height;
|
||||
short depth;
|
||||
color = generateLodColorForArea(chunk, config, startX, startZ, endX, endZ);
|
||||
|
||||
if (!config.useHeightmap)
|
||||
{
|
||||
@@ -166,11 +175,11 @@ public class LodBuilder
|
||||
startZ, endX, endZ);
|
||||
depth = 0;
|
||||
}
|
||||
LevelPos levelPos = new LevelPos((byte) 0,
|
||||
levelPos = new LevelPos((byte) 0,
|
||||
chunk.getPos().x * 16 + startX,
|
||||
chunk.getPos().z * 16 + startZ);
|
||||
LodDataPoint data = new LodDataPoint(height, depth, color);
|
||||
lodDim.addData(levelPos.convert((byte) detail.detailLevel),
|
||||
data = new LodDataPoint(height, depth, color);
|
||||
check = lodDim.addData(levelPos.convert((byte) detail.detailLevel),
|
||||
data,
|
||||
config.distanceGenerationMode,
|
||||
true,
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.seibel.lod.builders.LodBuilderConfig;
|
||||
import com.seibel.lod.enums.DistanceGenerationMode;
|
||||
import com.seibel.lod.enums.LodDetail;
|
||||
import com.seibel.lod.handlers.LodConfig;
|
||||
import com.seibel.lod.objects.LevelPos;
|
||||
import com.seibel.lod.objects.LodDataPoint;
|
||||
import com.seibel.lod.objects.LodDimension;
|
||||
import com.seibel.lod.proxy.ClientProxy;
|
||||
@@ -191,6 +192,7 @@ public class LodNodeGenWorker implements IWorker
|
||||
{
|
||||
// only generate LodChunks if they can
|
||||
// be added to the current LodDimension
|
||||
|
||||
if (lodDim.regionIsInRange(pos.x / LodUtil.REGION_WIDTH_IN_CHUNKS, pos.z / LodUtil.REGION_WIDTH_IN_CHUNKS))
|
||||
{
|
||||
// long startTime = System.currentTimeMillis();
|
||||
@@ -221,13 +223,13 @@ public class LodNodeGenWorker implements IWorker
|
||||
|
||||
lodRenderer.regenerateLODsNextFrame();
|
||||
|
||||
|
||||
LodDataPoint data = lodDim.getData(pos);
|
||||
if (data != null && !data.isEmpty())
|
||||
/*
|
||||
boolean dataExistence = lodDim.doesDataExist(new LevelPos((byte) 3, pos.x, pos.z));
|
||||
if (dataExistence)
|
||||
ClientProxy.LOGGER.info(pos.x + " " + pos.z + " Success!");
|
||||
else
|
||||
ClientProxy.LOGGER.info(pos.x + " " + pos.z);
|
||||
|
||||
*/
|
||||
// shows the pool size, active threads, queued tasks and completed tasks
|
||||
// ClientProxy.LOGGER.info(genThreads.toString());
|
||||
|
||||
|
||||
@@ -2,170 +2,208 @@ package com.seibel.lod.objects;
|
||||
|
||||
import com.seibel.lod.util.LodUtil;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
public class LevelPos implements Cloneable
|
||||
{
|
||||
public final byte detailLevel;
|
||||
public final int posX;
|
||||
public final int posZ;
|
||||
|
||||
public LevelPos(byte detailLevel, int posX, int posZ)
|
||||
{
|
||||
this.posX = posX;
|
||||
this.posZ = posZ;
|
||||
this.detailLevel = detailLevel;
|
||||
}
|
||||
|
||||
public LevelPos convert(byte newDetailLevel)
|
||||
{
|
||||
if (newDetailLevel >= detailLevel)
|
||||
{
|
||||
return new LevelPos(
|
||||
newDetailLevel,
|
||||
Math.floorDiv(posX, (int) Math.pow(2, newDetailLevel - detailLevel)),
|
||||
Math.floorDiv(posZ, (int) Math.pow(2, newDetailLevel - detailLevel)));
|
||||
} else
|
||||
{
|
||||
return new LevelPos(
|
||||
newDetailLevel,
|
||||
posX * (int) Math.pow(2, detailLevel - newDetailLevel),
|
||||
posZ * (int) Math.pow(2, detailLevel - newDetailLevel));
|
||||
}
|
||||
}
|
||||
|
||||
public LevelPos regionModule()
|
||||
{
|
||||
return new LevelPos(
|
||||
detailLevel,
|
||||
Math.floorMod(posX, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)),
|
||||
Math.floorMod(posZ, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)));
|
||||
}
|
||||
|
||||
public RegionPos getRegionPos()
|
||||
{
|
||||
return new RegionPos(
|
||||
Math.floorDiv(posX, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)),
|
||||
Math.floorDiv(posZ, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LevelPos clone()
|
||||
{
|
||||
return new LevelPos(detailLevel, posX, posZ);
|
||||
}
|
||||
|
||||
|
||||
public int maxDistance(int playerPosX, int playerPosZ, int regionPosX, int regionPosZ)
|
||||
{
|
||||
int width = (int) Math.pow(2, detailLevel);
|
||||
|
||||
int startPosX = regionPosX * 512 + posX * width;
|
||||
int startPosZ = regionPosZ * 512 + posZ * width;
|
||||
int endPosX = startPosX + width;
|
||||
int endPosZ = startPosZ + width;
|
||||
|
||||
int maxDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
|
||||
return maxDistance;
|
||||
}
|
||||
|
||||
public int maxDistance(int playerPosX, int playerPosZ)
|
||||
{
|
||||
int width = (int) Math.pow(2, detailLevel);
|
||||
|
||||
int startPosX = posX * width;
|
||||
int startPosZ = posZ * width;
|
||||
int endPosX = startPosX + width;
|
||||
int endPosZ = startPosZ + width;
|
||||
|
||||
int maxDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
|
||||
return maxDistance;
|
||||
}
|
||||
|
||||
public int minDistance(int playerPosX, int playerPosZ, int regionPosX, int regionPosZ)
|
||||
{
|
||||
int width = (int) Math.pow(2, detailLevel);
|
||||
|
||||
int startPosX = regionPosX * 512 + posX * width;
|
||||
int startPosZ = regionPosZ * 512 + posZ * width;
|
||||
int endPosX = startPosX + width;
|
||||
int endPosZ = startPosZ + width;
|
||||
|
||||
boolean inXArea = playerPosX >= startPosX && playerPosX <= endPosX;
|
||||
boolean inZArea = playerPosZ >= startPosZ && playerPosZ <= endPosZ;
|
||||
if (inXArea && inZArea)
|
||||
{
|
||||
return 0;
|
||||
} else if (inXArea)
|
||||
{
|
||||
return Math.min(
|
||||
Math.abs(playerPosZ - startPosZ),
|
||||
Math.abs(playerPosZ - endPosZ)
|
||||
);
|
||||
} else if (inZArea)
|
||||
{
|
||||
return Math.min(
|
||||
Math.abs(playerPosX - startPosX),
|
||||
Math.abs(playerPosX - endPosX)
|
||||
);
|
||||
} else
|
||||
{
|
||||
int minDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
return minDistance;
|
||||
}
|
||||
}
|
||||
|
||||
public int minDistance(int playerPosX, int playerPosZ)
|
||||
{
|
||||
int width = (int) Math.pow(2, detailLevel);
|
||||
|
||||
int startPosX = posX * width;
|
||||
int startPosZ = posZ * width;
|
||||
int endPosX = startPosX + width;
|
||||
int endPosZ = startPosZ + width;
|
||||
|
||||
boolean inXArea = playerPosX >= startPosX && playerPosX <= endPosX;
|
||||
boolean inZArea = playerPosZ >= startPosZ && playerPosZ <= endPosZ;
|
||||
|
||||
if (inXArea && inZArea)
|
||||
{
|
||||
return 0;
|
||||
} else if (inXArea)
|
||||
{
|
||||
return Math.min(
|
||||
Math.abs(playerPosZ - startPosZ),
|
||||
Math.abs(playerPosZ - endPosZ)
|
||||
);
|
||||
} else if (inZArea)
|
||||
{
|
||||
return Math.min(
|
||||
Math.abs(playerPosX - startPosX),
|
||||
Math.abs(playerPosX - endPosX)
|
||||
);
|
||||
} else
|
||||
{
|
||||
int minDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
return minDistance;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String s = (detailLevel + " " + posX + " " + posZ);
|
||||
return s;
|
||||
}
|
||||
public final byte detailLevel;
|
||||
public final int posX;
|
||||
public final int posZ;
|
||||
|
||||
public LevelPos(byte detailLevel, int posX, int posZ)
|
||||
{
|
||||
this.posX = posX;
|
||||
this.posZ = posZ;
|
||||
this.detailLevel = detailLevel;
|
||||
}
|
||||
|
||||
public LevelPos convert(byte newDetailLevel)
|
||||
{
|
||||
if (newDetailLevel >= detailLevel)
|
||||
{
|
||||
return new LevelPos(
|
||||
newDetailLevel,
|
||||
Math.floorDiv(posX, (int) Math.pow(2, newDetailLevel - detailLevel)),
|
||||
Math.floorDiv(posZ, (int) Math.pow(2, newDetailLevel - detailLevel)));
|
||||
} else
|
||||
{
|
||||
return new LevelPos(
|
||||
newDetailLevel,
|
||||
posX * (int) Math.pow(2, detailLevel - newDetailLevel),
|
||||
posZ * (int) Math.pow(2, detailLevel - newDetailLevel));
|
||||
}
|
||||
}
|
||||
|
||||
public LevelPos regionModule()
|
||||
{
|
||||
return new LevelPos(
|
||||
detailLevel,
|
||||
Math.floorMod(posX, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)),
|
||||
Math.floorMod(posZ, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)));
|
||||
}
|
||||
|
||||
public RegionPos getRegionPos()
|
||||
{
|
||||
return new RegionPos(
|
||||
Math.floorDiv(posX, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)),
|
||||
Math.floorDiv(posZ, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LevelPos clone()
|
||||
{
|
||||
return new LevelPos(detailLevel, posX, posZ);
|
||||
}
|
||||
|
||||
|
||||
public int maxDistance(int playerPosX, int playerPosZ, int regionPosX, int regionPosZ)
|
||||
{
|
||||
int width = (int) Math.pow(2, detailLevel);
|
||||
|
||||
int startPosX = regionPosX * 512 + posX * width;
|
||||
int startPosZ = regionPosZ * 512 + posZ * width;
|
||||
int endPosX = startPosX + width;
|
||||
int endPosZ = startPosZ + width;
|
||||
|
||||
int maxDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
|
||||
return maxDistance;
|
||||
}
|
||||
|
||||
public int maxDistance(int playerPosX, int playerPosZ)
|
||||
{
|
||||
int width = (int) Math.pow(2, detailLevel);
|
||||
|
||||
int startPosX = posX * width;
|
||||
int startPosZ = posZ * width;
|
||||
int endPosX = startPosX + width;
|
||||
int endPosZ = startPosZ + width;
|
||||
|
||||
int maxDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)));
|
||||
maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
|
||||
return maxDistance;
|
||||
}
|
||||
|
||||
public int minDistance(int playerPosX, int playerPosZ, int regionPosX, int regionPosZ)
|
||||
{
|
||||
int width = (int) Math.pow(2, detailLevel);
|
||||
|
||||
int startPosX = regionPosX * 512 + posX * width;
|
||||
int startPosZ = regionPosZ * 512 + posZ * width;
|
||||
int endPosX = startPosX + width;
|
||||
int endPosZ = startPosZ + width;
|
||||
|
||||
boolean inXArea = playerPosX >= startPosX && playerPosX <= endPosX;
|
||||
boolean inZArea = playerPosZ >= startPosZ && playerPosZ <= endPosZ;
|
||||
if (inXArea && inZArea)
|
||||
{
|
||||
return 0;
|
||||
} else if (inXArea)
|
||||
{
|
||||
return Math.min(
|
||||
Math.abs(playerPosZ - startPosZ),
|
||||
Math.abs(playerPosZ - endPosZ)
|
||||
);
|
||||
} else if (inZArea)
|
||||
{
|
||||
return Math.min(
|
||||
Math.abs(playerPosX - startPosX),
|
||||
Math.abs(playerPosX - endPosX)
|
||||
);
|
||||
} else
|
||||
{
|
||||
int minDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
return minDistance;
|
||||
}
|
||||
}
|
||||
|
||||
public int minDistance(int playerPosX, int playerPosZ)
|
||||
{
|
||||
int width = (int) Math.pow(2, detailLevel);
|
||||
|
||||
int startPosX = posX * width;
|
||||
int startPosZ = posZ * width;
|
||||
int endPosX = startPosX + width;
|
||||
int endPosZ = startPosZ + width;
|
||||
|
||||
boolean inXArea = playerPosX >= startPosX && playerPosX <= endPosX;
|
||||
boolean inZArea = playerPosZ >= startPosZ && playerPosZ <= endPosZ;
|
||||
|
||||
if (inXArea && inZArea)
|
||||
{
|
||||
return 0;
|
||||
} else if (inXArea)
|
||||
{
|
||||
return Math.min(
|
||||
Math.abs(playerPosZ - startPosZ),
|
||||
Math.abs(playerPosZ - endPosZ)
|
||||
);
|
||||
} else if (inZArea)
|
||||
{
|
||||
return Math.min(
|
||||
Math.abs(playerPosX - startPosX),
|
||||
Math.abs(playerPosX - endPosX)
|
||||
);
|
||||
} else
|
||||
{
|
||||
int minDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)));
|
||||
minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2)));
|
||||
return minDistance;
|
||||
}
|
||||
}
|
||||
|
||||
public static LevelPosComparator getPosComparator()
|
||||
{
|
||||
return new LevelPosComparator();
|
||||
}
|
||||
|
||||
public static LevelPosDetailComparator getPosAndDetailComparator()
|
||||
{
|
||||
return new LevelPosDetailComparator();
|
||||
}
|
||||
|
||||
public static class LevelPosComparator implements Comparator<Map.Entry<LevelPos, Integer>>
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(Map.Entry<LevelPos, Integer> first, Map.Entry<LevelPos, Integer> second)
|
||||
{
|
||||
return Integer.compare(first.getValue(), second.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static class LevelPosDetailComparator implements Comparator<Map.Entry<LevelPos, Integer>>
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(Map.Entry<LevelPos, Integer> first, Map.Entry<LevelPos, Integer> second)
|
||||
{
|
||||
Integer compareResult = Integer.compare(first.getKey().detailLevel, second.getKey().detailLevel);
|
||||
if (compareResult != 0)
|
||||
{
|
||||
compareResult = Integer.compare(first.getValue(), second.getValue());
|
||||
}
|
||||
return compareResult;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String s = (detailLevel + " " + posX + " " + posZ);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ public class LodDimension
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException if newRegion is outside what can be stored in this LodDimension.
|
||||
*/
|
||||
public void addOrOverwriteRegion(LodRegion newRegion) throws ArrayIndexOutOfBoundsException
|
||||
public synchronized void addOrOverwriteRegion(LodRegion newRegion) throws ArrayIndexOutOfBoundsException
|
||||
{
|
||||
int xIndex = (newRegion.regionPosX - center.x) + halfWidth;
|
||||
int zIndex = (center.z - newRegion.regionPosZ) + halfWidth;
|
||||
@@ -304,6 +304,7 @@ public class LodDimension
|
||||
*/
|
||||
public synchronized Boolean addData(LevelPos levelPos, LodDataPoint lodDataPoint, DistanceGenerationMode generationMode, boolean update, boolean dontSave)
|
||||
{
|
||||
|
||||
// don't continue if the region can't be saved
|
||||
RegionPos regionPos = levelPos.getRegionPos();
|
||||
if (!regionIsInRange(regionPos.x, regionPos.z))
|
||||
@@ -358,7 +359,7 @@ public class LodDimension
|
||||
*
|
||||
* @return list of quadTrees
|
||||
*/
|
||||
public List<LevelPos> getDataToGenerate(int playerPosX, int playerPosZ, int start, int end, byte generation, byte detailLevel, int dataNumber)
|
||||
public synchronized List<LevelPos> getDataToGenerate(int playerPosX, int playerPosZ, int start, int end, byte generation, byte detailLevel, int dataNumber)
|
||||
{
|
||||
|
||||
int n = regions.length;
|
||||
@@ -382,7 +383,7 @@ public class LodDimension
|
||||
listOfData.addAll(region.getDataToGenerate(playerPosX, playerPosZ, start, end, generation, detailLevel, dataNumber));
|
||||
}
|
||||
}
|
||||
Collections.sort(listOfData, Map.Entry.comparingByValue());
|
||||
Collections.sort(listOfData, LevelPos.getPosComparator());
|
||||
dataNumber = Math.min(dataNumber, listOfData.size());
|
||||
return listOfData.stream().map(entry -> entry.getKey()).collect(Collectors.toList()).subList(0, dataNumber);
|
||||
}
|
||||
@@ -393,7 +394,7 @@ public class LodDimension
|
||||
*
|
||||
* @return list of nodes
|
||||
*/
|
||||
public List<LevelPos> getDataToRender(int playerPosX, int playerPosZ, int start, int end, byte detailLevel)
|
||||
public synchronized List<LevelPos> getDataToRender(int playerPosX, int playerPosZ, int start, int end, byte detailLevel)
|
||||
{
|
||||
int n = regions.length;
|
||||
List<LevelPos> listOfData = new ArrayList<>();
|
||||
@@ -426,7 +427,7 @@ public class LodDimension
|
||||
*
|
||||
* @return list of nodes
|
||||
*/
|
||||
public List<LevelPos> getDataToRender(RegionPos regionPos, int playerPosX, int playerPosZ, int start, int end, byte detailLevel)
|
||||
public synchronized List<LevelPos> getDataToRender(RegionPos regionPos, int playerPosX, int playerPosZ, int start, int end, byte detailLevel)
|
||||
{
|
||||
int n = regions.length;
|
||||
List<LevelPos> listOfData = new ArrayList<>();
|
||||
|
||||
@@ -211,7 +211,7 @@ public class LodRegion implements Serializable
|
||||
{
|
||||
LevelPos levelPos = new LevelPos(LodUtil.REGION_DETAIL_LEVEL, 0, 0);
|
||||
List<Map.Entry<LevelPos,Integer>> listOfPos = getDataToGenerate(levelPos, playerPosX, playerPosZ, start, end, generation, detailLevel);
|
||||
Collections.sort(listOfPos,Map.Entry.comparingByValue());
|
||||
Collections.sort(listOfPos, LevelPos.getPosComparator());
|
||||
dataNumber = Math.min(dataNumber, listOfPos.size());
|
||||
return listOfPos.subList(0,dataNumber);
|
||||
|
||||
@@ -231,8 +231,6 @@ public class LodRegion implements Serializable
|
||||
|
||||
if (!(start <= maxDistance && minDistance <= end) || levelPos.detailLevel < detailLevel)
|
||||
{
|
||||
System.out.println(maxDistance);
|
||||
System.out.println(minDistance);
|
||||
return levelPosList;
|
||||
}
|
||||
|
||||
@@ -242,12 +240,15 @@ public class LodRegion implements Serializable
|
||||
|
||||
int childSize = (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - levelPos.detailLevel + 1);
|
||||
//we have reached the target detail level
|
||||
if (detailLevel == levelPos.detailLevel || generationType[levelPos.detailLevel][levelPos.posX][levelPos.posZ] < generation)
|
||||
if (detailLevel == levelPos.detailLevel)
|
||||
{
|
||||
levelPosList.add(
|
||||
new AbstractMap.SimpleEntry<LevelPos, Integer>(
|
||||
new LevelPos(levelPos.detailLevel, levelPos.posX + regionPosX * size, levelPos.posZ + regionPosZ * size),
|
||||
maxDistance));
|
||||
if(generationType[levelPos.detailLevel][levelPos.posX][levelPos.posZ] < generation)
|
||||
{
|
||||
levelPosList.add(
|
||||
new AbstractMap.SimpleEntry<LevelPos, Integer>(
|
||||
new LevelPos(levelPos.detailLevel, levelPos.posX + regionPosX * size, levelPos.posZ + regionPosZ * size),
|
||||
minDistance));
|
||||
}
|
||||
} else
|
||||
{
|
||||
//we want max a request per chunk. So for lod smaller than chunk we explore only the top rigth child
|
||||
@@ -260,14 +261,14 @@ public class LodRegion implements Serializable
|
||||
{
|
||||
childPos = new LevelPos((byte) (levelPos.detailLevel - 1), childPosX + x, childPosZ + z);
|
||||
|
||||
maxDistance = childPos.maxDistance(playerPosX,playerPosZ,regionPosX,regionPosZ);
|
||||
minDistance = childPos.minDistance(playerPosX,playerPosZ,regionPosX,regionPosZ);
|
||||
|
||||
if (generationType[childPos.detailLevel][childPos.posX][childPos.posZ] < generation || !doesDataExist(childPos))
|
||||
{
|
||||
levelPosList.add(
|
||||
new AbstractMap.SimpleEntry<LevelPos, Integer>(
|
||||
new LevelPos(childPos.detailLevel, childPos.posX + regionPosX * childSize, childPos.posZ + regionPosZ * childSize),
|
||||
maxDistance));
|
||||
minDistance));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,12 +290,12 @@ public class LodRegion implements Serializable
|
||||
childPos = levelPos.convert((byte) (levelPos.detailLevel - 1));
|
||||
if (generationType[childPos.detailLevel][childPos.posX][childPos.posZ] < generation)
|
||||
{
|
||||
maxDistance = childPos.maxDistance(playerPosX,playerPosZ,regionPosX,regionPosZ);
|
||||
minDistance = childPos.minDistance(playerPosX,playerPosZ,regionPosX,regionPosZ);
|
||||
|
||||
levelPosList.add(
|
||||
new AbstractMap.SimpleEntry<LevelPos, Integer>(
|
||||
new LevelPos(childPos.detailLevel, childPos.posX + regionPosX * childSize, childPos.posZ + regionPosZ * childSize),
|
||||
maxDistance));
|
||||
minDistance));
|
||||
} else
|
||||
{
|
||||
if (childPos.detailLevel != detailLevel)
|
||||
@@ -424,7 +425,7 @@ public class LodRegion implements Serializable
|
||||
int numberOfChildren = 0;
|
||||
|
||||
/**TODO add the ability to change how the heigth and depth are determinated (for example min or max)**/
|
||||
byte minGenerationType = 10;
|
||||
byte minGenerationType = 5;
|
||||
int tempRed = 0;
|
||||
int tempGreen = 0;
|
||||
int tempBlue = 0;
|
||||
|
||||
Reference in New Issue
Block a user