Fixed negative region not showing

This commit is contained in:
Leonardo
2021-08-09 17:54:04 +02:00
parent 190fef934c
commit f6f0ecb21b
4 changed files with 21 additions and 12 deletions
@@ -160,8 +160,8 @@ public class LodNodeBufferBuilder
// z axis
for (int j = 0; j < numbChunksWide; j++)
{
int chunkX = i + (startX / LodQuadTreeNode.CHUNK_WIDTH);
int chunkZ = j + (startZ / LodQuadTreeNode.CHUNK_WIDTH);
int chunkX = i + Math.floorDiv(startX , LodQuadTreeNode.CHUNK_WIDTH);
int chunkZ = j + Math.floorDiv(startZ , LodQuadTreeNode.CHUNK_WIDTH);
// skip any chunks that Minecraft is going to render
if(isCoordInCenterArea(i, j, (numbChunksWide / 2))
@@ -250,7 +250,6 @@ public class LodQuadTree
int NS = Math.abs(Math.floorDiv(posZ , widthRatio) % 2);
if (getChild(NS, WE) == null)
{
System.out.println(lodNode.detailLevel);
return null;
}
LodQuadTree child = getChild(NS, WE);
@@ -572,7 +571,7 @@ public class LodQuadTree
public String toString()
{
String s = lodNode.toString();
/*
if(hasChildren())
{
for (int NS = 0; NS <= 1; NS++)
@@ -586,7 +585,7 @@ public class LodQuadTree
}
}
}
*/
return s;
}
@@ -330,9 +330,9 @@ public class LodQuadTreeDimension
*/
public Boolean addNode(LodQuadTreeNode lodNode)
{
RegionPos regionPos = new RegionPos(new ChunkPos(lodNode.center.getX(), lodNode.center.getZ()));
int[] temp = LodUtil.convertAbsolutePosToQuadTreeRelativePos(lodNode.posX, lodNode.posZ, lodNode.detailLevel, LodQuadTreeNode.REGION_LEVEL);
// don't continue if the region can't be saved
RegionPos regionPos = new RegionPos(temp[0],temp[1]);
if (!regionIsInRange(regionPos.x, regionPos.z))
{
return false;
@@ -347,7 +347,7 @@ public class LodQuadTreeDimension
addOrOverwriteRegion(region);
}
boolean nodeAdded = region.setNodeAtLowerLevel(lodNode);
// only save valid LODs to disk
if (!lodNode.dontSave && fileHandler != null)
{
@@ -389,13 +389,13 @@ public class LodQuadTreeDimension
// TODO this works, but only in all positive coordinates.
int[] relativePos = LodUtil.convertAbsolutePosToQuadTreeRelativePos(chunkPos.x, chunkPos.z, LodQuadTreeNode.CHUNK_LEVEL);
LodQuadTree region = getRegion(new RegionPos(relativePos[0], relativePos[1]));
if(region == null)
{
return null;
}
return region.getNodeAtChunkPos(chunkPos, detailLevel);
return region.getNodeAtChunkPos(chunkPos);
}
/**
+11 -1
View File
@@ -104,7 +104,17 @@ public class LodUtil
return new int[] {relativePosX, relativePosZ};
}
/**
* Convert a 2D absolute position into a quad tree relative position.
*/
public static int[] convertAbsolutePosToQuadTreeRelativePos(int x, int z, int currectDetailLevel, int targetDetailLevel)
{
int relativePosX = Math.floorDiv(x, (int) Math.pow(2, targetDetailLevel - currectDetailLevel));
int relativePosZ = Math.floorDiv(z, (int) Math.pow(2, targetDetailLevel - currectDetailLevel));
return new int[] {relativePosX, relativePosZ};
}
/**
* Return whether the given chunk
* has any data in it.