various fix to the generation

This commit is contained in:
Leonardo
2021-09-22 01:26:55 +02:00
parent ea9eac89ec
commit 90d0fbe45b
5 changed files with 125 additions and 100 deletions
@@ -506,71 +506,94 @@ public class LodDimension
public PosToGenerateContainer getDataToGenerate(int maxDataToGenerate, int playerPosX, int playerPosZ)
{
PosToGenerateContainer posToGenerate;
boolean circularGeneration = true;
if (circularGeneration)
LodRegion region;
int x, z, dx, dz, t;
x = 0;
z = 0;
dx = 0;
dz = -1;
switch (LodConfig.CLIENT.worldGenerator.generationPriority.get())
{
posToGenerate = new PosToGenerateContainer((byte) 10, maxDataToGenerate, 0, playerPosX, playerPosZ);
int numbChunksWide = width * 32;
int playerChunkPosX = Math.floorDiv(playerPosX, LodUtil.CHUNK_WIDTH);
int playerChunkPosZ = Math.floorDiv(playerPosZ, LodUtil.CHUNK_WIDTH);
int xChunkToCheck;
int zChunkToCheck;
byte detailLevel;
int posX;
int posZ;
int distance;
int x,z,dx,dz;
long data;
x = z = dx =0;
dz = -1;
int t = numbChunksWide;
int maxI = t*t;
for(int i =0; i < maxI; i++){
if(maxDataToGenerate < 0){
break;
}
if ((-numbChunksWide/2 <= x) && (x <= numbChunksWide/2) && (-numbChunksWide/2 <= z) && (z <= numbChunksWide/2)){
xChunkToCheck = x + playerChunkPosX;
zChunkToCheck = z + playerChunkPosZ;
distance = LevelPosUtil.maxDistance(LodUtil.CHUNK_DETAIL_LEVEL,x,z,0,0);
detailLevel = DetailDistanceUtil.getGenerationDetailFromDistance(distance);
posX = LevelPosUtil.convert(LodUtil.CHUNK_DETAIL_LEVEL,xChunkToCheck, detailLevel);
posZ = LevelPosUtil.convert(LodUtil.CHUNK_DETAIL_LEVEL,zChunkToCheck, detailLevel);
data = getSingleData(detailLevel,posX,posZ);
if(!DataPointUtil.doesItExist(data))
{
posToGenerate.addPosToGenerate(detailLevel,posX,posZ);
maxDataToGenerate--;
}
}
if( (x == z) || ((x < 0) && (x == -z)) || ((x > 0) && (x == 1-z))){
t = dx;
dx = -dz;
dz = t;
}
x += dx;
z += dz;
}
} else
{
posToGenerate = new PosToGenerateContainer((byte) 8, maxDataToGenerate, (int) (maxDataToGenerate * 0.25f), playerPosX, playerPosZ);
int n = regions.length;
int xIndex;
int zIndex;
LodRegion region;
for (int xRegion = 0; xRegion < n; xRegion++)
{
for (int zRegion = 0; zRegion < n; zRegion++)
default:
case NORMAL:
posToGenerate = new PosToGenerateContainer((byte) 10, maxDataToGenerate, 0, playerPosX, playerPosZ);
int playerChunkX = LevelPosUtil.getChunkPos(LodUtil.BLOCK_DETAIL_LEVEL, playerPosX);
int playerChunkZ = LevelPosUtil.getChunkPos(LodUtil.BLOCK_DETAIL_LEVEL, playerPosZ);
int xChunkToCheck;
int zChunkToCheck;
byte detailLevel;
int posX;
int posZ;
long data;
int numbChunksWide = (width) * 32;
//int circleLimit = Integer.MAX_VALUE;
for (int i = 0; i < numbChunksWide * numbChunksWide; i++)
{
xIndex = (xRegion + center.x) - halfWidth;
zIndex = (zRegion + center.z) - halfWidth;
region = getRegion(xIndex, zIndex);
// use this for square generation
if (maxDataToGenerate <= 0)
{
break;
}
// use this for circular generation
/*if (circleLimit < Math.abs(x) && circleLimit < Math.abs(z))
break;
if (maxDataToGenerate == 0)
{
circleLimit = (int) (Math.abs(x) * 1.6f);
}*/
xChunkToCheck = x + playerChunkX;
zChunkToCheck = z + playerChunkZ;
//distance = LevelPosUtil.maxDistance(LodUtil.CHUNK_DETAIL_LEVEL, xChunkToCheck, zChunkToCheck, playerChunkX, playerChunkZ);
region = getRegion(LodUtil.CHUNK_DETAIL_LEVEL, xChunkToCheck, zChunkToCheck);
if(region == null)
continue;
detailLevel = region.getMinDetailLevel();
posX = LevelPosUtil.convert(LodUtil.CHUNK_DETAIL_LEVEL, xChunkToCheck, detailLevel);
posZ = LevelPosUtil.convert(LodUtil.CHUNK_DETAIL_LEVEL, zChunkToCheck, detailLevel);
data = getSingleData(detailLevel, posX, posZ);
if (DataPointUtil.getGenerationMode(data) < LodConfig.CLIENT.worldGenerator.distanceGenerationMode.get().complexity)
{
posToGenerate.addPosToGenerate(detailLevel, posX, posZ);
if (maxDataToGenerate >= 0)
maxDataToGenerate--;
}
if ((x == z) || ((x < 0) && (x == -z)) || ((x > 0) && (x == 1 - z)))
{
t = dx;
dx = -dz;
dz = t;
}
x += dx;
z += dz;
}
break;
case FAR:
posToGenerate = new PosToGenerateContainer((byte) 8, maxDataToGenerate, (int) (maxDataToGenerate * 0.25f), playerPosX, playerPosZ);
int n = regions.length;
int xRegion;
int zRegion;
for (int i = 0; i < width * width; i++)
{
xRegion = x + center.x;
zRegion = z + center.z;
region = getRegion(xRegion, zRegion);
if (region != null)
region.getDataToGenerate(posToGenerate, playerPosX, playerPosZ);
if ((x == z) || ((x < 0) && (x == -z)) || ((x > 0) && (x == 1 - z)))
{
t = dx;
dx = -dz;
dz = t;
}
x += dx;
z += dz;
}
}
break;
}
return posToGenerate;
}
@@ -580,7 +603,8 @@ public class LodDimension
*
* @return list of nodes
*/
public void getDataToRender(PosToRenderContainer posToRender, RegionPos regionPos, int playerPosX, int playerPosZ)
public void getDataToRender(PosToRenderContainer posToRender, RegionPos regionPos, int playerPosX,
int playerPosZ)
{
LodRegion region = getRegion(regionPos.x, regionPos.z);
if (region != null)
@@ -713,7 +737,8 @@ public class LodDimension
* Get the region at the given X and Z coordinates from the
* RegionFileHandler.
*/
public LodRegion getRegionFromFile(RegionPos regionPos, byte detailLevel, DistanceGenerationMode generationMode, VerticalQuality verticalQuality)
public LodRegion getRegionFromFile(RegionPos regionPos, byte detailLevel, DistanceGenerationMode
generationMode, VerticalQuality verticalQuality)
{
if (fileHandler != null)
return fileHandler.loadRegionFromFile(detailLevel, regionPos, generationMode, verticalQuality);
@@ -251,7 +251,7 @@ public class LodRegion
{
if (doesDataExist(childDetailLevel, childPosX + x, childPosZ + z))
{
if (!requireCorrectDetailLevel)
if (!requireCorrectDetailLevel && detailLevel > supposedLevel + 1)
{
childrenCount++;
} else
@@ -264,7 +264,7 @@ public class LodRegion
//If all the four children exist we go deeper
if(!requireCorrectDetailLevel)
if(!requireCorrectDetailLevel && detailLevel > supposedLevel + 1)
{
if (childrenCount == 4)
{
@@ -12,7 +12,7 @@ public class PosToGenerateContainer
private int maxFarSize;
private int nearSize;
private int farSize;
private int[] posToGenerate;
private int[][] posToGenerate;
public PosToGenerateContainer(byte farMinDetail, int maxDataToGenerate, int maxFarDataToGenerate, int playerPosX, int playerPosZ)
{
@@ -24,7 +24,7 @@ public class PosToGenerateContainer
maxSize = maxDataToGenerate;
nearSize = 0;
farSize = 0;
posToGenerate = new int[maxDataToGenerate*4];
posToGenerate = new int[maxDataToGenerate][4];
}
public void addPosToGenerate(byte detailLevel, int posX, int posZ)
@@ -43,20 +43,20 @@ public class PosToGenerateContainer
maxNearSize--;
}
index = posToGenerate.length - farSize;
while (index < posToGenerate.length - 1 && LevelPosUtil.compareLevelAndDistance(detailLevel, distance, (byte) (posToGenerate[(index + 1)*4 + 0] - 1), posToGenerate[(index + 1)*4 + 3]) <= 0)
while (index < posToGenerate.length - 1 && LevelPosUtil.compareLevelAndDistance(detailLevel, distance, (byte) (posToGenerate[index + 1][0] - 1), posToGenerate[index + 1][3]) <= 0)
{
posToGenerate[index*4 + 0] = posToGenerate[(index + 1)*4 + 0];
posToGenerate[index*4 + 1] = posToGenerate[(index + 1)*4 + 1];
posToGenerate[index*4 + 2] = posToGenerate[(index + 1)*4 + 2];
posToGenerate[index*4 + 3] = posToGenerate[(index + 1)*4 + 3];
posToGenerate[index][0] = posToGenerate[index + 1][0];
posToGenerate[index][1] = posToGenerate[index + 1][1];
posToGenerate[index][2] = posToGenerate[index + 1][2];
posToGenerate[index][3] = posToGenerate[index + 1][3];
index++;
}
if (index <= posToGenerate.length - 1)
{
posToGenerate[index*4 + 0] = detailLevel + 1;
posToGenerate[index*4 + 1] = posX;
posToGenerate[index*4 + 2] = posZ;
posToGenerate[index*4 + 3] = distance;
posToGenerate[index][0] = detailLevel + 1;
posToGenerate[index][1] = posX;
posToGenerate[index][2] = posZ;
posToGenerate[index][3] = distance;
}
} else
{//We are introducing a position in the near array
@@ -64,28 +64,27 @@ public class PosToGenerateContainer
nearSize++;
index = nearSize - 1;
while (index > 0 && LevelPosUtil.compareDistance(distance, posToGenerate[(index - 1)*4 + 3]) <= 0)
while (index > 0 && LevelPosUtil.compareDistance(distance, posToGenerate[index - 1][3]) <= 0)
{
posToGenerate[index*4 + 0] = posToGenerate[(index - 1)*4 + 0];
posToGenerate[index*4 + 1] = posToGenerate[(index - 1)*4 + 1];
posToGenerate[index*4 + 2] = posToGenerate[(index - 1)*4 + 2];
posToGenerate[index*4 + 3] = posToGenerate[(index - 1)*4 + 3];
posToGenerate[index][0] = posToGenerate[index - 1][0];
posToGenerate[index][1] = posToGenerate[index - 1][1];
posToGenerate[index][2] = posToGenerate[index - 1][2];
posToGenerate[index][3] = posToGenerate[index - 1][3];
index--;
}
if (index >= 0)
{
posToGenerate[index*4 + 0] = detailLevel + 1;
posToGenerate[index*4 + 1] = posX;
posToGenerate[index*4 + 2] = posZ;
posToGenerate[index*4 + 3] = distance;
posToGenerate[index][0] = detailLevel + 1;
posToGenerate[index][1] = posX;
posToGenerate[index][2] = posZ;
posToGenerate[index][3] = distance;
}
}
}
public int getNumberOfPos()
{
return farSize + nearSize;
return nearSize+farSize;
}
public int getNthDetail(int n)
@@ -97,8 +96,9 @@ public class PosToGenerateContainer
index = n / 2;
else
index = posToGenerate.length - n / 2 - 1;
return posToGenerate[index*4 + 0];
return posToGenerate[index][0];
}
public int getNthPosX(int n)
{
int index;
@@ -108,7 +108,7 @@ public class PosToGenerateContainer
index = n / 2;
else
index = posToGenerate.length - n / 2 - 1;
return posToGenerate[index*4 + 1];
return posToGenerate[index][1];
}
public int getNthPosZ(int n)
{
@@ -119,7 +119,7 @@ public class PosToGenerateContainer
index = n / 2;
else
index = posToGenerate.length - n / 2 - 1;
return posToGenerate[index*4 + 2];
return posToGenerate[index][2];
}
public int getNthGeneration(int n)
{
@@ -130,7 +130,7 @@ public class PosToGenerateContainer
index = n / 2;
else
index = posToGenerate.length - n / 2 - 1;
return posToGenerate[index*4 + 3];
return posToGenerate[index][3];
}
public String toString()
@@ -150,13 +150,13 @@ public class PosToGenerateContainer
builder.append('\n');
for (int i = 0; i < nearSize; i++)
{
builder.append(posToGenerate[i*4 +0]-1);
builder.append(posToGenerate[i][0]-1);
builder.append(" ");
builder.append(posToGenerate[i*4 +1]);
builder.append(posToGenerate[i][1]);
builder.append(" ");
builder.append(posToGenerate[i*4 +2]);
builder.append(posToGenerate[i][2]);
builder.append(" ");
builder.append(posToGenerate[i*4 +3]);
builder.append(posToGenerate[i][3]);
builder.append('\n');
}
builder.append('\n');
@@ -164,13 +164,13 @@ public class PosToGenerateContainer
builder.append('\n');
for (int i = maxSize - 1; i >= maxSize - farSize; i--)
{
builder.append(posToGenerate[i*4 +0]-1);
builder.append(posToGenerate[i][0]-1);
builder.append(" ");
builder.append(posToGenerate[i*4 +1]);
builder.append(posToGenerate[i][1]);
builder.append(" ");
builder.append(posToGenerate[i*4 +2]);
builder.append(posToGenerate[i][2]);
builder.append(" ");
builder.append(posToGenerate[i*4 +3]);
builder.append(posToGenerate[i][3]);
builder.append('\n');
}
builder.append('\n');
@@ -279,7 +279,7 @@ public class DataPointUtil
public static long[] mergeMultiData(long[] dataToMerge, int inputVerticalData, int maxVerticalData)
{
int size = dataToMerge.length / inputVerticalData;
short[] projection = ThreadMapUtil.getProjectionShort((WORLD_HEIGHT) / 16 + 1);
short[] projection = ThreadMapUtil.getProjectionShort((WORLD_HEIGHT) / 16 + 2);
short[] heightAndDepth = ThreadMapUtil.getHeightAndDepth((WORLD_HEIGHT + 1) * 2);
long[] singleDataToMerge = ThreadMapUtil.getSingleAddDataToMerge(size);
long[] dataPoint = ThreadMapUtil.verticalDataArray(WORLD_HEIGHT + 1);
@@ -231,7 +231,7 @@ public class LevelPosUtil
firstDetail);
if (compareResult == 0)
{
compareResult = compareDistance(
compareResult = Integer.compare(
firstDistance,
secondDistance);
}